| 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 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/scoped_observer.h" |
| 14 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "base/version.h" | 18 #include "base/version.h" |
| 18 #include "chrome/browser/extensions/extension_install_prompt.h" | 19 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/download_interrupt_reasons.h" | 21 #include "content/public/browser/download_interrupt_reasons.h" |
| 21 #include "content/public/browser/download_item.h" | 22 #include "content/public/browser/download_item.h" |
| 22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 26 #include "extensions/browser/extension_registry_observer.h" |
| 25 #include "extensions/common/manifest_handlers/shared_module_info.h" | 27 #include "extensions/common/manifest_handlers/shared_module_info.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
| 27 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 28 | 30 |
| 29 class Profile; | 31 class Profile; |
| 30 | 32 |
| 31 namespace base { | 33 namespace base { |
| 32 class FilePath; | 34 class FilePath; |
| 33 } | 35 } |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| 36 class WebContents; | 38 class WebContents; |
| 37 } | 39 } |
| 38 | 40 |
| 39 namespace extensions { | 41 namespace extensions { |
| 40 | 42 |
| 41 class CrxInstaller; | 43 class CrxInstaller; |
| 42 class Extension; | 44 class Extension; |
| 45 class ExtensionRegistry; |
| 43 class Manifest; | 46 class Manifest; |
| 44 | 47 |
| 45 // Downloads and installs extensions from the web store. | 48 // Downloads and installs extensions from the web store. |
| 46 class WebstoreInstaller : public content::NotificationObserver, | 49 class WebstoreInstaller : public content::NotificationObserver, |
| 50 public ExtensionRegistryObserver, |
| 47 public content::DownloadItem::Observer, | 51 public content::DownloadItem::Observer, |
| 48 public content::WebContentsObserver, | 52 public content::WebContentsObserver, |
| 49 public base::RefCountedThreadSafe< | 53 public base::RefCountedThreadSafe< |
| 50 WebstoreInstaller, content::BrowserThread::DeleteOnUIThread> { | 54 WebstoreInstaller, |
| 55 content::BrowserThread::DeleteOnUIThread> { |
| 51 public: | 56 public: |
| 52 enum InstallSource { | 57 enum InstallSource { |
| 53 // Inline installs trigger slightly different behavior (install source | 58 // Inline installs trigger slightly different behavior (install source |
| 54 // is different, download referrers are the item's page in the gallery). | 59 // is different, download referrers are the item's page in the gallery). |
| 55 INSTALL_SOURCE_INLINE, | 60 INSTALL_SOURCE_INLINE, |
| 56 INSTALL_SOURCE_APP_LAUNCHER, | 61 INSTALL_SOURCE_APP_LAUNCHER, |
| 57 INSTALL_SOURCE_OTHER | 62 INSTALL_SOURCE_OTHER |
| 58 }; | 63 }; |
| 59 | 64 |
| 60 enum FailureReason { | 65 enum FailureReason { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 WebstoreInstaller(Profile* profile, | 186 WebstoreInstaller(Profile* profile, |
| 182 Delegate* delegate, | 187 Delegate* delegate, |
| 183 content::WebContents* web_contents, | 188 content::WebContents* web_contents, |
| 184 const std::string& id, | 189 const std::string& id, |
| 185 scoped_ptr<Approval> approval, | 190 scoped_ptr<Approval> approval, |
| 186 InstallSource source); | 191 InstallSource source); |
| 187 | 192 |
| 188 // Starts downloading and installing the extension. | 193 // Starts downloading and installing the extension. |
| 189 void Start(); | 194 void Start(); |
| 190 | 195 |
| 191 // content::NotificationObserver | 196 // content::NotificationObserver. |
| 192 virtual void Observe(int type, | 197 virtual void Observe(int type, |
| 193 const content::NotificationSource& source, | 198 const content::NotificationSource& source, |
| 194 const content::NotificationDetails& details) OVERRIDE; | 199 const content::NotificationDetails& details) OVERRIDE; |
| 195 | 200 |
| 201 // ExtensionRegistryObserver. |
| 202 virtual void OnExtensionWillBeInstalled( |
| 203 content::BrowserContext* browser_context, |
| 204 const Extension* extension, |
| 205 bool is_update, |
| 206 const std::string& old_name) OVERRIDE; |
| 207 |
| 196 // Removes the reference to the delegate passed in the constructor. Used when | 208 // Removes the reference to the delegate passed in the constructor. Used when |
| 197 // the delegate object must be deleted before this object. | 209 // the delegate object must be deleted before this object. |
| 198 void InvalidateDelegate(); | 210 void InvalidateDelegate(); |
| 199 | 211 |
| 200 // Instead of using the default download directory, use |directory| instead. | 212 // Instead of using the default download directory, use |directory| instead. |
| 201 // This does *not* transfer ownership of |directory|. | 213 // This does *not* transfer ownership of |directory|. |
| 202 static void SetDownloadDirectoryForTests(base::FilePath* directory); | 214 static void SetDownloadDirectoryForTests(base::FilePath* directory); |
| 203 | 215 |
| 204 private: | 216 private: |
| 205 FRIEND_TEST_ALL_PREFIXES(WebstoreInstallerTest, PlatformParams); | 217 FRIEND_TEST_ALL_PREFIXES(WebstoreInstallerTest, PlatformParams); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 254 |
| 243 // Reports a successful install to the delegate for the given extension if | 255 // Reports a successful install to the delegate for the given extension if |
| 244 // this managed its installation. This also removes the associated | 256 // this managed its installation. This also removes the associated |
| 245 // PendingInstall. | 257 // PendingInstall. |
| 246 void ReportSuccess(); | 258 void ReportSuccess(); |
| 247 | 259 |
| 248 // Records stats regarding an interrupted webstore download item. | 260 // Records stats regarding an interrupted webstore download item. |
| 249 void RecordInterrupt(const content::DownloadItem* download) const; | 261 void RecordInterrupt(const content::DownloadItem* download) const; |
| 250 | 262 |
| 251 content::NotificationRegistrar registrar_; | 263 content::NotificationRegistrar registrar_; |
| 264 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 265 extension_registry_observer_; |
| 252 Profile* profile_; | 266 Profile* profile_; |
| 253 Delegate* delegate_; | 267 Delegate* delegate_; |
| 254 std::string id_; | 268 std::string id_; |
| 255 InstallSource install_source_; | 269 InstallSource install_source_; |
| 256 // The DownloadItem is owned by the DownloadManager and is valid from when | 270 // The DownloadItem is owned by the DownloadManager and is valid from when |
| 257 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). | 271 // OnDownloadStarted is called (with no error) until OnDownloadDestroyed(). |
| 258 content::DownloadItem* download_item_; | 272 content::DownloadItem* download_item_; |
| 259 // Used to periodically update the extension's download status. This will | 273 // Used to periodically update the extension's download status. This will |
| 260 // trigger at least every second, though sometimes more frequently (depending | 274 // trigger at least every second, though sometimes more frequently (depending |
| 261 // on number of modules, etc). | 275 // on number of modules, etc). |
| 262 base::OneShotTimer<WebstoreInstaller> download_progress_timer_; | 276 base::OneShotTimer<WebstoreInstaller> download_progress_timer_; |
| 263 scoped_ptr<Approval> approval_; | 277 scoped_ptr<Approval> approval_; |
| 264 GURL download_url_; | 278 GURL download_url_; |
| 265 scoped_refptr<CrxInstaller> crx_installer_; | 279 scoped_refptr<CrxInstaller> crx_installer_; |
| 266 | 280 |
| 267 // Pending modules. | 281 // Pending modules. |
| 268 std::list<SharedModuleInfo::ImportInfo> pending_modules_; | 282 std::list<SharedModuleInfo::ImportInfo> pending_modules_; |
| 269 // Total extension modules we need download and install (the main module and | 283 // Total extension modules we need download and install (the main module and |
| 270 // depedences). | 284 // depedences). |
| 271 int total_modules_; | 285 int total_modules_; |
| 272 bool download_started_; | 286 bool download_started_; |
| 273 }; | 287 }; |
| 274 | 288 |
| 275 } // namespace extensions | 289 } // namespace extensions |
| 276 | 290 |
| 277 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ | 291 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| OLD | NEW |