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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | |
10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.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/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
19 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
21 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
22 | 21 |
23 namespace extensions { | 22 namespace extensions { |
24 | 23 |
25 namespace system_indicator = api::system_indicator; | 24 namespace system_indicator = api::system_indicator; |
26 | 25 |
27 // Observes clicks on a given status icon and forwards the event to the | 26 // Observes clicks on a given status icon and forwards the event to the |
28 // appropriate extension. Handles icon updates, and responsible for creating | 27 // appropriate extension. Handles icon updates, and responsible for creating |
29 // and removing the icon from the notification area during construction and | 28 // and removing the icon from the notification area during construction and |
30 // destruction. | 29 // destruction. |
31 class ExtensionIndicatorIcon : public StatusIconObserver, | 30 class ExtensionIndicatorIcon : public StatusIconObserver, |
32 public ExtensionActionIconFactory::Observer { | 31 public ExtensionActionIconFactory::Observer { |
33 public: | 32 public: |
34 static ExtensionIndicatorIcon* Create(const Extension* extension, | 33 static std::unique_ptr<ExtensionIndicatorIcon> Create( |
35 ExtensionAction* action, | 34 const Extension* extension, |
36 Profile* profile, | 35 ExtensionAction* action, |
37 StatusTray* status_tray); | 36 Profile* profile, |
| 37 StatusTray* status_tray); |
38 ~ExtensionIndicatorIcon() override; | 38 ~ExtensionIndicatorIcon() override; |
39 | 39 |
40 // StatusIconObserver implementation. | 40 // StatusIconObserver implementation. |
41 void OnStatusIconClicked() override; | 41 void OnStatusIconClicked() override; |
42 | 42 |
43 // ExtensionActionIconFactory::Observer implementation. | 43 // ExtensionActionIconFactory::Observer implementation. |
44 void OnIconUpdated() override; | 44 void OnIconUpdated() override; |
45 | 45 |
46 private: | 46 private: |
47 ExtensionIndicatorIcon(const Extension* extension, | 47 ExtensionIndicatorIcon(const Extension* extension, |
48 ExtensionAction* action, | 48 ExtensionAction* action, |
49 Profile* profile, | 49 Profile* profile, |
50 StatusTray* status_tray); | 50 StatusTray* status_tray); |
51 | 51 |
52 const extensions::Extension* extension_; | 52 const extensions::Extension* extension_; |
53 StatusTray* status_tray_; | 53 StatusTray* status_tray_; |
54 StatusIcon* icon_; | 54 StatusIcon* icon_; |
55 Profile* profile_; | 55 Profile* profile_; |
56 ExtensionActionIconFactory icon_factory_; | 56 ExtensionActionIconFactory icon_factory_; |
57 }; | 57 }; |
58 | 58 |
59 ExtensionIndicatorIcon* ExtensionIndicatorIcon::Create( | 59 std::unique_ptr<ExtensionIndicatorIcon> ExtensionIndicatorIcon::Create( |
60 const Extension* extension, | 60 const Extension* extension, |
61 ExtensionAction* action, | 61 ExtensionAction* action, |
62 Profile* profile, | 62 Profile* profile, |
63 StatusTray* status_tray) { | 63 StatusTray* status_tray) { |
64 std::unique_ptr<ExtensionIndicatorIcon> extension_icon( | 64 std::unique_ptr<ExtensionIndicatorIcon> extension_icon( |
65 new ExtensionIndicatorIcon(extension, action, profile, status_tray)); | 65 new ExtensionIndicatorIcon(extension, action, profile, status_tray)); |
66 | 66 |
67 // Check if a status icon was successfully created. | 67 // Check if a status icon was successfully created. |
68 if (extension_icon->icon_) | 68 if (extension_icon->icon_) |
69 return extension_icon.release(); | 69 return extension_icon; |
70 | 70 |
71 // We could not create a status icon. | 71 // We could not create a status icon. |
72 return NULL; | 72 return std::unique_ptr<ExtensionIndicatorIcon>(); |
73 } | 73 } |
74 | 74 |
75 ExtensionIndicatorIcon::~ExtensionIndicatorIcon() { | 75 ExtensionIndicatorIcon::~ExtensionIndicatorIcon() { |
76 if (icon_) { | 76 if (icon_) { |
77 icon_->RemoveObserver(this); | 77 icon_->RemoveObserver(this); |
78 status_tray_->RemoveStatusIcon(icon_); | 78 status_tray_->RemoveStatusIcon(icon_); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void ExtensionIndicatorIcon::OnStatusIconClicked() { | 82 void ExtensionIndicatorIcon::OnStatusIconClicked() { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void SystemIndicatorManager::CreateOrUpdateIndicator( | 176 void SystemIndicatorManager::CreateOrUpdateIndicator( |
177 const Extension* extension, | 177 const Extension* extension, |
178 ExtensionAction* extension_action) { | 178 ExtensionAction* extension_action) { |
179 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
180 SystemIndicatorMap::iterator it = system_indicators_.find(extension->id()); | 180 SystemIndicatorMap::iterator it = system_indicators_.find(extension->id()); |
181 if (it != system_indicators_.end()) { | 181 if (it != system_indicators_.end()) { |
182 it->second->OnIconUpdated(); | 182 it->second->OnIconUpdated(); |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 ExtensionIndicatorIcon* extension_icon = ExtensionIndicatorIcon::Create( | 186 std::unique_ptr<ExtensionIndicatorIcon> extension_icon = |
187 extension, extension_action, profile_, status_tray_); | 187 ExtensionIndicatorIcon::Create(extension, extension_action, profile_, |
| 188 status_tray_); |
188 if (extension_icon) | 189 if (extension_icon) |
189 system_indicators_[extension->id()] = make_linked_ptr(extension_icon); | 190 system_indicators_[extension->id()] = std::move(extension_icon); |
190 } | 191 } |
191 | 192 |
192 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { | 193 void SystemIndicatorManager::RemoveIndicator(const std::string& extension_id) { |
193 DCHECK(thread_checker_.CalledOnValidThread()); | 194 DCHECK(thread_checker_.CalledOnValidThread()); |
194 system_indicators_.erase(extension_id); | 195 system_indicators_.erase(extension_id); |
195 } | 196 } |
196 | 197 |
197 } // namespace extensions | 198 } // namespace extensions |
OLD | NEW |