Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/extensions/api/webstore/bundle_installer.h

Issue 9414013: Add a webstore API for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // 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.
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_API_WEBSTORE_BUNDLE_INSTALLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_BUNDLE_INSTALLER_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "chrome/browser/extensions/extension_install_ui.h"
13 #include "chrome/browser/extensions/webstore_installer.h"
14 #include "chrome/browser/extensions/webstore_install_helper.h"
15 #include "chrome/common/extensions/extension.h"
16
17 namespace base {
18 class DictionaryValue;
19 } // namespace base
20 namespace content {
Aaron Boodman 2012/02/17 01:59:33 add blank lines separating these namespaces.
jstritar 2012/02/17 22:29:09 Done.
21 class NavigationController;
22 } // namespace content
23 class Browser;
24 class Profile;
25
26 namespace webstore {
27
28 // Represents an individual member of the bundle.
29 struct Item {
30 // Creates a dummy extension and sets the manifest's name to the item's
31 // localized name.
32 scoped_refptr<Extension> CreateDummyExtension(
33 base::DictionaryValue* manifest);
34
35 std::string id;
36 std::string manifest;
37 std::string localized_name;
38 };
39
40 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).
41
42 // Manages the installation life cycle for extension bundles.
43 //
44 // We install bundles in two steps:
45 // 1) PromptForApproval: parse manifests and prompt the user
46 // 2) CompleteInstall: install the CRXs and show confirmation bubble
47 //
48 class BundleInstaller : public WebstoreInstallHelper::Delegate,
49 public ExtensionInstallUI::Delegate,
50 public WebstoreInstaller::Delegate,
51 public base::RefCountedThreadSafe<BundleInstaller> {
52 public:
53 // Auto approve or cancel the permission prompt.
54 // Note: this should only be used for testing!
55 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.
56
57 class Delegate {
58 public:
59 virtual void OnBundleInstallApproved() {}
60 virtual void OnBundleInstallCanceled(bool user_initiated) {}
61 virtual void OnBundleInstallCompleted() {}
62 };
63
64 BundleInstaller(Profile* profile, const ItemList& items);
65 virtual ~BundleInstaller();
66
67 // Returns true if the user has approved the bundle's permissions.
68 bool approved() const { return approved_; }
69
70 // Returns all items that have been installed.
71 ItemList GetInstalledItems() const;
72
73 // Returns all items that failed to install.
74 ItemList GetFailedItems() const;
75
76 // Parses the extension manifests and then prompts the user to approve their
77 // permissions. One of OnBundleInstallApproved or OnBundleInstallCanceled
78 // will be called when complete if |delegate| is not NULL.
79 // Note: the |delegate| must stay alive until receiving the callback.
80 void PromptForApproval(Delegate* delegate);
81
82 // If the bundle has been approved, this downloads and installs the member
83 // extensions. OnBundleInstallComplete will be called when the process is
84 // complete and |delegate| is not NULL. The download process uses the
85 // specified |controller|.
86 // Note: the |delegate| must stay alive until receiving the callback.
87 void CompleteInstall(content::NavigationController* controller,
88 Delegate* delegate);
89
90 // 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
91 virtual void OnWebstoreParseSuccess(
92 const std::string& id,
93 const SkBitmap& icon,
94 base::DictionaryValue* parsed_manifest) OVERRIDE;
95 virtual void OnWebstoreParseFailure(
96 const std::string& id,
97 InstallHelperResultCode result_code,
98 const std::string& error_message) OVERRIDE;
99
100 // ExtensionInstallUI::Delegate implementation:
101 virtual void InstallUIProceed() OVERRIDE;
102 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
103
104 // WebstoreInstaller::Delegate implementation:
105 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
106 virtual void OnExtensionInstallFailure(const std::string& id,
107 const std::string& error) OVERRIDE;
108
109 private:
110 friend class base::RefCountedThreadSafe<BundleInstaller>;
111
112 typedef std::map<std::string, Item> ItemMap;
113 typedef std::map<std::string, base::DictionaryValue*> ManifestMap;
114
115 // Gets the items of the map as a list.
116 static ItemList GetItemMapAsList(const ItemMap& item_map);
117
118 // Displays the install bubble for |bundle| on |browser|.
119 // Note: this is a platform specific implementation.
120 static void ShowInstalledBubble(const BundleInstaller* bundle,
121 Browser* browser);
122
123 // 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.
124 void ParseManifests();
125
126 // Notifies the delegate that the installation has been approved.
127 void ReportApproved();
128
129 // Notifies the delegate that the installation was canceled.
130 void ReportCanceled(bool user_initiated);
131
132 // Notifies the delegate that the installation is complete.
133 void ReportComplete();
134
135 // Prompts the user to install the bundle once we have dummy extensions for
136 // all the pending items.
137 void ShowPromptIfDoneParsing();
138
139 // Prompts the user to install the bundle.
140 void ShowPrompt();
141
142 // Displays the installed bubble once all items have installed or failed.
143 void ShowInstalledBubbleIfDone();
144
145 // True if the user has approved the bundle.
146 bool approved_;
147
148 // Holds the Extensions used to generate the permission warnings.
149 ExtensionList dummy_extensions_;
150
151 // Holds the parsed manifests, indexed by the extension ids.
152 ManifestMap parsed_manifests_;
153
154 // Holds the Items in various states, indexed by their ids.
155 ItemMap pending_items_;
156 ItemMap failed_items_;
157 ItemMap installed_items_;
158
159 // The profile that the bundle should be installed in.
160 Profile* profile_;
161
162 // The controller that the webstore installer should use.
163 content::NavigationController* controller_;
164
165 Delegate* delegate_;
166
167 DISALLOW_COPY_AND_ASSIGN(BundleInstaller);
168 };
169
170 } // namespace webstore
171
172 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_BUNDLE_INSTALLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698