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

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

Issue 9694038: OBSOLETE REVIEW. See http://codereview.chromium.org/10382149/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/gtest_prod_util.h" 18 #include "base/gtest_prod_util.h"
19 #include "base/memory/linked_ptr.h" 19 #include "base/memory/linked_ptr.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/property_bag.h" 22 #include "base/property_bag.h"
23 #include "base/string16.h"
23 #include "base/time.h" 24 #include "base/time.h"
24 #include "base/tuple.h" 25 #include "base/tuple.h"
25 #include "chrome/browser/extensions/app_shortcut_manager.h" 26 #include "chrome/browser/extensions/app_shortcut_manager.h"
26 #include "chrome/browser/extensions/app_sync_bundle.h" 27 #include "chrome/browser/extensions/app_sync_bundle.h"
27 #include "chrome/browser/extensions/apps_promo.h" 28 #include "chrome/browser/extensions/apps_promo.h"
28 #include "chrome/browser/extensions/extension_icon_manager.h" 29 #include "chrome/browser/extensions/extension_icon_manager.h"
30 #include "chrome/browser/extensions/extension_management_policy.h"
29 #include "chrome/browser/extensions/extension_menu_manager.h" 31 #include "chrome/browser/extensions/extension_menu_manager.h"
30 #include "chrome/browser/extensions/extension_prefs.h" 32 #include "chrome/browser/extensions/extension_prefs.h"
31 #include "chrome/browser/extensions/extension_process_manager.h" 33 #include "chrome/browser/extensions/extension_process_manager.h"
32 #include "chrome/browser/extensions/extension_sync_bundle.h" 34 #include "chrome/browser/extensions/extension_sync_bundle.h"
33 #include "chrome/browser/extensions/extension_toolbar_model.h" 35 #include "chrome/browser/extensions/extension_toolbar_model.h"
34 #include "chrome/browser/extensions/extension_warning_set.h" 36 #include "chrome/browser/extensions/extension_warning_set.h"
35 #include "chrome/browser/extensions/extensions_quota_service.h" 37 #include "chrome/browser/extensions/extensions_quota_service.h"
36 #include "chrome/browser/extensions/external_extension_provider_interface.h" 38 #include "chrome/browser/extensions/external_extension_provider_interface.h"
37 #include "chrome/browser/extensions/pending_extension_manager.h" 39 #include "chrome/browser/extensions/pending_extension_manager.h"
38 #include "chrome/browser/extensions/process_map.h" 40 #include "chrome/browser/extensions/process_map.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 public: 92 public:
91 // A function that returns true if the given extension should be 93 // A function that returns true if the given extension should be
92 // included and false if it should be filtered out. Identical to 94 // included and false if it should be filtered out. Identical to
93 // PendingExtensionInfo::ShouldAllowInstallPredicate. 95 // PendingExtensionInfo::ShouldAllowInstallPredicate.
94 typedef bool (*ExtensionFilter)(const Extension&); 96 typedef bool (*ExtensionFilter)(const Extension&);
95 97
96 virtual ~ExtensionServiceInterface() {} 98 virtual ~ExtensionServiceInterface() {}
97 virtual const ExtensionSet* extensions() const = 0; 99 virtual const ExtensionSet* extensions() const = 0;
98 virtual const ExtensionSet* disabled_extensions() const = 0; 100 virtual const ExtensionSet* disabled_extensions() const = 0;
99 virtual PendingExtensionManager* pending_extension_manager() = 0; 101 virtual PendingExtensionManager* pending_extension_manager() = 0;
102 virtual ExtensionManagementPolicy* extension_management_policy() = 0;
100 103
101 // Install an update. Return true if the install can be started. 104 // Install an update. Return true if the install can be started.
102 // Set out_crx_installer to the installer if one was started. 105 // Set out_crx_installer to the installer if one was started.
103 virtual bool UpdateExtension( 106 virtual bool UpdateExtension(
104 const std::string& id, 107 const std::string& id,
105 const FilePath& path, 108 const FilePath& path,
106 const GURL& download_url, 109 const GURL& download_url,
107 CrxInstaller** out_crx_installer) = 0; 110 CrxInstaller** out_crx_installer) = 0;
108 virtual const Extension* GetExtensionById(const std::string& id, 111 virtual const Extension* GetExtensionById(const std::string& id,
109 bool include_disabled) const = 0; 112 bool include_disabled) const = 0;
(...skipping 21 matching lines...) Expand all
131 extension_misc::UnloadedExtensionReason reason) = 0; 134 extension_misc::UnloadedExtensionReason reason) = 0;
132 135
133 virtual void SyncExtensionChangeIfNeeded(const Extension& extension) = 0; 136 virtual void SyncExtensionChangeIfNeeded(const Extension& extension) = 0;
134 137
135 virtual bool is_ready() = 0; 138 virtual bool is_ready() = 0;
136 }; 139 };
137 140
138 // Manages installed and running Chromium extensions. 141 // Manages installed and running Chromium extensions.
139 class ExtensionService 142 class ExtensionService
140 : public ExtensionServiceInterface, 143 : public ExtensionServiceInterface,
144 public ExtensionManagementPolicy::Delegate,
141 public ExternalExtensionProviderInterface::VisitorInterface, 145 public ExternalExtensionProviderInterface::VisitorInterface,
142 public base::SupportsWeakPtr<ExtensionService>, 146 public base::SupportsWeakPtr<ExtensionService>,
143 public content::NotificationObserver { 147 public content::NotificationObserver {
144 public: 148 public:
145 using base::SupportsWeakPtr<ExtensionService>::AsWeakPtr; 149 using base::SupportsWeakPtr<ExtensionService>::AsWeakPtr;
146 150
147 // The name of the directory inside the profile where extensions are 151 // The name of the directory inside the profile where extensions are
148 // installed to. 152 // installed to.
149 static const char* kInstallDirectoryName; 153 static const char* kInstallDirectoryName;
150 154
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 virtual const ExtensionSet* disabled_extensions() const OVERRIDE; 211 virtual const ExtensionSet* disabled_extensions() const OVERRIDE;
208 const ExtensionSet* terminated_extensions() const; 212 const ExtensionSet* terminated_extensions() const;
209 213
210 // Retuns a set of all installed, disabled, and terminated extensions and 214 // Retuns a set of all installed, disabled, and terminated extensions and
211 // transfers ownership to caller. 215 // transfers ownership to caller.
212 const ExtensionSet* GenerateInstalledExtensionsSet() const; 216 const ExtensionSet* GenerateInstalledExtensionsSet() const;
213 217
214 // Gets the object managing the set of pending extensions. 218 // Gets the object managing the set of pending extensions.
215 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE; 219 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
216 220
221 virtual ExtensionManagementPolicy* extension_management_policy() OVERRIDE;
222
217 const FilePath& install_directory() const { return install_directory_; } 223 const FilePath& install_directory() const { return install_directory_; }
218 224
219 AppsPromo* apps_promo() { return &apps_promo_; } 225 AppsPromo* apps_promo() { return &apps_promo_; }
220 226
221 extensions::ProcessMap* process_map() { return &process_map_; } 227 extensions::ProcessMap* process_map() { return &process_map_; }
222 228
223 // Whether this extension can run in an incognito window. 229 // Whether this extension can run in an incognito window.
224 virtual bool IsIncognitoEnabled(const std::string& extension_id) const; 230 virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
225 virtual void SetIsIncognitoEnabled(const std::string& extension_id, 231 virtual void SetIsIncognitoEnabled(const std::string& extension_id,
226 bool enabled); 232 bool enabled);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // callers should never set to true. 332 // callers should never set to true.
327 // 333 //
328 // We pass the |extension_id| by value to avoid having it deleted from under 334 // We pass the |extension_id| by value to avoid having it deleted from under
329 // us incase someone calls it with Extension::id() or another string that we 335 // us incase someone calls it with Extension::id() or another string that we
330 // are going to delete in this function. 336 // are going to delete in this function.
331 // 337 //
332 // TODO(aa): Remove |external_uninstall| -- this information should be passed 338 // TODO(aa): Remove |external_uninstall| -- this information should be passed
333 // to ExtensionPrefs some other way. 339 // to ExtensionPrefs some other way.
334 virtual bool UninstallExtension(std::string extension_id, 340 virtual bool UninstallExtension(std::string extension_id,
335 bool external_uninstall, 341 bool external_uninstall,
336 std::string* error); 342 string16* error);
337 343
338 virtual bool IsExtensionEnabled( 344 virtual bool IsExtensionEnabled(
339 const std::string& extension_id) const OVERRIDE; 345 const std::string& extension_id) const OVERRIDE;
340 virtual bool IsExternalExtensionUninstalled( 346 virtual bool IsExternalExtensionUninstalled(
341 const std::string& extension_id) const OVERRIDE; 347 const std::string& extension_id) const OVERRIDE;
342 348
349 // ExtensionManagementPolicy::Delegate implementation.
350 // The ExtensionService is the keeper of the ExtensionManagementPolicy so
351 // other callers can query it. It's also an ExtensionManagementPolicy
352 // delegate itself, exposing any restrictions imposed by an individual
353 // extension.
354 virtual bool UserMayModifyStatus(const Extension* extension,
355 string16* error) const OVERRIDE;
356 virtual bool UserMayModifyUsage(const Extension* extension,
357 string16* error) const OVERRIDE;
358 virtual bool MustRemainEnabled(const Extension* extension,
359 string16* error) const OVERRIDE;
360
343 // Enables the extension. If the extension is already enabled, does 361 // Enables the extension. If the extension is already enabled, does
344 // nothing. 362 // nothing.
345 virtual void EnableExtension(const std::string& extension_id); 363 virtual void EnableExtension(const std::string& extension_id);
346 364
347 // Disables the extension. If the extension is already disabled, or 365 // Disables the extension. If the extension is already disabled, or
348 // cannot be disabled, does nothing. 366 // cannot be disabled, does nothing.
349 virtual void DisableExtension(const std::string& extension_id, 367 virtual void DisableExtension(const std::string& extension_id,
350 Extension::DisableReason disable_reason); 368 Extension::DisableReason disable_reason);
351 369
352 // Updates the |extension|'s granted permissions lists to include all 370 // Updates the |extension|'s granted permissions lists to include all
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // Initializes the |extension|'s active permission set and disables the 426 // Initializes the |extension|'s active permission set and disables the
409 // extension if the privilege level has increased (e.g., due to an upgrade). 427 // extension if the privilege level has increased (e.g., due to an upgrade).
410 void InitializePermissions(const Extension* extension); 428 void InitializePermissions(const Extension* extension);
411 429
412 // Go through each extensions in pref, unload blacklisted extensions 430 // Go through each extensions in pref, unload blacklisted extensions
413 // and update the blacklist state in pref. 431 // and update the blacklist state in pref.
414 virtual void UpdateExtensionBlacklist( 432 virtual void UpdateExtensionBlacklist(
415 const std::vector<std::string>& blacklist) OVERRIDE; 433 const std::vector<std::string>& blacklist) OVERRIDE;
416 434
417 // Go through each extension and unload those that the network admin has 435 // Go through each extension and unload those that the network admin has
418 // put on the blacklist (not to be confused with the Google managed blacklist 436 // put on the blacklist (not to be confused with the Google-managed blacklist)
419 // set of extensions. 437 // set of extensions.
420 virtual void CheckAdminBlacklist() OVERRIDE; 438 virtual void CheckAdminBlacklist() OVERRIDE;
421 439
422 virtual void CheckForUpdatesSoon() OVERRIDE; 440 virtual void CheckForUpdatesSoon() OVERRIDE;
423 441
424 // SyncableService implementation. 442 // SyncableService implementation.
425 virtual SyncError MergeDataAndStartSyncing( 443 virtual SyncError MergeDataAndStartSyncing(
426 syncable::ModelType type, 444 syncable::ModelType type,
427 const SyncDataList& initial_sync_data, 445 const SyncDataList& initial_sync_data,
428 scoped_ptr<SyncChangeProcessor> sync_processor, 446 scoped_ptr<SyncChangeProcessor> sync_processor,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 const extensions::ExtensionSyncData& extension_sync_data, 677 const extensions::ExtensionSyncData& extension_sync_data,
660 syncable::ModelType type); 678 syncable::ModelType type);
661 679
662 // Look up an extension by ID, optionally including either or both of enabled 680 // Look up an extension by ID, optionally including either or both of enabled
663 // and disabled extensions. 681 // and disabled extensions.
664 const Extension* GetExtensionByIdInternal(const std::string& id, 682 const Extension* GetExtensionByIdInternal(const std::string& id,
665 bool include_enabled, 683 bool include_enabled,
666 bool include_disabled, 684 bool include_disabled,
667 bool include_terminated) const; 685 bool include_terminated) const;
668 686
687 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
688 // Returns |modifiable_value| if the extension can be modified.
689 bool ExtensionManagementPolicyImpl(const Extension* extension,
690 string16* error,
691 bool modifiable_value) const;
692
669 // Adds the given extension to the list of terminated extensions if 693 // Adds the given extension to the list of terminated extensions if
670 // it is not already there and unloads it. 694 // it is not already there and unloads it.
671 void TrackTerminatedExtension(const Extension* extension); 695 void TrackTerminatedExtension(const Extension* extension);
672 696
673 // Removes the extension with the given id from the list of 697 // Removes the extension with the given id from the list of
674 // terminated extensions if it is there. 698 // terminated extensions if it is there.
675 void UntrackTerminatedExtension(const std::string& id); 699 void UntrackTerminatedExtension(const std::string& id);
676 700
677 // Handles sending notification that |extension| was loaded. 701 // Handles sending notification that |extension| was loaded.
678 void NotifyExtensionLoaded(const Extension* extension); 702 void NotifyExtensionLoaded(const Extension* extension);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 740
717 // The list of installed extensions that have been disabled. 741 // The list of installed extensions that have been disabled.
718 ExtensionSet disabled_extensions_; 742 ExtensionSet disabled_extensions_;
719 743
720 // The list of installed extensions that have been terminated. 744 // The list of installed extensions that have been terminated.
721 ExtensionSet terminated_extensions_; 745 ExtensionSet terminated_extensions_;
722 746
723 // Hold the set of pending extensions. 747 // Hold the set of pending extensions.
724 PendingExtensionManager pending_extension_manager_; 748 PendingExtensionManager pending_extension_manager_;
725 749
750 // ***
751 ExtensionManagementPolicy extension_management_policy_;
752
726 // The map of extension IDs to their runtime data. 753 // The map of extension IDs to their runtime data.
727 ExtensionRuntimeDataMap extension_runtime_data_; 754 ExtensionRuntimeDataMap extension_runtime_data_;
728 755
729 // Holds a map between renderer process IDs that are associated with an 756 // Holds a map between renderer process IDs that are associated with an
730 // installed app and their app. 757 // installed app and their app.
731 typedef std::map<int, scoped_refptr<const Extension> > InstalledAppMap; 758 typedef std::map<int, scoped_refptr<const Extension> > InstalledAppMap;
732 InstalledAppMap installed_app_hosts_; 759 InstalledAppMap installed_app_hosts_;
733 760
734 // The full path to the directory where extensions are installed. 761 // The full path to the directory where extensions are installed.
735 FilePath install_directory_; 762 FilePath install_directory_;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 scoped_ptr<ExtensionGlobalError> extension_global_error_; 874 scoped_ptr<ExtensionGlobalError> extension_global_error_;
848 875
849 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 876 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
850 InstallAppsWithUnlimtedStorage); 877 InstallAppsWithUnlimtedStorage);
851 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 878 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
852 InstallAppsAndCheckStorageProtection); 879 InstallAppsAndCheckStorageProtection);
853 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 880 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
854 }; 881 };
855 882
856 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 883 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698