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.
5 #include "chrome/browser/ui/webui/sync_file_system_internals/file_metadata_handler.h"
10 #include "base/bind_helpers.h"
11 #include "base/values.h"
12 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api_helpers.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
15 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
16 #include "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.h"
17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_data_source.h"
19 #include "extensions/common/extension.h"
21 using sync_file_system::RemoteFileSyncService
;
22 using sync_file_system::SyncFileSystemServiceFactory
;
23 using sync_file_system::SyncServiceState
;
25 namespace syncfs_internals
{
27 FileMetadataHandler::FileMetadataHandler(Profile
* profile
)
29 weak_factory_(this) {}
31 FileMetadataHandler::~FileMetadataHandler() {}
33 void FileMetadataHandler::RegisterMessages() {
34 web_ui()->RegisterMessageCallback(
36 base::Bind(&FileMetadataHandler::GetExtensions
,
37 base::Unretained(this)));
38 web_ui()->RegisterMessageCallback(
40 base::Bind(&FileMetadataHandler::GetFileMetadata
,
41 base::Unretained(this)));
44 void FileMetadataHandler::GetFileMetadata(
45 const base::ListValue
* args
) {
46 std::string extension_id
;
47 if (!args
->GetString(0, &extension_id
) || extension_id
.empty()) {
48 LOG(WARNING
) << "GetFileMetadata() Extension ID wasn't given";
52 // Extension ID from JS is just the host. Need to reformat it to chrome
53 // extension type GURL.
54 const GURL origin
= extensions::Extension::GetBaseURLFromExtensionId(
57 // Get all metadata for the one specific origin.
58 sync_file_system::SyncFileSystemService
* sync_service
=
59 SyncFileSystemServiceFactory::GetForProfile(profile_
);
62 sync_service
->DumpFiles(origin
,
63 base::Bind(&FileMetadataHandler::DidGetFileMetadata
,
64 weak_factory_
.GetWeakPtr()));
67 void FileMetadataHandler::GetExtensions(const base::ListValue
* args
) {
69 ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(
71 base::Bind(&FileMetadataHandler::DidGetExtensions
,
72 weak_factory_
.GetWeakPtr()));
75 void FileMetadataHandler::DidGetExtensions(const base::ListValue
& list
) {
76 web_ui()->CallJavascriptFunction("FileMetadata.onGetExtensions", list
);
79 void FileMetadataHandler::DidGetFileMetadata(const base::ListValue
& files
) {
80 web_ui()->CallJavascriptFunction("FileMetadata.onGetFileMetadata", files
);
83 } // namespace syncfs_internals