| 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/memory/weak_ptr.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #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.h" |
| 15 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" | 16 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" |
| 16 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" | 18 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 20 #include "grit/sync_file_system_internals_resources.h" | 21 #include "grit/sync_file_system_internals_resources.h" |
| 21 | 22 |
| 22 using sync_file_system::SyncFileSystemServiceFactory; | 23 using sync_file_system::SyncFileSystemServiceFactory; |
| 23 using sync_file_system::SyncServiceState; | 24 using sync_file_system::SyncServiceState; |
| 24 | 25 |
| 25 namespace syncfs_internals { | 26 namespace syncfs_internals { |
| 26 | 27 |
| 28 namespace { |
| 29 |
| 30 void ConvertExtensionStatusToDictionary( |
| 31 const base::WeakPtr<ExtensionService>& extension_service, |
| 32 const base::Callback<void(const base::ListValue&)>& callback, |
| 33 const std::map<GURL, std::string>& status_map) { |
| 34 DCHECK(!extension_service); |
| 35 |
| 36 base::ListValue list; |
| 37 for (std::map<GURL, std::string>::const_iterator itr = status_map.begin(); |
| 38 itr != status_map.end(); |
| 39 ++itr) { |
| 40 std::string extension_id = itr->first.HostNoBrackets(); |
| 41 |
| 42 // Join with human readable extension name. |
| 43 const extensions::Extension* extension = |
| 44 extension_service->GetExtensionById(extension_id, true); |
| 45 if (!extension) |
| 46 continue; |
| 47 |
| 48 base::DictionaryValue* dict = new base::DictionaryValue; |
| 49 dict->SetString("extensionID", extension_id); |
| 50 dict->SetString("extensionName", extension->name()); |
| 51 dict->SetString("status", itr->second); |
| 52 list.Append(dict); |
| 53 } |
| 54 |
| 55 callback.Run(list); |
| 56 } |
| 57 |
| 58 } // namespace |
| 59 |
| 27 ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile) | 60 ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile) |
| 28 : profile_(profile) {} | 61 : profile_(profile), |
| 62 weak_ptr_factory_(this) {} |
| 29 | 63 |
| 30 ExtensionStatusesHandler::~ExtensionStatusesHandler() {} | 64 ExtensionStatusesHandler::~ExtensionStatusesHandler() {} |
| 31 | 65 |
| 32 void ExtensionStatusesHandler::RegisterMessages() { | 66 void ExtensionStatusesHandler::RegisterMessages() { |
| 33 web_ui()->RegisterMessageCallback( | 67 web_ui()->RegisterMessageCallback( |
| 34 "getExtensionStatuses", | 68 "getExtensionStatuses", |
| 35 base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses, | 69 base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses, |
| 36 base::Unretained(this))); | 70 base::Unretained(this))); |
| 37 } | 71 } |
| 38 | 72 |
| 39 // static | 73 // static |
| 40 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary( | 74 void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary( |
| 41 Profile* profile, | 75 Profile* profile, |
| 42 base::ListValue* values) { | 76 const base::Callback<void(const base::ListValue&)>& callback) { |
| 43 DCHECK(profile); | 77 DCHECK(profile); |
| 44 DCHECK(values); | 78 |
| 45 sync_file_system::SyncFileSystemService* sync_service = | 79 sync_file_system::SyncFileSystemService* sync_service = |
| 46 SyncFileSystemServiceFactory::GetForProfile(profile); | 80 SyncFileSystemServiceFactory::GetForProfile(profile); |
| 81 if (!sync_service) |
| 82 return; |
| 83 |
| 47 ExtensionService* extension_service = | 84 ExtensionService* extension_service = |
| 48 extensions::ExtensionSystem::Get(profile)->extension_service(); | 85 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 49 if (!sync_service || !extension_service) | 86 if (!extension_service) |
| 50 return; | 87 return; |
| 51 | 88 |
| 52 std::map<GURL, std::string> status_map; | 89 sync_service->GetExtensionStatusMap(base::Bind( |
| 53 sync_service->GetExtensionStatusMap(&status_map); | 90 &ConvertExtensionStatusToDictionary, |
| 54 for (std::map<GURL, std::string>::const_iterator itr = status_map.begin(); | 91 extension_service->AsWeakPtr(), callback)); |
| 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 } | 92 } |
| 72 | 93 |
| 73 void ExtensionStatusesHandler::GetExtensionStatuses( | 94 void ExtensionStatusesHandler::GetExtensionStatuses( |
| 74 const base::ListValue* args) { | 95 const base::ListValue* args) { |
| 75 DCHECK(args); | 96 DCHECK(args); |
| 76 base::ListValue list; | 97 GetExtensionStatusesAsDictionary( |
| 77 GetExtensionStatusesAsDictionary(profile_, &list); | 98 profile_, |
| 99 base::Bind(&ExtensionStatusesHandler::DidGetExtensionStatuses, |
| 100 weak_ptr_factory_.GetWeakPtr())); |
| 101 } |
| 102 |
| 103 void ExtensionStatusesHandler::DidGetExtensionStatuses( |
| 104 const base::ListValue& list) { |
| 78 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses", | 105 web_ui()->CallJavascriptFunction("ExtensionStatuses.onGetExtensionStatuses", |
| 79 list); | 106 list); |
| 80 } | 107 } |
| 81 | 108 |
| 82 } // namespace syncfs_internals | 109 } // namespace syncfs_internals |
| OLD | NEW |