Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / sync_file_system_internals / file_metadata_handler.cc
blobb3487a759cf73e7f6431a64b8284f8092276ea15
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"
7 #include <map>
9 #include "base/bind.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"
20 #include "grit/sync_file_system_internals_resources.h"
22 using sync_file_system::RemoteFileSyncService;
23 using sync_file_system::SyncFileSystemServiceFactory;
24 using sync_file_system::SyncServiceState;
26 namespace syncfs_internals {
28 FileMetadataHandler::FileMetadataHandler(Profile* profile)
29 : profile_(profile),
30 weak_factory_(this) {}
32 FileMetadataHandler::~FileMetadataHandler() {}
34 void FileMetadataHandler::RegisterMessages() {
35 web_ui()->RegisterMessageCallback(
36 "getExtensions",
37 base::Bind(&FileMetadataHandler::GetExtensions,
38 base::Unretained(this)));
39 web_ui()->RegisterMessageCallback(
40 "getFileMetadata",
41 base::Bind(&FileMetadataHandler::GetFileMetadata,
42 base::Unretained(this)));
45 void FileMetadataHandler::GetFileMetadata(
46 const base::ListValue* args) {
47 std::string extension_id;
48 if (!args->GetString(0, &extension_id) || extension_id.empty()) {
49 LOG(WARNING) << "GetFileMetadata() Extension ID wasn't given";
50 return;
53 // Extension ID from JS is just the host. Need to reformat it to chrome
54 // extension type GURL.
55 const GURL origin = extensions::Extension::GetBaseURLFromExtensionId(
56 extension_id);
58 // Get all metadata for the one specific origin.
59 SyncFileSystemServiceFactory::GetForProfile(profile_)->DumpFiles(
60 origin,
61 base::Bind(&FileMetadataHandler::DidGetFileMetadata,
62 weak_factory_.GetWeakPtr()));
65 void FileMetadataHandler::GetExtensions(const base::ListValue* args) {
66 DCHECK(args);
67 base::ListValue list;
68 ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(profile_, &list);
69 web_ui()->CallJavascriptFunction("FileMetadata.onGetExtensions", list);
72 void FileMetadataHandler::DidGetFileMetadata(const base::ListValue* files) {
73 DCHECK(files);
74 web_ui()->CallJavascriptFunction("FileMetadata.onGetFileMetadata", *files);
77 } // namespace syncfs_internals