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" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/status_icons/status_icon.h" | 13 #include "chrome/browser/status_icons/status_icon.h" |
14 #include "chrome/browser/status_icons/status_icon_observer.h" | 14 #include "chrome/browser/status_icons/status_icon_observer.h" |
15 #include "chrome/browser/status_icons/status_tray.h" | 15 #include "chrome/browser/status_icons/status_tray.h" |
16 #include "chrome/common/extensions/api/system_indicator.h" | 16 #include "chrome/common/extensions/api/system_indicator.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 20 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
22 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 namespace system_indicator = api::system_indicator; | 27 namespace system_indicator = api::system_indicator; |
27 | 28 |
28 // 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 |
29 // appropriate extension. Handles icon updates, and responsible for creating | 30 // appropriate extension. Handles icon updates, and responsible for creating |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 base::string16 tool_tip = base::UTF8ToUTF16(extension_->name()); | 115 base::string16 tool_tip = base::UTF8ToUTF16(extension_->name()); |
115 | 116 |
116 icon_ = status_tray_->CreateStatusIcon( | 117 icon_ = status_tray_->CreateStatusIcon( |
117 StatusTray::OTHER_ICON, icon_image, tool_tip); | 118 StatusTray::OTHER_ICON, icon_image, tool_tip); |
118 if (icon_) | 119 if (icon_) |
119 icon_->AddObserver(this); | 120 icon_->AddObserver(this); |
120 } | 121 } |
121 | 122 |
122 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, | 123 SystemIndicatorManager::SystemIndicatorManager(Profile* profile, |
123 StatusTray* status_tray) | 124 StatusTray* status_tray) |
124 : profile_(profile), status_tray_(status_tray) { | 125 : profile_(profile), |
125 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 126 status_tray_(status_tray), |
126 content::Source<Profile>(profile_->GetOriginalProfile())); | 127 extension_registry_observer_(this) { |
| 128 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 129 |
127 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 130 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
128 content::Source<Profile>(profile_->GetOriginalProfile())); | 131 content::Source<Profile>(profile_->GetOriginalProfile())); |
129 } | 132 } |
130 | 133 |
131 SystemIndicatorManager::~SystemIndicatorManager() { | 134 SystemIndicatorManager::~SystemIndicatorManager() { |
132 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
133 } | 136 } |
134 | 137 |
135 void SystemIndicatorManager::Shutdown() { | 138 void SystemIndicatorManager::Shutdown() { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
137 } | 140 } |
138 | 141 |
| 142 void SystemIndicatorManager::OnExtensionUnloaded( |
| 143 content::BrowserContext* browser_context, |
| 144 const Extension* extension, |
| 145 UnloadedExtensionInfo::Reason reason) { |
| 146 RemoveIndicator(extension->id()); |
| 147 } |
| 148 |
139 void SystemIndicatorManager::Observe( | 149 void SystemIndicatorManager::Observe( |
140 int type, | 150 int type, |
141 const content::NotificationSource& source, | 151 const content::NotificationSource& source, |
142 const content::NotificationDetails& details) { | 152 const content::NotificationDetails& details) { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 153 DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED); |
144 | 155 |
145 switch (type) { | 156 OnSystemIndicatorChanged(content::Details<ExtensionAction>(details).ptr()); |
146 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | |
147 RemoveIndicator( | |
148 content::Details<UnloadedExtensionInfo>(details)->extension->id()); | |
149 break; | |
150 case chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED: | |
151 OnSystemIndicatorChanged( | |
152 content::Details<ExtensionAction>(details).ptr()); | |
153 break; | |
154 default: | |
155 NOTREACHED(); | |
156 break; | |
157 } | |
158 } | 157 } |
159 | 158 |
160 void SystemIndicatorManager::OnSystemIndicatorChanged( | 159 void SystemIndicatorManager::OnSystemIndicatorChanged( |
161 const ExtensionAction* extension_action) { | 160 const ExtensionAction* extension_action) { |
162 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
163 std::string extension_id = extension_action->extension_id(); | 162 std::string extension_id = extension_action->extension_id(); |
164 ExtensionService* service = | 163 ExtensionService* service = |
165 ExtensionSystem::Get(profile_)->extension_service(); | 164 ExtensionSystem::Get(profile_)->extension_service(); |
166 | 165 |
167 if (extension_action->GetIsVisible(ExtensionAction::kDefaultTabId)) { | 166 if (extension_action->GetIsVisible(ExtensionAction::kDefaultTabId)) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (extension_icon) | 200 if (extension_icon) |
202 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); | 201 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); |
203 } | 202 } |
204 | 203 |
205 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { | 204 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { |
206 DCHECK(thread_checker_.CalledOnValidThread()); | 205 DCHECK(thread_checker_.CalledOnValidThread()); |
207 system_indicators_.erase(extension_id); | 206 system_indicators_.erase(extension_id); |
208 } | 207 } |
209 | 208 |
210 } // namespace extensions | 209 } // namespace extensions |
OLD | NEW |