[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/compiler_specific.h" |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 14 | #include "content/public/browser/notification_observer.h" |
| 15 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 16 | #include "googleurl/src/gurl.h" |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 17 | |
[email protected] | f66a50a | 2011-11-02 23:53:46 | [diff] [blame^] | 18 | class FilePath; |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 19 | class NavigationController; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 20 | class Profile; |
| 21 | |
| 22 | // Downloads and installs extensions from the web store. |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 23 | class WebstoreInstaller : public content::NotificationObserver, |
| 24 | public base::RefCounted<WebstoreInstaller> { |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 25 | public: |
| 26 | enum Flag { |
| 27 | FLAG_NONE = 0, |
| 28 | |
[email protected] | 99dfecd | 2011-10-18 01:11:50 | [diff] [blame] | 29 | // Inline installs trigger slightly different behavior (install source |
| 30 | // is different, download referrers are the item's page in the gallery). |
| 31 | FLAG_INLINE_INSTALL = 1 << 0 |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | class Delegate { |
| 35 | public: |
| 36 | virtual void OnExtensionInstallSuccess(const std::string& id) = 0; |
| 37 | virtual void OnExtensionInstallFailure(const std::string& id, |
| 38 | const std::string& error) = 0; |
| 39 | }; |
| 40 | |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 41 | |
| 42 | // Creates a WebstoreInstaller for downloading and installing the extension |
| 43 | // with the given |id| from the Chrome Web Store. If |delegate| is not NULL, |
| 44 | // it will be notified when the install succeeds or fails. The installer will |
| 45 | // use the specified |controller| to download the extension. Only one |
| 46 | // WebstoreInstaller can use a specific controller at any given time. |
| 47 | // Note: the delegate should stay alive until being called back. |
| 48 | WebstoreInstaller(Profile* profile, |
| 49 | Delegate* delegate, |
| 50 | NavigationController* controller, |
| 51 | const std::string& id, |
| 52 | int flags); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 53 | virtual ~WebstoreInstaller(); |
| 54 | |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 55 | // Starts downloading and installing the extension. |
| 56 | void Start(); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 57 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 58 | // content::NotificationObserver |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 59 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 60 | const content::NotificationSource& source, |
| 61 | const content::NotificationDetails& details) OVERRIDE; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 62 | |
| 63 | private: |
[email protected] | f66a50a | 2011-11-02 23:53:46 | [diff] [blame^] | 64 | // Starts downloading the extension to |file_path|. |
| 65 | void StartDownload(FilePath file_path); |
| 66 | |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 67 | // Reports an install |error| to the delegate for the given extension if this |
| 68 | // managed its installation. This also removes the associated PendingInstall. |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 69 | void ReportFailure(const std::string& error); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 70 | |
| 71 | // Reports a successful install to the delegate for the given extension if |
| 72 | // this managed its installation. This also removes the associated |
| 73 | // PendingInstall. |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 74 | void ReportSuccess(); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 75 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 76 | content::NotificationRegistrar registrar_; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 77 | Profile* profile_; |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 78 | Delegate* delegate_; |
| 79 | NavigationController* controller_; |
| 80 | std::string id_; |
| 81 | int flags_; |
| 82 | GURL download_url_; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |