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