| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/system_indicator/system_indicator_manage
r.h" | 5 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r.h" |
| 6 | 6 |
| 7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/status_icons/status_icon.h" | 12 #include "chrome/browser/status_icons/status_icon.h" |
| 14 #include "chrome/browser/status_icons/status_icon_observer.h" | 13 #include "chrome/browser/status_icons/status_icon_observer.h" |
| 15 #include "chrome/browser/status_icons/status_tray.h" | 14 #include "chrome/browser/status_icons/status_tray.h" |
| 16 #include "chrome/common/extensions/api/system_indicator.h" | 15 #include "chrome/common/extensions/api/system_indicator.h" |
| 17 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 19 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/browser/notification_types.h" |
| 22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 namespace system_indicator = api::system_indicator; | 27 namespace system_indicator = api::system_indicator; |
| 28 | 28 |
| 29 // Observes clicks on a given status icon and forwards the event to the | 29 // Observes clicks on a given status icon and forwards the event to the |
| 30 // appropriate extension. Handles icon updates, and responsible for creating | 30 // appropriate extension. Handles icon updates, and responsible for creating |
| 31 // and removing the icon from the notification area during construction and | 31 // and removing the icon from the notification area during construction and |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 icon_->AddObserver(this); | 120 icon_->AddObserver(this); |
| 121 } | 121 } |
| 122 | 122 |
| 123 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, | 123 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, |
| 124 StatusTray* status_tray) | 124 StatusTray* status_tray) |
| 125 : profile_(profile), | 125 : profile_(profile), |
| 126 status_tray_(status_tray), | 126 status_tray_(status_tray), |
| 127 extension_registry_observer_(this) { | 127 extension_registry_observer_(this) { |
| 128 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 128 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 129 | 129 |
| 130 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 130 registrar_.Add(this, |
| 131 extensions::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
| 131 content::Source<Profile>(profile_->GetOriginalProfile())); | 132 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 132 } | 133 } |
| 133 | 134 |
| 134 SystemIndicatorManager::~SystemIndicatorManager() { | 135 SystemIndicatorManager::~SystemIndicatorManager() { |
| 135 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void SystemIndicatorManager::Shutdown() { | 139 void SystemIndicatorManager::Shutdown() { |
| 139 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void SystemIndicatorManager::OnExtensionUnloaded( | 143 void SystemIndicatorManager::OnExtensionUnloaded( |
| 143 content::BrowserContext* browser_context, | 144 content::BrowserContext* browser_context, |
| 144 const Extension* extension, | 145 const Extension* extension, |
| 145 UnloadedExtensionInfo::Reason reason) { | 146 UnloadedExtensionInfo::Reason reason) { |
| 146 RemoveIndicator(extension->id()); | 147 RemoveIndicator(extension->id()); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void SystemIndicatorManager::Observe( | 150 void SystemIndicatorManager::Observe( |
| 150 int type, | 151 int type, |
| 151 const content::NotificationSource& source, | 152 const content::NotificationSource& source, |
| 152 const content::NotificationDetails& details) { | 153 const content::NotificationDetails& details) { |
| 153 DCHECK(thread_checker_.CalledOnValidThread()); | 154 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED); | 155 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED); |
| 155 | 156 |
| 156 OnSystemIndicatorChanged(content::Details<ExtensionAction>(details).ptr()); | 157 OnSystemIndicatorChanged(content::Details<ExtensionAction>(details).ptr()); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void SystemIndicatorManager::OnSystemIndicatorChanged( | 160 void SystemIndicatorManager::OnSystemIndicatorChanged( |
| 160 const ExtensionAction* extension_action) { | 161 const ExtensionAction* extension_action) { |
| 161 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 std::string extension_id = extension_action->extension_id(); | 163 std::string extension_id = extension_action->extension_id(); |
| 163 ExtensionService* service = | 164 ExtensionService* service = |
| 164 ExtensionSystem::Get(profile_)->extension_service(); | 165 ExtensionSystem::Get(profile_)->extension_service(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (extension_icon) | 201 if (extension_icon) |
| 201 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); | 202 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { | 205 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { |
| 205 DCHECK(thread_checker_.CalledOnValidThread()); | 206 DCHECK(thread_checker_.CalledOnValidThread()); |
| 206 system_indicators_.erase(extension_id); | 207 system_indicators_.erase(extension_id); |
| 207 } | 208 } |
| 208 | 209 |
| 209 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |