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

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

Issue 3522015: Implement new strategy for default apps (Closed)
Patch Set: all done Created 10 years, 2 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
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_EXTENSIONS_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/linked_ptr.h" 17 #include "base/linked_ptr.h"
18 #include "base/ref_counted.h" 18 #include "base/ref_counted.h"
19 #include "base/task.h" 19 #include "base/task.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/tuple.h" 21 #include "base/tuple.h"
22 #include "chrome/browser/chrome_thread.h" 22 #include "chrome/browser/chrome_thread.h"
23 #include "chrome/browser/extensions/default_apps.h"
23 #include "chrome/browser/extensions/extension_icon_manager.h" 24 #include "chrome/browser/extensions/extension_icon_manager.h"
24 #include "chrome/browser/extensions/extension_menu_manager.h" 25 #include "chrome/browser/extensions/extension_menu_manager.h"
25 #include "chrome/browser/extensions/extension_prefs.h" 26 #include "chrome/browser/extensions/extension_prefs.h"
26 #include "chrome/browser/extensions/extension_process_manager.h" 27 #include "chrome/browser/extensions/extension_process_manager.h"
27 #include "chrome/browser/extensions/extension_toolbar_model.h" 28 #include "chrome/browser/extensions/extension_toolbar_model.h"
28 #include "chrome/browser/extensions/extensions_quota_service.h" 29 #include "chrome/browser/extensions/extensions_quota_service.h"
29 #include "chrome/browser/extensions/external_extension_provider.h" 30 #include "chrome/browser/extensions/external_extension_provider.h"
30 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" 31 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h"
31 #include "chrome/browser/prefs/pref_change_registrar.h" 32 #include "chrome/browser/prefs/pref_change_registrar.h"
32 #include "chrome/common/notification_observer.h" 33 #include "chrome/common/notification_observer.h"
(...skipping 11 matching lines...) Expand all
44 // A pending extension is an extension that hasn't been installed yet 45 // 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 46 // 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 47 // update URL of a pending extension may be blank, in which case a
47 // default one is assumed. 48 // default one is assumed.
48 struct PendingExtensionInfo { 49 struct PendingExtensionInfo {
49 // TODO(skerner): Consider merging ExpectedCrxType with 50 // TODO(skerner): Consider merging ExpectedCrxType with
50 // browser_sync::ExtensionType. 51 // browser_sync::ExtensionType.
51 enum ExpectedCrxType { 52 enum ExpectedCrxType {
52 UNKNOWN, // Sometimes we don't know the type of a pending item. An 53 UNKNOWN, // Sometimes we don't know the type of a pending item. An
53 // update URL from external_extensions.json is one such case. 54 // update URL from external_extensions.json is one such case.
55 APP,
54 THEME, 56 THEME,
55 EXTENSION 57 EXTENSION
56 }; 58 };
57 59
58 PendingExtensionInfo(const GURL& update_url, 60 PendingExtensionInfo(const GURL& update_url,
59 ExpectedCrxType expected_crx_type, 61 ExpectedCrxType expected_crx_type,
60 bool is_from_sync, 62 bool is_from_sync,
61 bool install_silently, 63 bool install_silently,
62 bool enable_on_install, 64 bool enable_on_install,
63 bool enable_incognito_on_install); 65 bool enable_incognito_on_install,
66 Extension::Location install_source);
64 67
65 PendingExtensionInfo(); 68 PendingExtensionInfo();
66 69
67 GURL update_url; 70 GURL update_url;
68 ExpectedCrxType expected_crx_type; 71 ExpectedCrxType expected_crx_type;
69 bool is_from_sync; // This update check was initiated from sync. 72 bool is_from_sync; // This update check was initiated from sync.
70 bool install_silently; 73 bool install_silently;
71 bool enable_on_install; 74 bool enable_on_install;
72 bool enable_incognito_on_install; 75 bool enable_incognito_on_install;
76 Extension::Location install_source;
73 }; 77 };
74 78
75 // A PendingExtensionMap is a map from IDs of pending extensions to 79 // A PendingExtensionMap is a map from IDs of pending extensions to
76 // their info. 80 // their info.
77 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap; 81 typedef std::map<std::string, PendingExtensionInfo> PendingExtensionMap;
78 82
79 // This is an interface class to encapsulate the dependencies that 83 // This is an interface class to encapsulate the dependencies that
80 // ExtensionUpdater has on ExtensionsService. This allows easy mocking. 84 // ExtensionUpdater has on ExtensionsService. This allows easy mocking.
81 class ExtensionUpdateService { 85 class ExtensionUpdateService {
82 public: 86 public:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Registers an extension to be loaded as a component extension. 166 // Registers an extension to be loaded as a component extension.
163 void register_component_extension(const ComponentExtensionInfo& info) { 167 void register_component_extension(const ComponentExtensionInfo& info) {
164 component_extension_manifests_.push_back(info); 168 component_extension_manifests_.push_back(info);
165 } 169 }
166 170
167 // Returns true if any extensions are installed. 171 // Returns true if any extensions are installed.
168 virtual bool HasInstalledExtensions() { 172 virtual bool HasInstalledExtensions() {
169 return !(extensions_.empty() && disabled_extensions_.empty()); 173 return !(extensions_.empty() && disabled_extensions_.empty());
170 } 174 }
171 175
176 const FilePath& install_directory() const { return install_directory_; }
177
178 DefaultApps* default_apps() { return &default_apps_; }
179
172 // Whether this extension can run in an incognito window. 180 // Whether this extension can run in an incognito window.
173 bool IsIncognitoEnabled(const Extension* extension); 181 bool IsIncognitoEnabled(const Extension* extension);
174 void SetIsIncognitoEnabled(Extension* extension, bool enabled); 182 void SetIsIncognitoEnabled(Extension* extension, bool enabled);
175 183
176 // Whether this extension can inject scripts into pages with file URLs. 184 // Whether this extension can inject scripts into pages with file URLs.
177 bool AllowFileAccess(const Extension* extension); 185 bool AllowFileAccess(const Extension* extension);
178 void SetAllowFileAccess(Extension* extension, bool allow); 186 void SetAllowFileAccess(Extension* extension, bool allow);
179 187
180 const FilePath& install_directory() const { return install_directory_; }
181
182 // Initialize and start all installed extensions. 188 // Initialize and start all installed extensions.
183 void Init(); 189 void Init();
184 190
185 // Start up the extension event routers. 191 // Start up the extension event routers.
186 void InitEventRouters(); 192 void InitEventRouters();
187 193
188 // Look up an extension by ID. 194 // Look up an extension by ID.
189 Extension* GetExtensionById(const std::string& id, bool include_disabled) { 195 Extension* GetExtensionById(const std::string& id, bool include_disabled) {
190 return GetExtensionByIdInternal(id, true, include_disabled); 196 return GetExtensionByIdInternal(id, true, include_disabled);
191 } 197 }
(...skipping 26 matching lines...) Expand all
218 const std::string& id, const GURL& update_url, 224 const std::string& id, const GURL& update_url,
219 const PendingExtensionInfo::ExpectedCrxType expected_crx_type, 225 const PendingExtensionInfo::ExpectedCrxType expected_crx_type,
220 bool install_silently, bool enable_on_install, 226 bool install_silently, bool enable_on_install,
221 bool enable_incognito_on_install); 227 bool enable_incognito_on_install);
222 228
223 // Given an extension id and an update URL, schedule the extension 229 // Given an extension id and an update URL, schedule the extension
224 // to be fetched, installed, and activated. 230 // to be fetched, installed, and activated.
225 void AddPendingExtensionFromExternalUpdateUrl(const std::string& id, 231 void AddPendingExtensionFromExternalUpdateUrl(const std::string& id,
226 const GURL& update_url); 232 const GURL& update_url);
227 233
234 // Like the above. Always installed silently, and defaults update url
235 // from extension id.
236 void AddPendingExtensionFromDefaultAppList(const std::string& id);
237
228 // Reloads the specified extension. 238 // Reloads the specified extension.
229 void ReloadExtension(const std::string& extension_id); 239 void ReloadExtension(const std::string& extension_id);
230 240
231 // Uninstalls the specified extension. Callers should only call this method 241 // Uninstalls the specified extension. Callers should only call this method
232 // with extensions that exist. |external_uninstall| is a magical parameter 242 // with extensions that exist. |external_uninstall| is a magical parameter
233 // that is only used to send information to ExtensionPrefs, which external 243 // that is only used to send information to ExtensionPrefs, which external
234 // callers should never set to true. 244 // callers should never set to true.
235 // TODO(aa): Remove |external_uninstall| -- this information should be passed 245 // TODO(aa): Remove |external_uninstall| -- this information should be passed
236 // to ExtensionPrefs some other way. 246 // to ExtensionPrefs some other way.
237 void UninstallExtension(const std::string& extension_id, 247 void UninstallExtension(const std::string& extension_id,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 389
380 // ExtensionHost of background page calls this method right after its render 390 // ExtensionHost of background page calls this method right after its render
381 // view has been created. 391 // view has been created.
382 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); 392 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host);
383 393
384 // NotificationObserver 394 // NotificationObserver
385 virtual void Observe(NotificationType type, 395 virtual void Observe(NotificationType type,
386 const NotificationSource& source, 396 const NotificationSource& source,
387 const NotificationDetails& details); 397 const NotificationDetails& details);
388 398
389 // Whether there are any apps installed. 399 // Whether there are any apps installed. Component apps are not included.
390 bool HasApps(); 400 bool HasApps() const;
401
402 // Gets the set of loaded app ids. Component apps are not included.
403 ExtensionIdSet GetAppIds() const;
391 404
392 private: 405 private:
393 virtual ~ExtensionsService(); 406 virtual ~ExtensionsService();
394 friend class ChromeThread; 407 friend class ChromeThread;
395 friend class DeleteTask<ExtensionsService>; 408 friend class DeleteTask<ExtensionsService>;
396 409
397 // Clear all persistent data that may have been stored by the extension. 410 // Clear all persistent data that may have been stored by the extension.
398 void ClearExtensionData(const GURL& extension_url); 411 void ClearExtensionData(const GURL& extension_url);
399 412
400 // Look up an extension by ID, optionally including either or both of enabled 413 // Look up an extension by ID, optionally including either or both of enabled
401 // and disabled extensions. 414 // and disabled extensions.
402 Extension* GetExtensionByIdInternal(const std::string& id, 415 Extension* GetExtensionByIdInternal(const std::string& id,
403 bool include_enabled, 416 bool include_enabled,
404 bool include_disabled); 417 bool include_disabled);
405 418
406 // Like AddPendingExtension() but assumes an extension with the same 419 // Like AddPendingExtension() but assumes an extension with the same
407 // id is not already installed. 420 // id is not already installed.
408 void AddPendingExtensionInternal( 421 void AddPendingExtensionInternal(
409 const std::string& id, const GURL& update_url, 422 const std::string& id, const GURL& update_url,
410 PendingExtensionInfo::ExpectedCrxType crx_type, 423 PendingExtensionInfo::ExpectedCrxType crx_type,
411 bool is_from_sync, bool install_silently, 424 bool is_from_sync, bool install_silently,
412 bool enable_on_install, bool enable_incognito_on_install); 425 bool enable_on_install, bool enable_incognito_on_install,
426 Extension::Location install_source);
413 427
414 // Handles sending notification that |extension| was loaded. 428 // Handles sending notification that |extension| was loaded.
415 void NotifyExtensionLoaded(Extension* extension); 429 void NotifyExtensionLoaded(Extension* extension);
416 430
417 // Handles sending notification that |extension| was unloaded. 431 // Handles sending notification that |extension| was unloaded.
418 void NotifyExtensionUnloaded(Extension* extension); 432 void NotifyExtensionUnloaded(Extension* extension);
419 433
420 // Helper that updates the active extension list used for crash reporting. 434 // Helper that updates the active extension list used for crash reporting.
421 void UpdateActiveExtensionsInCrashReporter(); 435 void UpdateActiveExtensionsInCrashReporter();
422 436
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // storage within that origin. 518 // storage within that origin.
505 typedef std::map<GURL, int> UnlimitedStorageMap; 519 typedef std::map<GURL, int> UnlimitedStorageMap;
506 UnlimitedStorageMap unlimited_storage_map_; 520 UnlimitedStorageMap unlimited_storage_map_;
507 521
508 // Collection of origins whose storage is protected by "Clear browsing data." 522 // Collection of origins whose storage is protected by "Clear browsing data."
509 // A map from origin to the number of Apps currently installed and therefore 523 // A map from origin to the number of Apps currently installed and therefore
510 // intrinsically protected. 524 // intrinsically protected.
511 typedef std::map<GURL, int> ProtectedStorageMap; 525 typedef std::map<GURL, int> ProtectedStorageMap;
512 ProtectedStorageMap protected_storage_map_; 526 ProtectedStorageMap protected_storage_map_;
513 527
528 // Manages the installation of default apps and the promotion of them in the
529 // app launcher.
530 DefaultApps default_apps_;
531
514 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 532 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest,
515 UpdatePendingExtensionAlreadyInstalled); 533 UpdatePendingExtensionAlreadyInstalled);
516 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 534 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest,
517 InstallAppsWithUnlimtedStorage); 535 InstallAppsWithUnlimtedStorage);
518 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 536 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest,
519 InstallAppsAndCheckStorageProtection); 537 InstallAppsAndCheckStorageProtection);
520 DISALLOW_COPY_AND_ASSIGN(ExtensionsService); 538 DISALLOW_COPY_AND_ASSIGN(ExtensionsService);
521 }; 539 };
522 540
523 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ 541 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_updater_unittest.cc ('k') | chrome/browser/extensions/extensions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698