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