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

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

Issue 5730004: Rename ExtensionsService to ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 10 years 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) 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_EXTENSION_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_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"
(...skipping 10 matching lines...) Expand all
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.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 ExtensionsServiceBackend; 37 class ExtensionServiceBackend;
38 class ExtensionToolbarModel; 38 class ExtensionToolbarModel;
39 class ExtensionUpdater; 39 class ExtensionUpdater;
40 class GURL; 40 class GURL;
41 class Profile; 41 class Profile;
42 class Version; 42 class Version;
43 43
44 // A pending extension is an extension that hasn't been installed yet 44 // A pending extension is an extension that hasn't been installed yet
45 // and is intended to be installed in the next auto-update cycle. The 45 // and is intended to be installed in the next auto-update cycle. The
46 // update URL of a pending extension may be blank, in which case a 46 // update URL of a pending extension may be blank, in which case a
47 // default one is assumed. 47 // default one is assumed.
(...skipping 25 matching lines...) Expand all
73 bool enable_on_install; 73 bool enable_on_install;
74 bool enable_incognito_on_install; 74 bool enable_incognito_on_install;
75 Extension::Location install_source; 75 Extension::Location install_source;
76 }; 76 };
77 77
78 // A PendingExtensionMap is a map from IDs of pending extensions to 78 // A PendingExtensionMap is a map from IDs of pending extensions to
79 // their info. 79 // their info.
80 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; 80 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap;
81 81
82 // This is an interface class to encapsulate the dependencies that 82 // This is an interface class to encapsulate the dependencies that
83 // ExtensionUpdater has on ExtensionsService. This allows easy mocking. 83 // ExtensionUpdater has on ExtensionService. This allows easy mocking.
84 class ExtensionUpdateService { 84 class ExtensionUpdateService {
85 public: 85 public:
86 virtual ~ExtensionUpdateService() {} 86 virtual ~ExtensionUpdateService() {}
87 virtual const ExtensionList* extensions() const = 0; 87 virtual const ExtensionList* extensions() const = 0;
88 virtual const PendingExtensionMap& pending_extensions() const = 0; 88 virtual const PendingExtensionMap& pending_extensions() const = 0;
89 virtual void UpdateExtension(const std::string& id, const FilePath& path, 89 virtual void UpdateExtension(const std::string& id, const FilePath& path,
90 const GURL& download_url) = 0; 90 const GURL& download_url) = 0;
91 virtual const Extension* GetExtensionById(const std::string& id, 91 virtual const Extension* GetExtensionById(const std::string& id,
92 bool include_disabled) = 0; 92 bool include_disabled) = 0;
93 virtual void UpdateExtensionBlacklist( 93 virtual void UpdateExtensionBlacklist(
94 const std::vector<std::string>& blacklist) = 0; 94 const std::vector<std::string>& blacklist) = 0;
95 virtual void CheckAdminBlacklist() = 0; 95 virtual void CheckAdminBlacklist() = 0;
96 virtual bool HasInstalledExtensions() = 0; 96 virtual bool HasInstalledExtensions() = 0;
97 97
98 virtual ExtensionPrefs* extension_prefs() = 0; 98 virtual ExtensionPrefs* extension_prefs() = 0;
99 }; 99 };
100 100
101 // Manages installed and running Chromium extensions. 101 // Manages installed and running Chromium extensions.
102 class ExtensionsService 102 class ExtensionService
103 : public base::RefCountedThreadSafe<ExtensionsService, 103 : public base::RefCountedThreadSafe<ExtensionService,
104 BrowserThread::DeleteOnUIThread>, 104 BrowserThread::DeleteOnUIThread>,
105 public ExtensionUpdateService, 105 public ExtensionUpdateService,
106 public NotificationObserver { 106 public NotificationObserver {
107 public: 107 public:
108 // Information about a registered component extension. 108 // Information about a registered component extension.
109 struct ComponentExtensionInfo { 109 struct ComponentExtensionInfo {
110 ComponentExtensionInfo(const std::string& manifest, 110 ComponentExtensionInfo(const std::string& manifest,
111 const FilePath& root_directory) 111 const FilePath& root_directory)
112 : manifest(manifest), 112 : manifest(manifest),
113 root_directory(root_directory) { 113 root_directory(root_directory) {
114 } 114 }
115 115
116 // The extension's manifest. This is required for component extensions so 116 // The extension's manifest. This is required for component extensions so
117 // that ExtensionsService doesn't need to go to disk to load them. 117 // that ExtensionService doesn't need to go to disk to load them.
118 std::string manifest; 118 std::string manifest;
119 119
120 // Directory where the extension is stored. 120 // Directory where the extension is stored.
121 FilePath root_directory; 121 FilePath root_directory;
122 }; 122 };
123 123
124 // The name of the directory inside the profile where extensions are 124 // The name of the directory inside the profile where extensions are
125 // installed to. 125 // installed to.
126 static const char* kInstallDirectoryName; 126 static const char* kInstallDirectoryName;
127 127
(...skipping 11 matching lines...) Expand all
139 139
140 // Determine if the downloaded extension came from the theme mini-gallery, 140 // Determine if the downloaded extension came from the theme mini-gallery,
141 // Used to test if we need to show the "Loading" dialog for themes. 141 // Used to test if we need to show the "Loading" dialog for themes.
142 static bool IsDownloadFromMiniGallery(const GURL& download_url); 142 static bool IsDownloadFromMiniGallery(const GURL& download_url);
143 143
144 // Returns whether the URL is from either a hosted or packaged app. 144 // Returns whether the URL is from either a hosted or packaged app.
145 bool IsInstalledApp(const GURL& url); 145 bool IsInstalledApp(const GURL& url);
146 146
147 // Attempts to uninstall an extension from a given ExtensionService. Returns 147 // Attempts to uninstall an extension from a given ExtensionService. Returns
148 // true iff the target extension exists. 148 // true iff the target extension exists.
149 static bool UninstallExtensionHelper(ExtensionsService* extensions_service, 149 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
150 const std::string& extension_id); 150 const std::string& extension_id);
151 151
152 // Constructor stores pointers to |profile| and |extension_prefs| but 152 // Constructor stores pointers to |profile| and |extension_prefs| but
153 // ownership remains at caller. 153 // ownership remains at caller.
154 ExtensionsService(Profile* profile, 154 ExtensionService(Profile* profile,
155 const CommandLine* command_line, 155 const CommandLine* command_line,
156 const FilePath& install_directory, 156 const FilePath& install_directory,
157 ExtensionPrefs* extension_prefs, 157 ExtensionPrefs* extension_prefs,
158 bool autoupdate_enabled); 158 bool autoupdate_enabled);
159 159
160 // Gets the list of currently installed extensions. 160 // Gets the list of currently installed extensions.
161 virtual const ExtensionList* extensions() const; 161 virtual const ExtensionList* extensions() const;
162 virtual const ExtensionList* disabled_extensions() const; 162 virtual const ExtensionList* disabled_extensions() const;
163 163
164 // Gets the set of pending extensions. 164 // Gets the set of pending extensions.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 411
412 ExtensionsQuotaService* quota_service() { return &quota_service_; } 412 ExtensionsQuotaService* quota_service() { return &quota_service_; }
413 413
414 ExtensionMenuManager* menu_manager() { return &menu_manager_; } 414 ExtensionMenuManager* menu_manager() { return &menu_manager_; }
415 415
416 const std::map<GURL, int>& protected_storage_map() const { 416 const std::map<GURL, int>& protected_storage_map() const {
417 return protected_storage_map_; 417 return protected_storage_map_;
418 } 418 }
419 419
420 // Notify the frontend that there was an error loading an extension. 420 // Notify the frontend that there was an error loading an extension.
421 // This method is public because ExtensionsServiceBackend can post to here. 421 // This method is public because ExtensionServiceBackend can post to here.
422 void ReportExtensionLoadError(const FilePath& extension_path, 422 void ReportExtensionLoadError(const FilePath& extension_path,
423 const std::string& error, 423 const std::string& error,
424 NotificationType type, 424 NotificationType type,
425 bool be_noisy); 425 bool be_noisy);
426 426
427 // ExtensionHost of background page calls this method right after its render 427 // ExtensionHost of background page calls this method right after its render
428 // view has been created. 428 // view has been created.
429 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 429 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host);
430 430
431 // NotificationObserver 431 // NotificationObserver
432 virtual void Observe(NotificationType type, 432 virtual void Observe(NotificationType type,
433 const NotificationSource& source, 433 const NotificationSource& source,
434 const NotificationDetails& details); 434 const NotificationDetails& details);
435 435
436 // Whether there are any apps installed. Component apps are not included. 436 // Whether there are any apps installed. Component apps are not included.
437 bool HasApps() const; 437 bool HasApps() const;
438 438
439 // Gets the set of loaded app ids. Component apps are not included. 439 // Gets the set of loaded app ids. Component apps are not included.
440 ExtensionIdSet GetAppIds() const; 440 ExtensionIdSet GetAppIds() const;
441 441
442 private: 442 private:
443 friend class BrowserThread; 443 friend class BrowserThread;
444 friend class DeleteTask<ExtensionsService>; 444 friend class DeleteTask<ExtensionService>;
445 445
446 // Contains Extension data that can change during the life of the process, 446 // Contains Extension data that can change during the life of the process,
447 // but does not persist across restarts. 447 // but does not persist across restarts.
448 struct ExtensionRuntimeData { 448 struct ExtensionRuntimeData {
449 // True if the background page is ready. 449 // True if the background page is ready.
450 bool background_page_ready; 450 bool background_page_ready;
451 451
452 // True while the extension is being upgraded. 452 // True while the extension is being upgraded.
453 bool being_upgraded; 453 bool being_upgraded;
454 454
455 // Generic bag of runtime data that users can associate with extensions. 455 // Generic bag of runtime data that users can associate with extensions.
456 PropertyBag property_bag; 456 PropertyBag property_bag;
457 457
458 ExtensionRuntimeData(); 458 ExtensionRuntimeData();
459 ~ExtensionRuntimeData(); 459 ~ExtensionRuntimeData();
460 }; 460 };
461 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; 461 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
462 462
463 virtual ~ExtensionsService(); 463 virtual ~ExtensionService();
464 464
465 // Clear all persistent data that may have been stored by the extension. 465 // Clear all persistent data that may have been stored by the extension.
466 void ClearExtensionData(const GURL& extension_url); 466 void ClearExtensionData(const GURL& extension_url);
467 467
468 // Look up an extension by ID, optionally including either or both of enabled 468 // Look up an extension by ID, optionally including either or both of enabled
469 // and disabled extensions. 469 // and disabled extensions.
470 const Extension* GetExtensionByIdInternal(const std::string& id, 470 const Extension* GetExtensionByIdInternal(const std::string& id,
471 bool include_enabled, 471 bool include_enabled,
472 bool include_disabled); 472 bool include_disabled);
473 473
(...skipping 17 matching lines...) Expand all
491 491
492 // Helper method. Loads extension from prefs. 492 // Helper method. Loads extension from prefs.
493 void LoadInstalledExtension(const ExtensionInfo& info, bool write_to_prefs); 493 void LoadInstalledExtension(const ExtensionInfo& info, bool write_to_prefs);
494 494
495 // Helper methods to configure the storage services accordingly. 495 // Helper methods to configure the storage services accordingly.
496 void GrantProtectedStorage(const Extension* extension); 496 void GrantProtectedStorage(const Extension* extension);
497 void RevokeProtectedStorage(const Extension* extension); 497 void RevokeProtectedStorage(const Extension* extension);
498 void GrantUnlimitedStorage(const Extension* extension); 498 void GrantUnlimitedStorage(const Extension* extension);
499 void RevokeUnlimitedStorage(const Extension* extension); 499 void RevokeUnlimitedStorage(const Extension* extension);
500 500
501 // The profile this ExtensionsService is part of. 501 // The profile this ExtensionService is part of.
502 Profile* profile_; 502 Profile* profile_;
503 503
504 // Preferences for the owning profile (weak reference). 504 // Preferences for the owning profile (weak reference).
505 ExtensionPrefs* extension_prefs_; 505 ExtensionPrefs* extension_prefs_;
506 506
507 // The current list of installed extensions. 507 // The current list of installed extensions.
508 ExtensionList extensions_; 508 ExtensionList extensions_;
509 509
510 // The list of installed extensions that have been disabled. 510 // The list of installed extensions that have been disabled.
511 ExtensionList disabled_extensions_; 511 ExtensionList disabled_extensions_;
512 512
513 // The set of pending extensions. 513 // The set of pending extensions.
514 PendingExtensionMap pending_extensions_; 514 PendingExtensionMap pending_extensions_;
515 515
516 // The map of extension IDs to their runtime data. 516 // The map of extension IDs to their runtime data.
517 ExtensionRuntimeDataMap extension_runtime_data_; 517 ExtensionRuntimeDataMap extension_runtime_data_;
518 518
519 // The full path to the directory where extensions are installed. 519 // The full path to the directory where extensions are installed.
520 FilePath install_directory_; 520 FilePath install_directory_;
521 521
522 // Whether or not extensions are enabled. 522 // Whether or not extensions are enabled.
523 bool extensions_enabled_; 523 bool extensions_enabled_;
524 524
525 // Whether to notify users when they attempt to install an extension. 525 // Whether to notify users when they attempt to install an extension.
526 bool show_extensions_prompts_; 526 bool show_extensions_prompts_;
527 527
528 // The backend that will do IO on behalf of this instance. 528 // The backend that will do IO on behalf of this instance.
529 scoped_refptr<ExtensionsServiceBackend> backend_; 529 scoped_refptr<ExtensionServiceBackend> backend_;
530 530
531 // Used by dispatchers to limit API quota for individual extensions. 531 // Used by dispatchers to limit API quota for individual extensions.
532 ExtensionsQuotaService quota_service_; 532 ExtensionsQuotaService quota_service_;
533 533
534 // Record that Init() has been called, and NotificationType::EXTENSIONS_READY 534 // Record that Init() has been called, and NotificationType::EXTENSIONS_READY
535 // has fired. 535 // has fired.
536 bool ready_; 536 bool ready_;
537 537
538 // Our extension updater, if updates are turned on. 538 // Our extension updater, if updates are turned on.
539 scoped_refptr<ExtensionUpdater> updater_; 539 scoped_refptr<ExtensionUpdater> updater_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 typedef std::map<GURL, int> ProtectedStorageMap; 584 typedef std::map<GURL, int> ProtectedStorageMap;
585 ProtectedStorageMap protected_storage_map_; 585 ProtectedStorageMap protected_storage_map_;
586 586
587 // Manages the installation of default apps and the promotion of them in the 587 // Manages the installation of default apps and the promotion of them in the
588 // app launcher. 588 // app launcher.
589 DefaultApps default_apps_; 589 DefaultApps default_apps_;
590 590
591 // Flag to make sure event routers are only initialized once. 591 // Flag to make sure event routers are only initialized once.
592 bool event_routers_initialized_; 592 bool event_routers_initialized_;
593 593
594 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 594 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
595 UpdatePendingExtensionAlreadyInstalled); 595 UpdatePendingExtensionAlreadyInstalled);
596 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 596 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
597 InstallAppsWithUnlimtedStorage); 597 InstallAppsWithUnlimtedStorage);
598 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 598 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
599 InstallAppsAndCheckStorageProtection); 599 InstallAppsAndCheckStorageProtection);
600 DISALLOW_COPY_AND_ASSIGN(ExtensionsService); 600 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
601 }; 601 };
602 602
603 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 603 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_proxy_api.cc ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698