Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_ handler.h" | 5 #include "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_ handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync_file_system/sync_file_system_service.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" | 15 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" |
| 16 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" | 17 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 20 #include "grit/sync_file_system_internals_resources.h" | 20 #include "grit/sync_file_system_internals_resources.h" |
| 21 | 21 |
| 22 using sync_file_system::SyncFileSystemServiceFactory; | 22 using sync_file_system::SyncFileSystemServiceFactory; |
| 23 using sync_file_system::SyncServiceState; | 23 using sync_file_system::SyncServiceState; |
| 24 | 24 |
| 25 namespace syncfs_internals { | 25 namespace syncfs_internals { |
| 26 | 26 |
| 27 namespace { | |
| 28 | |
| 29 void ConvertExtensionStatusToDictionary( | |
| 30 ExtensionService* extension_service, | |
| 31 const base::Callback<void(const base::ListValue&)>& callback, | |
| 32 const std::map<GURL, std::string>& status_map) { | |
| 33 DCHECK(!extension_service); | |
| 34 | |
| 35 base::ListValue list; | |
| 36 for (std::map<GURL, std::string>::const_iterator itr = status_map.begin(); | |
| 37 itr != status_map.end(); | |
| 38 ++itr) { | |
| 39 std::string extension_id = itr->first.HostNoBrackets(); | |
| 40 | |
| 41 // Join with human readable extension name. | |
| 42 const extensions::Extension* extension = | |
| 43 extension_service->GetExtensionById(extension_id, true); | |
| 44 if (!extension) | |
| 45 continue; | |
| 46 | |
| 47 base::DictionaryValue* dict = new base::DictionaryValue; | |
| 48 dict->SetString("extensionID", extension_id); | |
| 49 dict->SetString("extensionName", extension->name()); | |
| 50 dict->SetString("status", itr->second); | |
| 51 list.Append(dict); | |
| 52 } | |
| 53 | |
| 54 callback.Run(list); | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 27 ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile) | 59 ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile) |
| 28 : profile_(profile) {} | 60 : profile_(profile), |
| 61 weak_ptr_factory_(this) {} | |
| 29 | 62 |
| 30 ExtensionStatusesHandler::~ExtensionStatusesHandler() {} | 63 ExtensionStatusesHandler::~ExtensionStatusesHandler() {} |
| 31 | 64 |
| 32 void ExtensionStatusesHandler::RegisterMessages() { | 65 void ExtensionStatusesHandler::RegisterMessages() { |
| 33 web_ui()->RegisterMessageCallback( | 66 web_ui()->RegisterMessageCallback( |
| 34 "getExtensionStatuses", | 67 "getExtensionStatuses", |
| 35 base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses, | 68 base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses, |
| 36 base::Unretained(this))); | 69 base::Unretained(this))); |
| 37 } | 70 } |
| 38 | 71 |
| 39 // static | 72 // static |
| 40 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary( | 73 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary( |
| 41 Profile* profile, | 74 Profile* profile, |
| 42 base::ListValue* values) { | 75 const base::Callback<void(const base::ListValue&)>& callback) { |
| 43 DCHECK(profile); | 76 DCHECK(profile); |
| 44 DCHECK(values); | 77 |
| 45 sync_file_system::SyncFileSystemService* sync_service = | 78 sync_file_system::SyncFileSystemService* sync_service = |
| 46 SyncFileSystemServiceFactory::GetForProfile(profile); | 79 SyncFileSystemServiceFactory::GetForProfile(profile); |
| 80 if (!sync_service) | |
| 81 return; | |
| 82 | |
| 47 ExtensionService* extension_service = | 83 ExtensionService* extension_service = |
| 48 extensions::ExtensionSystem::Get(profile)->extension_service(); | 84 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 49 if (!sync_service || !extension_service) | 85 if (!extension_service) |
| 50 return; | 86 return; |
| 51 | 87 |
| 52 std::map<GURL, std::string> status_map; | 88 sync_service->GetExtensionStatusMap(base::Bind( |
| 53 sync_service->GetExtensionStatusMap(&status_map); | 89 &ConvertExtensionStatusToDictionary, |
| 54 for (std::map<GURL, std::string>::const_iterator itr = status_map.begin(); | 90 base::Unretained(extension_service), callback)); |
|
tzik
2014/05/21 10:52:33
extension_service->AsWeakPtr() and check it in Con
peria
2014/05/22 02:25:21
Done.
There already is a DCHECK(!extension_service
| |
| 55 itr != status_map.end(); | |
| 56 ++itr) { | |
| 57 std::string extension_id = itr->first.HostNoBrackets(); | |
| 58 | |
| 59 // Join with human readable extension name. | |
| 60 const extensions::Extension* extension = | |
| 61 extension_service->GetExtensionById(extension_id, true); | |
| 62 if (!extension) | |
| 63 continue; | |
| 64 | |
| 65 base::DictionaryValue* dict = new base::DictionaryValue; | |
| 66 dict->SetString("extensionID", extension_id); | |
| 67 dict->SetString("extensionName", extension->name()); | |
| 68 dict->SetString("status", itr->second); | |
| 69 values->Append(dict); | |
| 70 } | |
| 71 } | 91 } |
| 72 | 92 |
| 73 void ExtensionStatusesHandler::GetExtensionStatuses( | 93 void ExtensionStatusesHandler::GetExtensionStatuses( |
| 74 const base::ListValue* args) { | 94 const base::ListValue* args) { |
| 75 DCHECK(args); | 95 DCHECK(args); |
| 76 base::ListValue list; | 96 GetExtensionStatusesAsDictionary( |
| 77 GetExtensionStatusesAsDictionary(profile_, &list); | 97 profile_, |
| 98 base::Bind(&ExtensionStatusesHandler::DidGetExtensionStatuses, | |
| 99 weak_ptr_factory_.GetWeakPtr())); | |
| 100 } | |
| 101 | |
| 102 void ExtensionStatusesHandler::DidGetExtensionStatuses( | |
| 103 const base::ListValue& list) { | |
| 78 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses", | 104 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses", |
| 79 list); | 105 list); |
| 80 } | 106 } |
| 81 | 107 |
| 82 } // namespace syncfs_internals | 108 } // namespace syncfs_internals |
| OLD | NEW |