Chromium Code Reviews| Index: chrome/browser/extensions/api/webstore/bundle_installer.h |
| diff --git a/chrome/browser/extensions/api/webstore/bundle_installer.h b/chrome/browser/extensions/api/webstore/bundle_installer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a8ad73428645086012a60dda0c58740612c81dff |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/webstore/bundle_installer.h |
| @@ -0,0 +1,172 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
Aaron Boodman
2012/02/17 01:59:33
2012
Aaron Boodman
2012/02/17 01:59:33
Typically the contents of the api/foo/ directories
Aaron Boodman
2012/02/17 01:59:33
Is this class unit-testable? It seems like it almo
jstritar
2012/02/17 22:29:09
Done.
jstritar
2012/02/17 22:29:09
Okay, I was thinking of moving all the webstore th
jstritar
2012/02/17 22:29:09
I tried to do this, but it's not easy given how We
Aaron Boodman
2012/02/18 11:11:54
Is there anything else in the 'webstore' namespace
Aaron Boodman
2012/02/18 11:11:54
OK, thanks for looking.
jstritar
2012/02/21 15:35:28
Oh, yeah, using the 'extensions' namespace now.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_BUNDLE_INSTALLER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_BUNDLE_INSTALLER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "chrome/browser/extensions/extension_install_ui.h" |
| +#include "chrome/browser/extensions/webstore_installer.h" |
| +#include "chrome/browser/extensions/webstore_install_helper.h" |
| +#include "chrome/common/extensions/extension.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} // namespace base |
| +namespace content { |
|
Aaron Boodman
2012/02/17 01:59:33
add blank lines separating these namespaces.
jstritar
2012/02/17 22:29:09
Done.
|
| +class NavigationController; |
| +} // namespace content |
| +class Browser; |
| +class Profile; |
| + |
| +namespace webstore { |
| + |
| +// Represents an individual member of the bundle. |
| +struct Item { |
| + // Creates a dummy extension and sets the manifest's name to the item's |
| + // localized name. |
| + scoped_refptr<Extension> CreateDummyExtension( |
| + base::DictionaryValue* manifest); |
| + |
| + std::string id; |
| + std::string manifest; |
| + std::string localized_name; |
| +}; |
| + |
| +typedef std::vector<Item> ItemList; |
|
Aaron Boodman
2012/02/17 01:59:33
Having this all alone in the namespace looks a lit
jstritar
2012/02/17 22:29:09
Done (also moved Item).
|
| + |
| +// Manages the installation life cycle for extension bundles. |
| +// |
| +// We install bundles in two steps: |
| +// 1) PromptForApproval: parse manifests and prompt the user |
| +// 2) CompleteInstall: install the CRXs and show confirmation bubble |
| +// |
| +class BundleInstaller : public WebstoreInstallHelper::Delegate, |
| + public ExtensionInstallUI::Delegate, |
| + public WebstoreInstaller::Delegate, |
| + public base::RefCountedThreadSafe<BundleInstaller> { |
| + public: |
| + // Auto approve or cancel the permission prompt. |
| + // Note: this should only be used for testing! |
| + static void SetAutoApproveForTesting(bool approve); |
|
Aaron Boodman
2012/02/17 01:59:33
You can enforce this in the implementation by chec
jstritar
2012/02/17 22:29:09
Nice, done.
|
| + |
| + class Delegate { |
| + public: |
| + virtual void OnBundleInstallApproved() {} |
| + virtual void OnBundleInstallCanceled(bool user_initiated) {} |
| + virtual void OnBundleInstallCompleted() {} |
| + }; |
| + |
| + BundleInstaller(Profile* profile, const ItemList& items); |
| + virtual ~BundleInstaller(); |
| + |
| + // Returns true if the user has approved the bundle's permissions. |
| + bool approved() const { return approved_; } |
| + |
| + // Returns all items that have been installed. |
| + ItemList GetInstalledItems() const; |
| + |
| + // Returns all items that failed to install. |
| + ItemList GetFailedItems() const; |
| + |
| + // Parses the extension manifests and then prompts the user to approve their |
| + // permissions. One of OnBundleInstallApproved or OnBundleInstallCanceled |
| + // will be called when complete if |delegate| is not NULL. |
| + // Note: the |delegate| must stay alive until receiving the callback. |
| + void PromptForApproval(Delegate* delegate); |
| + |
| + // If the bundle has been approved, this downloads and installs the member |
| + // extensions. OnBundleInstallComplete will be called when the process is |
| + // complete and |delegate| is not NULL. The download process uses the |
| + // specified |controller|. |
| + // Note: the |delegate| must stay alive until receiving the callback. |
| + void CompleteInstall(content::NavigationController* controller, |
| + Delegate* delegate); |
| + |
| + // WebstoreInstallHelper::Delegate implementation: |
|
Aaron Boodman
2012/02/17 01:59:33
If these are not part of the class's public interf
jstritar
2012/02/17 22:29:09
Done. Does this only work because the Delegates ar
Aaron Boodman
2012/02/18 11:11:54
No, it's a general feature of C++ that you can inh
|
| + virtual void OnWebstoreParseSuccess( |
| + const std::string& id, |
| + const SkBitmap& icon, |
| + base::DictionaryValue* parsed_manifest) OVERRIDE; |
| + virtual void OnWebstoreParseFailure( |
| + const std::string& id, |
| + InstallHelperResultCode result_code, |
| + const std::string& error_message) OVERRIDE; |
| + |
| + // ExtensionInstallUI::Delegate implementation: |
| + virtual void InstallUIProceed() OVERRIDE; |
| + virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| + |
| + // WebstoreInstaller::Delegate implementation: |
| + virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; |
| + virtual void OnExtensionInstallFailure(const std::string& id, |
| + const std::string& error) OVERRIDE; |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<BundleInstaller>; |
| + |
| + typedef std::map<std::string, Item> ItemMap; |
| + typedef std::map<std::string, base::DictionaryValue*> ManifestMap; |
| + |
| + // Gets the items of the map as a list. |
| + static ItemList GetItemMapAsList(const ItemMap& item_map); |
| + |
| + // Displays the install bubble for |bundle| on |browser|. |
| + // Note: this is a platform specific implementation. |
| + static void ShowInstalledBubble(const BundleInstaller* bundle, |
| + Browser* browser); |
| + |
| + // Parses the all the manifests using WebstoreInstallHelper. |
|
Aaron Boodman
2012/02/17 01:59:33
.remove(" all");
jstritar
2012/02/17 22:29:09
Done.
|
| + void ParseManifests(); |
| + |
| + // Notifies the delegate that the installation has been approved. |
| + void ReportApproved(); |
| + |
| + // Notifies the delegate that the installation was canceled. |
| + void ReportCanceled(bool user_initiated); |
| + |
| + // Notifies the delegate that the installation is complete. |
| + void ReportComplete(); |
| + |
| + // Prompts the user to install the bundle once we have dummy extensions for |
| + // all the pending items. |
| + void ShowPromptIfDoneParsing(); |
| + |
| + // Prompts the user to install the bundle. |
| + void ShowPrompt(); |
| + |
| + // Displays the installed bubble once all items have installed or failed. |
| + void ShowInstalledBubbleIfDone(); |
| + |
| + // True if the user has approved the bundle. |
| + bool approved_; |
| + |
| + // Holds the Extensions used to generate the permission warnings. |
| + ExtensionList dummy_extensions_; |
| + |
| + // Holds the parsed manifests, indexed by the extension ids. |
| + ManifestMap parsed_manifests_; |
| + |
| + // Holds the Items in various states, indexed by their ids. |
| + ItemMap pending_items_; |
| + ItemMap failed_items_; |
| + ItemMap installed_items_; |
| + |
| + // The profile that the bundle should be installed in. |
| + Profile* profile_; |
| + |
| + // The controller that the webstore installer should use. |
| + content::NavigationController* controller_; |
| + |
| + Delegate* delegate_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BundleInstaller); |
| +}; |
| + |
| +} // namespace webstore |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_BUNDLE_INSTALLER_H_ |