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

Side by Side Diff: chrome/browser/extensions/extension_service.h

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 9 years, 11 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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_EXTENSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/linked_ptr.h" 16 #include "base/linked_ptr.h"
17 #include "base/ref_counted.h" 17 #include "base/ref_counted.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "base/tuple.h" 20 #include "base/tuple.h"
21 #include "chrome/browser/browser_thread.h" 21 #include "chrome/browser/browser_thread.h"
22 #include "chrome/browser/extensions/default_apps.h" 22 #include "chrome/browser/extensions/default_apps.h"
23 #include "chrome/browser/extensions/extension_icon_manager.h" 23 #include "chrome/browser/extensions/extension_icon_manager.h"
24 #include "chrome/browser/extensions/extension_menu_manager.h" 24 #include "chrome/browser/extensions/extension_menu_manager.h"
25 #include "chrome/browser/extensions/extension_prefs.h" 25 #include "chrome/browser/extensions/extension_prefs.h"
26 #include "chrome/browser/extensions/extension_process_manager.h" 26 #include "chrome/browser/extensions/extension_process_manager.h"
27 #include "chrome/browser/extensions/extension_toolbar_model.h" 27 #include "chrome/browser/extensions/extension_toolbar_model.h"
28 #include "chrome/browser/extensions/extensions_quota_service.h" 28 #include "chrome/browser/extensions/extensions_quota_service.h"
29 #include "chrome/browser/extensions/external_extension_provider.h" 29 #include "chrome/browser/extensions/external_extension_provider_interface.h"
30 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" 30 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h"
31 #include "chrome/browser/prefs/pref_change_registrar.h" 31 #include "chrome/browser/prefs/pref_change_registrar.h"
32 #include "chrome/common/notification_observer.h" 32 #include "chrome/common/notification_observer.h"
33 #include "chrome/common/notification_registrar.h" 33 #include "chrome/common/notification_registrar.h"
34 #include "chrome/common/extensions/extension.h" 34 #include "chrome/common/extensions/extension.h"
35 #include "chrome/common/property_bag.h" 35 #include "chrome/common/property_bag.h"
36 36
37 class ExtensionServiceBackend; 37 class ExtensionServiceBackend;
38 class ExtensionToolbarModel; 38 class ExtensionToolbarModel;
39 class ExtensionUpdater; 39 class ExtensionUpdater;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 virtual bool HasInstalledExtensions() = 0; 92 virtual bool HasInstalledExtensions() = 0;
93 93
94 virtual ExtensionPrefs* extension_prefs() = 0; 94 virtual ExtensionPrefs* extension_prefs() = 0;
95 }; 95 };
96 96
97 // Manages installed and running Chromium extensions. 97 // Manages installed and running Chromium extensions.
98 class ExtensionService 98 class ExtensionService
99 : public base::RefCountedThreadSafe<ExtensionService, 99 : public base::RefCountedThreadSafe<ExtensionService,
100 BrowserThread::DeleteOnUIThread>, 100 BrowserThread::DeleteOnUIThread>,
101 public ExtensionUpdateService, 101 public ExtensionUpdateService,
102 public ExternalExtensionProviderInterface::VisitorInterface,
102 public NotificationObserver { 103 public NotificationObserver {
103 public: 104 public:
104 // Information about a registered component extension. 105 // Information about a registered component extension.
105 struct ComponentExtensionInfo { 106 struct ComponentExtensionInfo {
106 ComponentExtensionInfo(const std::string& manifest, 107 ComponentExtensionInfo(const std::string& manifest,
107 const FilePath& root_directory) 108 const FilePath& root_directory)
108 : manifest(manifest), 109 : manifest(manifest),
109 root_directory(root_directory) { 110 root_directory(root_directory) {
110 } 111 }
111 112
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Continues loading all know extensions. It can be called from 292 // Continues loading all know extensions. It can be called from
292 // LoadAllExtensions or from file thread if we had to relocalize manifest 293 // LoadAllExtensions or from file thread if we had to relocalize manifest
293 // (write_to_prefs is true in that case). 294 // (write_to_prefs is true in that case).
294 void ContinueLoadAllExtensions(ExtensionPrefs::ExtensionsInfo* info, 295 void ContinueLoadAllExtensions(ExtensionPrefs::ExtensionsInfo* info,
295 base::TimeTicks start_time, 296 base::TimeTicks start_time,
296 bool write_to_prefs); 297 bool write_to_prefs);
297 298
298 // Check for updates (or potentially new extensions from external providers) 299 // Check for updates (or potentially new extensions from external providers)
299 void CheckForExternalUpdates(); 300 void CheckForExternalUpdates();
300 301
301 // Copies the list of force-installed extensions from the user PrefService
302 // to ExternalPolicyExtensionProvider.
303 void UpdateExternalPolicyExtensionProvider();
304
305 // Unload the specified extension. 302 // Unload the specified extension.
306 void UnloadExtension(const std::string& extension_id, 303 void UnloadExtension(const std::string& extension_id,
307 UnloadedExtensionInfo::Reason reason); 304 UnloadedExtensionInfo::Reason reason);
308 305
309 // Unload all extensions. This is currently only called on shutdown, and 306 // Unload all extensions. This is currently only called on shutdown, and
310 // does not send notifications. 307 // does not send notifications.
311 void UnloadAllExtensions(); 308 void UnloadAllExtensions();
312 309
313 // Called only by testing. 310 // Called only by testing.
314 void ReloadExtensions(); 311 void ReloadExtensions();
(...skipping 21 matching lines...) Expand all
336 // permissions the given extension has been granted. 333 // permissions the given extension has been granted.
337 bool ExtensionBindingsAllowed(const GURL& url); 334 bool ExtensionBindingsAllowed(const GURL& url);
338 335
339 // Returns the icon to display in the omnibox for the given extension. 336 // Returns the icon to display in the omnibox for the given extension.
340 const SkBitmap& GetOmniboxIcon(const std::string& extension_id); 337 const SkBitmap& GetOmniboxIcon(const std::string& extension_id);
341 338
342 // Returns the icon to display in the omnibox popup window for the given 339 // Returns the icon to display in the omnibox popup window for the given
343 // extension. 340 // extension.
344 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); 341 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id);
345 342
346 // Clear all ExternalExtensionProviders.
347 void ClearProvidersForTesting();
348
349 // Sets an ExternalExtensionProvider for the service to use during testing.
350 // Takes ownership of |test_provider|.
351 void AddProviderForTesting(ExternalExtensionProvider* test_provider);
352
353 // Called when the initial extensions load has completed. 343 // Called when the initial extensions load has completed.
354 virtual void OnLoadedInstalledExtensions(); 344 virtual void OnLoadedInstalledExtensions();
355 345
356 // Called when an extension has been loaded. 346 // Called when an extension has been loaded.
357 void OnExtensionLoaded(const Extension* extension); 347 void OnExtensionLoaded(const Extension* extension);
358 348
359 // Called by the backend when an extension has been installed. 349 // Called by the backend when an extension has been installed.
360 void OnExtensionInstalled(const Extension* extension); 350 void OnExtensionInstalled(const Extension* extension);
361 351
362 // Called by the backend when an external extension is found.
363 void OnExternalExtensionFileFound(const std::string& id,
364 const std::string& version,
365 const FilePath& path,
366 Extension::Location location);
367
368 // Checks if the privileges requested by |extension| have increased, and if 352 // Checks if the privileges requested by |extension| have increased, and if
369 // so, disables the extension and prompts the user to approve the change. 353 // so, disables the extension and prompts the user to approve the change.
370 void DisableIfPrivilegeIncrease(const Extension* extension); 354 void DisableIfPrivilegeIncrease(const Extension* extension);
371 355
372 // Go through each extensions in pref, unload blacklisted extensions 356 // Go through each extensions in pref, unload blacklisted extensions
373 // and update the blacklist state in pref. 357 // and update the blacklist state in pref.
374 virtual void UpdateExtensionBlacklist( 358 virtual void UpdateExtensionBlacklist(
375 const std::vector<std::string>& blacklist); 359 const std::vector<std::string>& blacklist);
376 360
377 // Go through each extension and unload those that the network admin has 361 // Go through each extension and unload those that the network admin has
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // This method is public because ExtensionServiceBackend can post to here. 403 // This method is public because ExtensionServiceBackend can post to here.
420 void ReportExtensionLoadError(const FilePath& extension_path, 404 void ReportExtensionLoadError(const FilePath& extension_path,
421 const std::string& error, 405 const std::string& error,
422 NotificationType type, 406 NotificationType type,
423 bool be_noisy); 407 bool be_noisy);
424 408
425 // ExtensionHost of background page calls this method right after its render 409 // ExtensionHost of background page calls this method right after its render
426 // view has been created. 410 // view has been created.
427 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 411 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host);
428 412
413 // For the extension in |version_path| with |id|, check to see if it's an
414 // externally managed extension. If so, uninstall it.
415 void CheckExternalUninstall(const std::string& id);
416
417 // Clear all ExternalExtensionProviders.
418 void ClearProvidersForTesting();
419
420 // Adds an ExternalExtensionProviderInterface for the service to use during
421 // testing. Takes ownership of |test_provider|.
422 void AddProviderForTesting(ExternalExtensionProviderInterface* test_provider);
423
424 // ExternalExtensionProvider::Visitor implementation.
425 virtual void OnExternalExtensionFileFound(const std::string& id,
426 const Version* version,
427 const FilePath& path,
428 Extension::Location location);
429
430 virtual void OnExternalExtensionUpdateUrlFound(const std::string& id,
431 const GURL& update_url,
432 Extension::Location location);
433
434 virtual void OnExternalProviderReady();
435
429 // NotificationObserver 436 // NotificationObserver
430 virtual void Observe(NotificationType type, 437 virtual void Observe(NotificationType type,
431 const NotificationSource& source, 438 const NotificationSource& source,
432 const NotificationDetails& details); 439 const NotificationDetails& details);
433 440
434 // Whether there are any apps installed. Component apps are not included. 441 // Whether there are any apps installed. Component apps are not included.
435 bool HasApps() const; 442 bool HasApps() const;
436 443
437 // Gets the set of loaded app ids. Component apps are not included. 444 // Gets the set of loaded app ids. Component apps are not included.
438 ExtensionIdSet GetAppIds() const; 445 ExtensionIdSet GetAppIds() const;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 typedef std::map<GURL, int> ProtectedStorageMap; 601 typedef std::map<GURL, int> ProtectedStorageMap;
595 ProtectedStorageMap protected_storage_map_; 602 ProtectedStorageMap protected_storage_map_;
596 603
597 // Manages the installation of default apps and the promotion of them in the 604 // Manages the installation of default apps and the promotion of them in the
598 // app launcher. 605 // app launcher.
599 DefaultApps default_apps_; 606 DefaultApps default_apps_;
600 607
601 // Flag to make sure event routers are only initialized once. 608 // Flag to make sure event routers are only initialized once.
602 bool event_routers_initialized_; 609 bool event_routers_initialized_;
603 610
611 // A collection of external extension providers. Each provider reads
612 // a source of external extension information. Examples include the
613 // windows registry and external_extensions.json.
614 ProviderCollection external_extension_providers_;
615
616 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
617 // extension URL is found. Used in CheckForExternalUpdates() to see
618 // if an update check is needed to install pending extensions.
619 bool external_extension_added_;
620
604 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 621 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
605 UpdatePendingExtensionAlreadyInstalled); 622 UpdatePendingExtensionAlreadyInstalled);
606 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 623 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
607 InstallAppsWithUnlimtedStorage); 624 InstallAppsWithUnlimtedStorage);
608 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 625 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
609 InstallAppsAndCheckStorageProtection); 626 InstallAppsAndCheckStorageProtection);
610 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 627 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
611 }; 628 };
612 629
613 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 630 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_browsertest.cc ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698