1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/ui/webui/sync_file_system_internals/dump_database_handler.h"
6 
7 #include "base/bind.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
10 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
11 #include "content/public/browser/web_ui.h"
12 #include "content/public/browser/web_ui_data_source.h"
13 
14 using sync_file_system::SyncFileSystemServiceFactory;
15 
16 namespace syncfs_internals {
17 
DumpDatabaseHandler(Profile * profile)18 DumpDatabaseHandler::DumpDatabaseHandler(Profile* profile)
19     : profile_(profile) {}
~DumpDatabaseHandler()20 DumpDatabaseHandler::~DumpDatabaseHandler() {}
21 
RegisterMessages()22 void DumpDatabaseHandler::RegisterMessages() {
23   web_ui()->RegisterMessageCallback(
24       "getDatabaseDump",
25       base::BindRepeating(&DumpDatabaseHandler::GetDatabaseDump,
26                           base::Unretained(this)));
27 }
28 
GetDatabaseDump(const base::ListValue *)29 void DumpDatabaseHandler::GetDatabaseDump(const base::ListValue*) {
30   std::unique_ptr<base::ListValue> list;
31   sync_file_system::SyncFileSystemService* sync_service =
32       SyncFileSystemServiceFactory::GetForProfile(profile_);
33   if (sync_service) {
34     sync_service->DumpDatabase(
35         base::Bind(&DumpDatabaseHandler::DidGetDatabaseDump,
36                    base::Unretained(this)));
37   }
38 }
39 
DidGetDatabaseDump(const base::ListValue & list)40 void DumpDatabaseHandler::DidGetDatabaseDump(const base::ListValue& list) {
41   web_ui()->CallJavascriptFunctionUnsafe("DumpDatabase.onGetDatabaseDump",
42                                          list);
43 }
44 
45 }  // namespace syncfs_internals
46