OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/extensions/extension_menu_manager.h" | 22 #include "chrome/browser/extensions/extension_menu_manager.h" |
23 #include "chrome/browser/extensions/extension_prefs.h" | 23 #include "chrome/browser/extensions/extension_prefs.h" |
24 #include "chrome/browser/extensions/extension_process_manager.h" | 24 #include "chrome/browser/extensions/extension_process_manager.h" |
25 #include "chrome/browser/extensions/extension_toolbar_model.h" | 25 #include "chrome/browser/extensions/extension_toolbar_model.h" |
26 #include "chrome/browser/extensions/extensions_quota_service.h" | 26 #include "chrome/browser/extensions/extensions_quota_service.h" |
27 #include "chrome/browser/extensions/external_extension_provider.h" | 27 #include "chrome/browser/extensions/external_extension_provider.h" |
28 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 28 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
29 #include "chrome/common/notification_observer.h" | 29 #include "chrome/common/notification_observer.h" |
30 #include "chrome/common/notification_registrar.h" | 30 #include "chrome/common/notification_registrar.h" |
31 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
| 32 #include "testing/gtest/include/gtest/gtest_prod.h" |
32 | 33 |
33 class Browser; | 34 class Browser; |
34 class ExtensionsServiceBackend; | 35 class ExtensionsServiceBackend; |
35 class ExtensionToolbarModel; | 36 class ExtensionToolbarModel; |
36 class ExtensionUpdater; | 37 class ExtensionUpdater; |
37 class GURL; | 38 class GURL; |
38 class PrefService; | 39 class PrefService; |
39 class Profile; | 40 class Profile; |
40 class ResourceDispatcherHost; | 41 class ResourceDispatcherHost; |
41 class SiteInstance; | 42 class SiteInstance; |
| 43 class Version; |
| 44 |
| 45 // A pending extension is an extension that hasn't been installed yet |
| 46 // and is intended to be installed in the next auto-update cycle. The |
| 47 // update URL of a pending extension may be blank, in which case a |
| 48 // default one is assumed. |
| 49 struct PendingExtensionInfo { |
| 50 PendingExtensionInfo(const GURL& update_url, |
| 51 const Version& version, |
| 52 bool is_theme, |
| 53 bool install_silently); |
| 54 |
| 55 PendingExtensionInfo(); |
| 56 |
| 57 GURL update_url; |
| 58 Version version; |
| 59 bool is_theme; |
| 60 bool install_silently; |
| 61 }; |
| 62 |
| 63 // A PendingExtensionMap is a map from IDs of pending extensions to |
| 64 // their info. |
| 65 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; |
42 | 66 |
43 // This is an interface class to encapsulate the dependencies that | 67 // This is an interface class to encapsulate the dependencies that |
44 // ExtensionUpdater has on ExtensionsService. This allows easy mocking. | 68 // ExtensionUpdater has on ExtensionsService. This allows easy mocking. |
45 class ExtensionUpdateService { | 69 class ExtensionUpdateService { |
46 public: | 70 public: |
47 virtual ~ExtensionUpdateService() {} | 71 virtual ~ExtensionUpdateService() {} |
48 virtual const ExtensionList* extensions() const = 0; | 72 virtual const ExtensionList* extensions() const = 0; |
| 73 virtual const PendingExtensionMap& pending_extensions() const = 0; |
49 virtual void UpdateExtension(const std::string& id, const FilePath& path, | 74 virtual void UpdateExtension(const std::string& id, const FilePath& path, |
50 const GURL& download_url) = 0; | 75 const GURL& download_url) = 0; |
51 virtual Extension* GetExtensionById(const std::string& id, | 76 virtual Extension* GetExtensionById(const std::string& id, |
52 bool include_disabled) = 0; | 77 bool include_disabled) = 0; |
53 virtual void UpdateExtensionBlacklist( | 78 virtual void UpdateExtensionBlacklist( |
54 const std::vector<std::string>& blacklist) = 0; | 79 const std::vector<std::string>& blacklist) = 0; |
55 virtual bool HasInstalledExtensions() = 0; | 80 virtual bool HasInstalledExtensions() = 0; |
56 | 81 |
57 // These set/get a server-provided time representing the start of the last day | 82 // These set/get a server-provided time representing the start of the last day |
58 // that we sent the 'ping' parameter during an update check. | 83 // that we sent the 'ping' parameter during an update check. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 PrefService* prefs, | 133 PrefService* prefs, |
109 const FilePath& install_directory, | 134 const FilePath& install_directory, |
110 bool autoupdate_enabled); | 135 bool autoupdate_enabled); |
111 | 136 |
112 // Gets the list of currently installed extensions. | 137 // Gets the list of currently installed extensions. |
113 virtual const ExtensionList* extensions() const { return &extensions_; } | 138 virtual const ExtensionList* extensions() const { return &extensions_; } |
114 virtual const ExtensionList* disabled_extensions() const { | 139 virtual const ExtensionList* disabled_extensions() const { |
115 return &disabled_extensions_; | 140 return &disabled_extensions_; |
116 } | 141 } |
117 | 142 |
| 143 // Gets the set of pending extensions. |
| 144 virtual const PendingExtensionMap& pending_extensions() const { |
| 145 return pending_extensions_; |
| 146 } |
| 147 |
118 // Registers an extension to be loaded as a component extension. | 148 // Registers an extension to be loaded as a component extension. |
119 void register_component_extension(const ComponentExtensionInfo& info) { | 149 void register_component_extension(const ComponentExtensionInfo& info) { |
120 component_extension_manifests_.push_back(info); | 150 component_extension_manifests_.push_back(info); |
121 } | 151 } |
122 | 152 |
123 // Returns true if any extensions are installed. | 153 // Returns true if any extensions are installed. |
124 virtual bool HasInstalledExtensions() { | 154 virtual bool HasInstalledExtensions() { |
125 return !(extensions_.empty() && disabled_extensions_.empty()); | 155 return !(extensions_.empty() && disabled_extensions_.empty()); |
126 } | 156 } |
127 | 157 |
(...skipping 24 matching lines...) Expand all Loading... |
152 void InstallExtension(const FilePath& extension_path); | 182 void InstallExtension(const FilePath& extension_path); |
153 | 183 |
154 // Updates a currently-installed extension with the contents from | 184 // Updates a currently-installed extension with the contents from |
155 // |extension_path|. | 185 // |extension_path|. |
156 // TODO(aa): This method can be removed. ExtensionUpdater could use | 186 // TODO(aa): This method can be removed. ExtensionUpdater could use |
157 // CrxInstaller directly instead. | 187 // CrxInstaller directly instead. |
158 virtual void UpdateExtension(const std::string& id, | 188 virtual void UpdateExtension(const std::string& id, |
159 const FilePath& extension_path, | 189 const FilePath& extension_path, |
160 const GURL& download_url); | 190 const GURL& download_url); |
161 | 191 |
| 192 // If an extension with the given id is already installed, |
| 193 // does nothing. Otherwise, the extension will be installed in the |
| 194 // next auto-update cycle. |
| 195 // |
| 196 // TODO(akalin): Make sure that all the places that check for |
| 197 // existing versions also consult the pending extension info. |
| 198 void AddPendingExtension( |
| 199 const std::string& id, const GURL& update_url, |
| 200 const Version& version, bool is_theme, bool install_silently); |
| 201 |
162 // Reloads the specified extension. | 202 // Reloads the specified extension. |
163 void ReloadExtension(const std::string& extension_id); | 203 void ReloadExtension(const std::string& extension_id); |
164 | 204 |
165 // Uninstalls the specified extension. Callers should only call this method | 205 // Uninstalls the specified extension. Callers should only call this method |
166 // with extensions that exist. |external_uninstall| is a magical parameter | 206 // with extensions that exist. |external_uninstall| is a magical parameter |
167 // that is only used to send information to ExtensionPrefs, which external | 207 // that is only used to send information to ExtensionPrefs, which external |
168 // callers should never set to true. | 208 // callers should never set to true. |
169 // TODO(aa): Remove |external_uninstall| -- this information should be passed | 209 // TODO(aa): Remove |external_uninstall| -- this information should be passed |
170 // to ExtensionPrefs some other way. | 210 // to ExtensionPrefs some other way. |
171 void UninstallExtension(const std::string& extension_id, | 211 void UninstallExtension(const std::string& extension_id, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 335 |
296 // Clear all persistent data that may have been stored by the extension. | 336 // Clear all persistent data that may have been stored by the extension. |
297 void ClearExtensionData(const GURL& extension_url); | 337 void ClearExtensionData(const GURL& extension_url); |
298 | 338 |
299 // Look up an extension by ID, optionally including either or both of enabled | 339 // Look up an extension by ID, optionally including either or both of enabled |
300 // and disabled extensions. | 340 // and disabled extensions. |
301 Extension* GetExtensionByIdInternal(const std::string& id, | 341 Extension* GetExtensionByIdInternal(const std::string& id, |
302 bool include_enabled, | 342 bool include_enabled, |
303 bool include_disabled); | 343 bool include_disabled); |
304 | 344 |
| 345 // Like AddPendingExtension() but assumes an extension with the same |
| 346 // id is not already installed. |
| 347 void AddPendingExtensionInternal( |
| 348 const std::string& id, const GURL& update_url, |
| 349 const Version& version, bool is_theme, bool install_silently); |
| 350 |
305 // Handles sending notification that |extension| was loaded. | 351 // Handles sending notification that |extension| was loaded. |
306 void NotifyExtensionLoaded(Extension* extension); | 352 void NotifyExtensionLoaded(Extension* extension); |
307 | 353 |
308 // Handles sending notification that |extension| was unloaded. | 354 // Handles sending notification that |extension| was unloaded. |
309 void NotifyExtensionUnloaded(Extension* extension); | 355 void NotifyExtensionUnloaded(Extension* extension); |
310 | 356 |
311 // Helper that updates the active extension list used for crash reporting. | 357 // Helper that updates the active extension list used for crash reporting. |
312 void UpdateActiveExtensionsInCrashReporter(); | 358 void UpdateActiveExtensionsInCrashReporter(); |
313 | 359 |
314 // Helper method. Loads extension from prefs. | 360 // Helper method. Loads extension from prefs. |
315 void LoadInstalledExtension(const ExtensionInfo& info, bool relocalize); | 361 void LoadInstalledExtension(const ExtensionInfo& info, bool relocalize); |
316 | 362 |
317 // The profile this ExtensionsService is part of. | 363 // The profile this ExtensionsService is part of. |
318 Profile* profile_; | 364 Profile* profile_; |
319 | 365 |
320 // Preferences for the owning profile. | 366 // Preferences for the owning profile. |
321 scoped_ptr<ExtensionPrefs> extension_prefs_; | 367 scoped_ptr<ExtensionPrefs> extension_prefs_; |
322 | 368 |
323 // The current list of installed extensions. | 369 // The current list of installed extensions. |
324 ExtensionList extensions_; | 370 ExtensionList extensions_; |
325 | 371 |
326 // The list of installed extensions that have been disabled. | 372 // The list of installed extensions that have been disabled. |
327 ExtensionList disabled_extensions_; | 373 ExtensionList disabled_extensions_; |
328 | 374 |
| 375 // The set of pending extensions. |
| 376 PendingExtensionMap pending_extensions_; |
| 377 |
329 // The full path to the directory where extensions are installed. | 378 // The full path to the directory where extensions are installed. |
330 FilePath install_directory_; | 379 FilePath install_directory_; |
331 | 380 |
332 // Whether or not extensions are enabled. | 381 // Whether or not extensions are enabled. |
333 bool extensions_enabled_; | 382 bool extensions_enabled_; |
334 | 383 |
335 // Whether to notify users when they attempt to install an extension. | 384 // Whether to notify users when they attempt to install an extension. |
336 bool show_extensions_prompts_; | 385 bool show_extensions_prompts_; |
337 | 386 |
338 // The backend that will do IO on behalf of this instance. | 387 // The backend that will do IO on behalf of this instance. |
(...skipping 24 matching lines...) Expand all Loading... |
363 | 412 |
364 NotificationRegistrar registrar_; | 413 NotificationRegistrar registrar_; |
365 | 414 |
366 // Keeps track of menu items added by extensions. | 415 // Keeps track of menu items added by extensions. |
367 ExtensionMenuManager menu_manager_; | 416 ExtensionMenuManager menu_manager_; |
368 | 417 |
369 // List of registered component extensions (see Extension::Location). | 418 // List of registered component extensions (see Extension::Location). |
370 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; | 419 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
371 RegisteredComponentExtensions component_extension_manifests_; | 420 RegisteredComponentExtensions component_extension_manifests_; |
372 | 421 |
| 422 FRIEND_TEST(ExtensionsServiceTest, UpdatePendingExtensionAlreadyInstalled); |
| 423 |
373 DISALLOW_COPY_AND_ASSIGN(ExtensionsService); | 424 DISALLOW_COPY_AND_ASSIGN(ExtensionsService); |
374 }; | 425 }; |
375 | 426 |
376 // Implements IO for the ExtensionsService. | 427 // Implements IO for the ExtensionsService. |
377 // TODO(aa): This can probably move into the .cc file. | 428 // TODO(aa): This can probably move into the .cc file. |
378 class ExtensionsServiceBackend | 429 class ExtensionsServiceBackend |
379 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, | 430 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, |
380 public ExternalExtensionProvider::Visitor { | 431 public ExternalExtensionProvider::Visitor { |
381 public: | 432 public: |
382 // |rdh| can be NULL in the case of test environment. | 433 // |rdh| can be NULL in the case of test environment. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 521 |
471 // A map of all external extension providers. | 522 // A map of all external extension providers. |
472 typedef std::map<Extension::Location, | 523 typedef std::map<Extension::Location, |
473 linked_ptr<ExternalExtensionProvider> > ProviderMap; | 524 linked_ptr<ExternalExtensionProvider> > ProviderMap; |
474 ProviderMap external_extension_providers_; | 525 ProviderMap external_extension_providers_; |
475 | 526 |
476 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); | 527 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); |
477 }; | 528 }; |
478 | 529 |
479 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 530 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
OLD | NEW |