summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-12 10:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-12 08:34:13 +0000
commit53d399fe6415a96ea6986ec0d402a9c07da72453 (patch)
treece7dbd5d170326a7d1c5f69f5dcd841c178e0dc0 /chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc
parenta3ee7849e3b0ad3d5f9595fa1cfd694c22dcee2a (diff)
BASELINE: Update Chromium to 60.0.3112.116 and Ninja to 1.8.2
Also adds a few devtools and webui files needed for new features. Change-Id: I431976cc9f4c209d062a925ab6a5d63ec61abcfe Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc')
-rw-r--r--chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc117
1 files changed, 117 insertions, 0 deletions
diff --git a/chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc b/chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc
new file mode 100644
index 00000000000..a9e8ec0244d
--- /dev/null
+++ b/chromium/chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.cc
@@ -0,0 +1,117 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/sync_file_system_internals/extension_statuses_handler.h"
+
+#include <map>
+#include <memory>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync_file_system/sync_file_system_service.h"
+#include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
+#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_ui_data_source.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/common/extension.h"
+
+using sync_file_system::SyncFileSystemServiceFactory;
+using sync_file_system::SyncServiceState;
+
+namespace syncfs_internals {
+
+namespace {
+
+void ConvertExtensionStatusToDictionary(
+ const base::WeakPtr<ExtensionService>& extension_service,
+ const base::Callback<void(const base::ListValue&)>& callback,
+ const std::map<GURL, std::string>& status_map) {
+ if (!extension_service) {
+ callback.Run(base::ListValue());
+ return;
+ }
+
+ base::ListValue list;
+ for (std::map<GURL, std::string>::const_iterator itr = status_map.begin();
+ itr != status_map.end();
+ ++itr) {
+ std::string extension_id = itr->first.HostNoBrackets();
+
+ // Join with human readable extension name.
+ const extensions::Extension* extension =
+ extension_service->GetExtensionById(extension_id, true);
+ if (!extension)
+ continue;
+
+ std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
+ dict->SetString("extensionID", extension_id);
+ dict->SetString("extensionName", extension->name());
+ dict->SetString("status", itr->second);
+ list.Append(std::move(dict));
+ }
+
+ callback.Run(list);
+}
+
+} // namespace
+
+ExtensionStatusesHandler::ExtensionStatusesHandler(Profile* profile)
+ : profile_(profile),
+ weak_ptr_factory_(this) {}
+
+ExtensionStatusesHandler::~ExtensionStatusesHandler() {}
+
+void ExtensionStatusesHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "getExtensionStatuses",
+ base::Bind(&ExtensionStatusesHandler::GetExtensionStatuses,
+ base::Unretained(this)));
+}
+
+// static
+void ExtensionStatusesHandler::GetExtensionStatusesAsDictionary(
+ Profile* profile,
+ const base::Callback<void(const base::ListValue&)>& callback) {
+ DCHECK(profile);
+
+ sync_file_system::SyncFileSystemService* sync_service =
+ SyncFileSystemServiceFactory::GetForProfile(profile);
+ if (!sync_service) {
+ callback.Run(base::ListValue());
+ return;
+ }
+
+ ExtensionService* extension_service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
+ if (!extension_service) {
+ callback.Run(base::ListValue());
+ return;
+ }
+
+ sync_service->GetExtensionStatusMap(base::Bind(
+ &ConvertExtensionStatusToDictionary,
+ extension_service->AsWeakPtr(), callback));
+}
+
+void ExtensionStatusesHandler::GetExtensionStatuses(
+ const base::ListValue* args) {
+ DCHECK(args);
+ GetExtensionStatusesAsDictionary(
+ profile_,
+ base::Bind(&ExtensionStatusesHandler::DidGetExtensionStatuses,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ExtensionStatusesHandler::DidGetExtensionStatuses(
+ const base::ListValue& list) {
+ web_ui()->CallJavascriptFunctionUnsafe(
+ "ExtensionStatuses.onGetExtensionStatuses", list);
+}
+
+} // namespace syncfs_internals