Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / sync_file_system_internals / extension_statuses_handler.cc
blob1849ec9ca5b6178552bb290e29628509e04e327d
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/extension_statuses_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/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
16 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.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::SyncFileSystemServiceFactory;
23 using sync_file_system::SyncServiceState;
25 namespace syncfs_internals {
27 ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile)
28 : profile_(profile) {}
30 ExtensionStatusesHandler::~ExtensionStatusesHandler() {}
32 void ExtensionStatusesHandler::RegisterMessages() {
33 web_ui()->RegisterMessageCallback(
34 "getExtensionStatuses",
35 base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses,
36 base::Unretained(this)));
39 //static
40 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(
41 Profile* profile,
42 base::ListValue* values) {
43 DCHECK(profile);
44 DCHECK(values);
45 std::map<GURL, std::string> status_map;
46 SyncFileSystemServiceFactory::GetForProfile(profile)->GetExtensionStatusMap(
47 &status_map);
49 ExtensionService* extension_service =
50 extensions::ExtensionSystem::Get(profile)->extension_service();
51 if (!extension_service)
52 return;
53 for (std::map<GURL, std::string>::const_iterator itr = status_map.begin();
54 itr != status_map.end();
55 ++itr) {
56 std::string extension_id = itr->first.HostNoBrackets();
58 // Join with human readable extension name.
59 const extensions::Extension* extension =
60 extension_service->GetExtensionById(extension_id, true);
61 if (!extension)
62 continue;
64 base::DictionaryValue* dict = new base::DictionaryValue;
65 dict->SetString("extensionID", extension_id);
66 dict->SetString("extensionName", extension->name());
67 dict->SetString("status", itr->second);
68 values->Append(dict);
72 void ExtensionStatusesHandler::GetExtensionStatuses(
73 const base::ListValue* args) {
74 DCHECK(args);
75 base::ListValue list;
76 GetExtensionStatusesAsDictionary(profile_, &list);
77 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses",
78 list);
81 } // namespace syncfs_internals