Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / system_indicator / system_indicator_manager.cc
index f0e8c35..e5f45fd 100644 (file)
@@ -6,18 +6,15 @@
 
 #include "base/memory/linked_ptr.h"
 #include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/extensions/extension_action.h"
-#include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/status_icons/status_icon.h"
 #include "chrome/browser/status_icons/status_icon_observer.h"
 #include "chrome/browser/status_icons/status_tray.h"
 #include "chrome/common/extensions/api/system_indicator.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
+#include "content/public/browser/web_contents.h"
 #include "extensions/browser/event_router.h"
-#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extension_registry.h"
 #include "extensions/common/extension.h"
 #include "ui/gfx/image/image.h"
 
@@ -84,8 +81,7 @@ void ExtensionIndicatorIcon::OnStatusIconClicked() {
   scoped_ptr<base::ListValue> params(
       api::system_indicator::OnClicked::Create());
 
-  EventRouter* event_router =
-      ExtensionSystem::Get(profile_)->event_router();
+  EventRouter* event_router = EventRouter::Get(profile_);
   scoped_ptr<Event> event(new Event(
       system_indicator::OnClicked::kEventName,
       params.Pass(),
@@ -122,11 +118,12 @@ ExtensionIndicatorIcon::ExtensionIndicatorIcon(const Extension* extension,
 
 SystemIndicatorManager::SystemIndicatorManager(Profile* profile,
                                                StatusTray* status_tray)
-    : profile_(profile), status_tray_(status_tray) {
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
-                 content::Source<Profile>(profile_->GetOriginalProfile()));
-  registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED,
-                 content::Source<Profile>(profile_->GetOriginalProfile()));
+    : profile_(profile),
+      status_tray_(status_tray),
+      extension_action_observer_(this),
+      extension_registry_observer_(this) {
+  extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
+  extension_action_observer_.Add(ExtensionActionAPI::Get(profile_));
 }
 
 SystemIndicatorManager::~SystemIndicatorManager() {
@@ -137,38 +134,28 @@ void SystemIndicatorManager::Shutdown() {
   DCHECK(thread_checker_.CalledOnValidThread());
 }
 
-void SystemIndicatorManager::Observe(
-    int type,
-    const content::NotificationSource& source,
-    const content::NotificationDetails& details) {
-  DCHECK(thread_checker_.CalledOnValidThread());
-
-  switch (type) {
-    case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
-      RemoveIndicator(
-          content::Details<UnloadedExtensionInfo>(details)->extension->id());
-      break;
-    case chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED:
-      OnSystemIndicatorChanged(
-          content::Details<ExtensionAction>(details).ptr());
-      break;
-    default:
-      NOTREACHED();
-      break;
-  }
+void SystemIndicatorManager::OnExtensionUnloaded(
+    content::BrowserContext* browser_context,
+    const Extension* extension,
+    UnloadedExtensionInfo::Reason reason) {
+  RemoveIndicator(extension->id());
 }
 
-void SystemIndicatorManager::OnSystemIndicatorChanged(
-    const ExtensionAction* extension_action) {
+void SystemIndicatorManager::OnExtensionActionUpdated(
+    ExtensionAction* extension_action,
+    content::WebContents* web_contents,
+    content::BrowserContext* browser_context) {
   DCHECK(thread_checker_.CalledOnValidThread());
-  std::string extension_id = extension_action->extension_id();
-  ExtensionService* service =
-      ExtensionSystem::Get(profile_)->extension_service();
+  if (profile_->GetOriginalProfile() != browser_context ||
+      extension_action->action_type() != ActionInfo::TYPE_SYSTEM_INDICATOR)
+    return;
 
+  std::string extension_id = extension_action->extension_id();
   if (extension_action->GetIsVisible(ExtensionAction::kDefaultTabId)) {
-    const Extension* extension =
-        service->GetExtensionById(extension_id, false);
-    CreateOrUpdateIndicator(extension, extension_action);
+    CreateOrUpdateIndicator(
+        ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID(
+            extension_id),
+        extension_action);
   } else {
     RemoveIndicator(extension_id);
   }