OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/extensions/extension_installed_bubble.h" | 5 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/extensions/api/commands/command_service.h" | 19 #include "chrome/browser/extensions/api/commands/command_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 22 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
(...skipping 18 matching lines...) Expand all Loading... |
40 const int kAnimationWaitMs = 50; | 41 const int kAnimationWaitMs = 50; |
41 // How often we retry when waiting for browser action animation to end. | 42 // How often we retry when waiting for browser action animation to end. |
42 const int kAnimationWaitRetries = 10; | 43 const int kAnimationWaitRetries = 10; |
43 | 44 |
44 // Class responsible for showing the bubble after it's installed. Owns itself. | 45 // Class responsible for showing the bubble after it's installed. Owns itself. |
45 class ExtensionInstalledBubbleObserver | 46 class ExtensionInstalledBubbleObserver |
46 : public content::NotificationObserver, | 47 : public content::NotificationObserver, |
47 public extensions::ExtensionRegistryObserver { | 48 public extensions::ExtensionRegistryObserver { |
48 public: | 49 public: |
49 explicit ExtensionInstalledBubbleObserver( | 50 explicit ExtensionInstalledBubbleObserver( |
50 scoped_ptr<ExtensionInstalledBubble> bubble) | 51 std::unique_ptr<ExtensionInstalledBubble> bubble) |
51 : bubble_(std::move(bubble)), | 52 : bubble_(std::move(bubble)), |
52 extension_registry_observer_(this), | 53 extension_registry_observer_(this), |
53 animation_wait_retries_(0), | 54 animation_wait_retries_(0), |
54 weak_factory_(this) { | 55 weak_factory_(this) { |
55 // |extension| has been initialized but not loaded at this point. We need to | 56 // |extension| has been initialized but not loaded at this point. We need to |
56 // wait on showing the Bubble until the EXTENSION_LOADED gets fired. | 57 // wait on showing the Bubble until the EXTENSION_LOADED gets fired. |
57 extension_registry_observer_.Add( | 58 extension_registry_observer_.Add( |
58 extensions::ExtensionRegistry::Get(bubble_->browser()->profile())); | 59 extensions::ExtensionRegistry::Get(bubble_->browser()->profile())); |
59 | 60 |
60 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 61 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 weak_factory_.GetWeakPtr()), | 127 weak_factory_.GetWeakPtr()), |
127 base::TimeDelta::FromMilliseconds(kAnimationWaitMs)); | 128 base::TimeDelta::FromMilliseconds(kAnimationWaitMs)); |
128 } else { | 129 } else { |
129 // Retries are over; won't try again. | 130 // Retries are over; won't try again. |
130 // TODO(hcarmona): Look into logging this with the BubbleManager. | 131 // TODO(hcarmona): Look into logging this with the BubbleManager. |
131 delete this; | 132 delete this; |
132 } | 133 } |
133 } | 134 } |
134 | 135 |
135 // The bubble that will be shown when the extension has finished installing. | 136 // The bubble that will be shown when the extension has finished installing. |
136 scoped_ptr<ExtensionInstalledBubble> bubble_; | 137 std::unique_ptr<ExtensionInstalledBubble> bubble_; |
137 | 138 |
138 ScopedObserver<extensions::ExtensionRegistry, | 139 ScopedObserver<extensions::ExtensionRegistry, |
139 extensions::ExtensionRegistryObserver> | 140 extensions::ExtensionRegistryObserver> |
140 extension_registry_observer_; | 141 extension_registry_observer_; |
141 | 142 |
142 content::NotificationRegistrar registrar_; | 143 content::NotificationRegistrar registrar_; |
143 | 144 |
144 // The number of times to retry showing the bubble if the bubble_->browser() | 145 // The number of times to retry showing the bubble if the bubble_->browser() |
145 // action toolbar is animating. | 146 // action toolbar is animating. |
146 int animation_wait_retries_; | 147 int animation_wait_retries_; |
147 | 148 |
148 base::WeakPtrFactory<ExtensionInstalledBubbleObserver> weak_factory_; | 149 base::WeakPtrFactory<ExtensionInstalledBubbleObserver> weak_factory_; |
149 | 150 |
150 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleObserver); | 151 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleObserver); |
151 }; | 152 }; |
152 | 153 |
153 // Returns the keybinding for an extension command, or a null if none exists. | 154 // Returns the keybinding for an extension command, or a null if none exists. |
154 scoped_ptr<extensions::Command> GetCommand( | 155 std::unique_ptr<extensions::Command> GetCommand( |
155 const std::string& extension_id, | 156 const std::string& extension_id, |
156 Profile* profile, | 157 Profile* profile, |
157 ExtensionInstalledBubble::BubbleType type) { | 158 ExtensionInstalledBubble::BubbleType type) { |
158 scoped_ptr<extensions::Command> result; | 159 std::unique_ptr<extensions::Command> result; |
159 extensions::Command command; | 160 extensions::Command command; |
160 extensions::CommandService* command_service = | 161 extensions::CommandService* command_service = |
161 extensions::CommandService::Get(profile); | 162 extensions::CommandService::Get(profile); |
162 bool has_command = false; | 163 bool has_command = false; |
163 if (type == ExtensionInstalledBubble::BROWSER_ACTION) { | 164 if (type == ExtensionInstalledBubble::BROWSER_ACTION) { |
164 has_command = command_service->GetBrowserActionCommand( | 165 has_command = command_service->GetBrowserActionCommand( |
165 extension_id, extensions::CommandService::ACTIVE, &command, nullptr); | 166 extension_id, extensions::CommandService::ACTIVE, &command, nullptr); |
166 } else if (type == ExtensionInstalledBubble::PAGE_ACTION) { | 167 } else if (type == ExtensionInstalledBubble::PAGE_ACTION) { |
167 has_command = command_service->GetPageActionCommand( | 168 has_command = command_service->GetPageActionCommand( |
168 extension_id, extensions::CommandService::ACTIVE, &command, nullptr); | 169 extension_id, extensions::CommandService::ACTIVE, &command, nullptr); |
169 } | 170 } |
170 if (has_command) | 171 if (has_command) |
171 result.reset(new extensions::Command(command)); | 172 result.reset(new extensions::Command(command)); |
172 return result; | 173 return result; |
173 } | 174 } |
174 | 175 |
175 } // namespace | 176 } // namespace |
176 | 177 |
177 // static | 178 // static |
178 void ExtensionInstalledBubble::ShowBubble( | 179 void ExtensionInstalledBubble::ShowBubble( |
179 const extensions::Extension* extension, | 180 const extensions::Extension* extension, |
180 Browser* browser, | 181 Browser* browser, |
181 const SkBitmap& icon) { | 182 const SkBitmap& icon) { |
182 // The ExtensionInstalledBubbleObserver will delete itself when the | 183 // The ExtensionInstalledBubbleObserver will delete itself when the |
183 // ExtensionInstalledBubble is shown or when it can't be shown anymore. | 184 // ExtensionInstalledBubble is shown or when it can't be shown anymore. |
184 auto x = new ExtensionInstalledBubbleObserver( | 185 auto x = new ExtensionInstalledBubbleObserver( |
185 make_scoped_ptr(new ExtensionInstalledBubble(extension, browser, icon))); | 186 base::WrapUnique(new ExtensionInstalledBubble(extension, browser, icon))); |
186 extensions::ExtensionRegistry* reg = | 187 extensions::ExtensionRegistry* reg = |
187 extensions::ExtensionRegistry::Get(browser->profile()); | 188 extensions::ExtensionRegistry::Get(browser->profile()); |
188 if (reg->enabled_extensions().GetByID(extension->id())) { | 189 if (reg->enabled_extensions().GetByID(extension->id())) { |
189 x->Run(); | 190 x->Run(); |
190 } | 191 } |
191 } | 192 } |
192 | 193 |
193 ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension, | 194 ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension, |
194 Browser* browser, | 195 Browser* browser, |
195 const SkBitmap& icon) | 196 const SkBitmap& icon) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 break; | 299 break; |
299 case OMNIBOX_KEYWORD: | 300 case OMNIBOX_KEYWORD: |
300 options_ |= HOW_TO_USE | HOW_TO_MANAGE; | 301 options_ |= HOW_TO_USE | HOW_TO_MANAGE; |
301 anchor_position_ = ANCHOR_OMNIBOX; | 302 anchor_position_ = ANCHOR_OMNIBOX; |
302 break; | 303 break; |
303 case GENERIC: | 304 case GENERIC: |
304 anchor_position_ = ANCHOR_APP_MENU; | 305 anchor_position_ = ANCHOR_APP_MENU; |
305 break; | 306 break; |
306 } | 307 } |
307 } | 308 } |
OLD | NEW |