[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] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 13 | #include "content/public/browser/notification_observer.h" |
| 14 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 15 | |
| 16 | class GURL; |
| 17 | class Profile; |
| 18 | |
| 19 | // Downloads and installs extensions from the web store. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 20 | class WebstoreInstaller : public content::NotificationObserver { |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 21 | public: |
| 22 | enum Flag { |
| 23 | FLAG_NONE = 0, |
| 24 | |
[email protected] | 99dfecd | 2011-10-18 01:11:50 | [diff] [blame] | 25 | // Inline installs trigger slightly different behavior (install source |
| 26 | // is different, download referrers are the item's page in the gallery). |
| 27 | FLAG_INLINE_INSTALL = 1 << 0 |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | class Delegate { |
| 31 | public: |
| 32 | virtual void OnExtensionInstallSuccess(const std::string& id) = 0; |
| 33 | virtual void OnExtensionInstallFailure(const std::string& id, |
| 34 | const std::string& error) = 0; |
| 35 | }; |
| 36 | |
| 37 | explicit WebstoreInstaller(Profile* profile); |
| 38 | virtual ~WebstoreInstaller(); |
| 39 | |
| 40 | // Download and install the extension with the given |id| from the Chrome |
| 41 | // Web Store. If |delegate| is not NULL, it will be notified when the |
| 42 | // install succeeds or fails. |
| 43 | // Note: the delegate should stay alive until being called back. |
| 44 | void InstallExtension(const std::string& id, Delegate* delegate, int flags); |
| 45 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 46 | // content::NotificationObserver |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 47 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 48 | const content::NotificationSource& source, |
| 49 | const content::NotificationDetails& details) OVERRIDE; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | struct PendingInstall; |
| 53 | |
| 54 | // Removes the PendingIntall data for the given extension, returning true and |
| 55 | // setting |install| if there is such data. |
| 56 | bool ClearPendingInstall(const std::string& id, PendingInstall* install); |
| 57 | |
| 58 | // Creates the PendingInstall for the specified extension. |
| 59 | const PendingInstall& CreatePendingInstall( |
[email protected] | 99dfecd | 2011-10-18 01:11:50 | [diff] [blame] | 60 | const std::string& id, GURL install_url, Delegate* delegate); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 61 | |
| 62 | // Gets the extension id for the given gallery install |url|. |
| 63 | std::string GetPendingInstallId(const GURL& url); |
| 64 | |
| 65 | // Reports an install |error| to the delegate for the given extension if this |
| 66 | // managed its installation. This also removes the associated PendingInstall. |
| 67 | void ReportFailure(const std::string& id, const std::string& error); |
| 68 | |
| 69 | // Reports a successful install to the delegate for the given extension if |
| 70 | // this managed its installation. This also removes the associated |
| 71 | // PendingInstall. |
| 72 | void ReportSuccess(const std::string& id); |
| 73 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame^] | 74 | content::NotificationRegistrar registrar_; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 75 | Profile* profile_; |
| 76 | std::vector<PendingInstall> pending_installs_; |
| 77 | }; |
| 78 | |
| 79 | #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALLER_H_ |