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"
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)));
40 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(
42 base::ListValue
* values
) {
45 std::map
<GURL
, std::string
> status_map
;
46 SyncFileSystemServiceFactory::GetForProfile(profile
)->GetExtensionStatusMap(
49 ExtensionService
* extension_service
=
50 extensions::ExtensionSystem::Get(profile
)->extension_service();
51 if (!extension_service
)
53 for (std::map
<GURL
, std::string
>::const_iterator itr
= status_map
.begin();
54 itr
!= status_map
.end();
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);
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
);
72 void ExtensionStatusesHandler::GetExtensionStatuses(
73 const base::ListValue
* args
) {
76 GetExtensionStatusesAsDictionary(profile_
, &list
);
77 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses",
81 } // namespace syncfs_internals