OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "chrome/browser/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "base/version.h" | 27 #include "base/version.h" |
28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
30 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 30 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
31 #include "chrome/browser/extensions/component_loader.h" | 31 #include "chrome/browser/extensions/component_loader.h" |
32 #include "chrome/browser/extensions/crx_installer.h" | 32 #include "chrome/browser/extensions/crx_installer.h" |
33 #include "chrome/browser/extensions/data_deleter.h" | 33 #include "chrome/browser/extensions/data_deleter.h" |
34 #include "chrome/browser/extensions/extension_disabled_ui.h" | 34 #include "chrome/browser/extensions/extension_disabled_ui.h" |
35 #include "chrome/browser/extensions/extension_error_reporter.h" | 35 #include "chrome/browser/extensions/extension_error_reporter.h" |
36 #include "chrome/browser/extensions/extension_error_ui.h" | 36 #include "chrome/browser/extensions/extension_error_ui.h" |
37 #include "chrome/browser/extensions/extension_garbage_collector.h" | |
38 #include "chrome/browser/extensions/extension_install_ui.h" | 37 #include "chrome/browser/extensions/extension_install_ui.h" |
39 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 38 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
40 #include "chrome/browser/extensions/extension_sync_service.h" | 39 #include "chrome/browser/extensions/extension_sync_service.h" |
41 #include "chrome/browser/extensions/extension_util.h" | 40 #include "chrome/browser/extensions/extension_util.h" |
42 #include "chrome/browser/extensions/external_install_ui.h" | 41 #include "chrome/browser/extensions/external_install_ui.h" |
43 #include "chrome/browser/extensions/external_provider_impl.h" | 42 #include "chrome/browser/extensions/external_provider_impl.h" |
44 #include "chrome/browser/extensions/install_verifier.h" | 43 #include "chrome/browser/extensions/install_verifier.h" |
45 #include "chrome/browser/extensions/installed_loader.h" | 44 #include "chrome/browser/extensions/installed_loader.h" |
46 #include "chrome/browser/extensions/pending_extension_manager.h" | 45 #include "chrome/browser/extensions/pending_extension_manager.h" |
47 #include "chrome/browser/extensions/permissions_updater.h" | 46 #include "chrome/browser/extensions/permissions_updater.h" |
48 #include "chrome/browser/extensions/unpacked_installer.h" | 47 #include "chrome/browser/extensions/unpacked_installer.h" |
49 #include "chrome/browser/extensions/updater/extension_cache.h" | 48 #include "chrome/browser/extensions/updater/extension_cache.h" |
50 #include "chrome/browser/extensions/updater/extension_updater.h" | 49 #include "chrome/browser/extensions/updater/extension_updater.h" |
51 #include "chrome/browser/profiles/profile.h" | 50 #include "chrome/browser/profiles/profile.h" |
52 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 51 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
53 #include "chrome/browser/ui/webui/favicon_source.h" | 52 #include "chrome/browser/ui/webui/favicon_source.h" |
54 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 53 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
55 #include "chrome/browser/ui/webui/theme_source.h" | 54 #include "chrome/browser/ui/webui/theme_source.h" |
56 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/crash_keys.h" | 56 #include "chrome/common/crash_keys.h" |
58 #include "chrome/common/extensions/extension_constants.h" | 57 #include "chrome/common/extensions/extension_constants.h" |
59 #include "chrome/common/extensions/extension_file_util.h" | 58 #include "chrome/common/extensions/extension_file_util.h" |
60 #include "chrome/common/extensions/features/feature_channel.h" | 59 #include "chrome/common/extensions/features/feature_channel.h" |
| 60 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
61 #include "chrome/common/extensions/manifest_url_handler.h" | 61 #include "chrome/common/extensions/manifest_url_handler.h" |
62 #include "chrome/common/pref_names.h" | 62 #include "chrome/common/pref_names.h" |
63 #include "chrome/common/url_constants.h" | 63 #include "chrome/common/url_constants.h" |
64 #include "components/startup_metric_utils/startup_metric_utils.h" | 64 #include "components/startup_metric_utils/startup_metric_utils.h" |
65 #include "content/public/browser/browser_thread.h" | 65 #include "content/public/browser/browser_thread.h" |
66 #include "content/public/browser/devtools_agent_host.h" | 66 #include "content/public/browser/devtools_agent_host.h" |
67 #include "content/public/browser/notification_service.h" | 67 #include "content/public/browser/notification_service.h" |
68 #include "content/public/browser/notification_types.h" | 68 #include "content/public/browser/notification_types.h" |
69 #include "content/public/browser/render_process_host.h" | 69 #include "content/public/browser/render_process_host.h" |
70 #include "content/public/browser/storage_partition.h" | 70 #include "content/public/browser/storage_partition.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 EXTERNAL_EXTENSION_UNINSTALLED, | 140 EXTERNAL_EXTENSION_UNINSTALLED, |
141 EXTERNAL_EXTENSION_BUCKET_BOUNDARY, | 141 EXTERNAL_EXTENSION_BUCKET_BOUNDARY, |
142 }; | 142 }; |
143 | 143 |
144 // Prompt the user this many times before considering an extension acknowledged. | 144 // Prompt the user this many times before considering an extension acknowledged. |
145 static const int kMaxExtensionAcknowledgePromptCount = 3; | 145 static const int kMaxExtensionAcknowledgePromptCount = 3; |
146 | 146 |
147 // Wait this many seconds after an extensions becomes idle before updating it. | 147 // Wait this many seconds after an extensions becomes idle before updating it. |
148 static const int kUpdateIdleDelay = 5; | 148 static const int kUpdateIdleDelay = 5; |
149 | 149 |
| 150 // Wait this many seconds before trying to garbage collect extensions again. |
| 151 static const int kGarbageCollectRetryDelay = 30; |
| 152 |
| 153 // Wait this many seconds after startup to see if there are any extensions |
| 154 // which can be garbage collected. |
| 155 static const int kGarbageCollectStartupDelay = 30; |
| 156 |
150 static bool IsSharedModule(const Extension* extension) { | 157 static bool IsSharedModule(const Extension* extension) { |
151 return SharedModuleInfo::IsSharedModule(extension); | 158 return SharedModuleInfo::IsSharedModule(extension); |
152 } | 159 } |
153 | 160 |
154 static bool IsCWSSharedModule(const Extension* extension) { | 161 static bool IsCWSSharedModule(const Extension* extension) { |
155 return extension->from_webstore() && IsSharedModule(extension); | 162 return extension->from_webstore() && IsSharedModule(extension); |
156 } | 163 } |
157 | 164 |
158 class SharedModuleProvider : public extensions::ManagementPolicy::Provider { | 165 class SharedModuleProvider : public extensions::ManagementPolicy::Provider { |
159 public: | 166 public: |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 registry_(extensions::ExtensionRegistry::Get(profile)), | 333 registry_(extensions::ExtensionRegistry::Get(profile)), |
327 pending_extension_manager_(*this, profile), | 334 pending_extension_manager_(*this, profile), |
328 install_directory_(install_directory), | 335 install_directory_(install_directory), |
329 extensions_enabled_(extensions_enabled), | 336 extensions_enabled_(extensions_enabled), |
330 show_extensions_prompts_(true), | 337 show_extensions_prompts_(true), |
331 install_updates_when_idle_(true), | 338 install_updates_when_idle_(true), |
332 ready_(ready), | 339 ready_(ready), |
333 update_once_all_providers_are_ready_(false), | 340 update_once_all_providers_are_ready_(false), |
334 browser_terminating_(false), | 341 browser_terminating_(false), |
335 installs_delayed_for_gc_(false), | 342 installs_delayed_for_gc_(false), |
336 is_first_run_(false), | 343 is_first_run_(false) { |
337 garbage_collector_(new extensions::ExtensionGarbageCollector(this)) { | 344 #if defined(OS_CHROMEOS) |
| 345 disable_garbage_collection_ = false; |
| 346 #endif |
338 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 347 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
339 | 348 |
340 // Figure out if extension installation should be enabled. | 349 // Figure out if extension installation should be enabled. |
341 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( | 350 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( |
342 *command_line, profile)) | 351 *command_line, profile)) |
343 extensions_enabled_ = false; | 352 extensions_enabled_ = false; |
344 | 353 |
345 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 354 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
346 content::NotificationService::AllBrowserContextsAndSources()); | 355 content::NotificationService::AllBrowserContextsAndSources()); |
347 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 356 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 extension_prefs_->GetAllDelayedInstallInfo()); | 522 extension_prefs_->GetAllDelayedInstallInfo()); |
514 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", | 523 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
515 delayed_info2->size() - delayed_info->size()); | 524 delayed_info2->size() - delayed_info->size()); |
516 | 525 |
517 SetReadyAndNotifyListeners(); | 526 SetReadyAndNotifyListeners(); |
518 | 527 |
519 // TODO(erikkay) this should probably be deferred to a future point | 528 // TODO(erikkay) this should probably be deferred to a future point |
520 // rather than running immediately at startup. | 529 // rather than running immediately at startup. |
521 CheckForExternalUpdates(); | 530 CheckForExternalUpdates(); |
522 | 531 |
| 532 base::MessageLoop::current()->PostDelayedTask( |
| 533 FROM_HERE, |
| 534 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 535 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); |
| 536 |
| 537 if (extension_prefs_->NeedsStorageGarbageCollection()) { |
| 538 GarbageCollectIsolatedStorage(); |
| 539 extension_prefs_->SetNeedsStorageGarbageCollection(false); |
| 540 } |
523 system_->management_policy()->RegisterProvider( | 541 system_->management_policy()->RegisterProvider( |
524 shared_module_policy_provider_.get()); | 542 shared_module_policy_provider_.get()); |
525 | 543 |
526 LoadGreylistFromPrefs(); | 544 LoadGreylistFromPrefs(); |
527 } | 545 } |
528 | 546 |
529 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", | 547 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", |
530 base::Time::Now() - begin_time); | 548 base::Time::Now() - begin_time); |
531 } | 549 } |
532 | 550 |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 void ExtensionService::ReloadExtensionsForTest() { | 1556 void ExtensionService::ReloadExtensionsForTest() { |
1539 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit | 1557 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit |
1540 // warning about calling test code in production. | 1558 // warning about calling test code in production. |
1541 UnloadAllExtensionsInternal(); | 1559 UnloadAllExtensionsInternal(); |
1542 component_loader_->LoadAll(); | 1560 component_loader_->LoadAll(); |
1543 extensions::InstalledLoader(this).LoadAllExtensions(); | 1561 extensions::InstalledLoader(this).LoadAllExtensions(); |
1544 // Don't call SetReadyAndNotifyListeners() since tests call this multiple | 1562 // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
1545 // times. | 1563 // times. |
1546 } | 1564 } |
1547 | 1565 |
| 1566 void ExtensionService::GarbageCollectExtensions() { |
| 1567 #if defined(OS_CHROMEOS) |
| 1568 if (disable_garbage_collection_) |
| 1569 return; |
| 1570 #endif |
| 1571 |
| 1572 if (extension_prefs_->pref_service()->ReadOnly()) |
| 1573 return; |
| 1574 |
| 1575 bool clean_temp_dir = true; |
| 1576 |
| 1577 if (pending_extension_manager()->HasPendingExtensions()) { |
| 1578 // Don't garbage collect temp dir while there are pending installations, |
| 1579 // which may be using the temporary installation directory. Try to garbage |
| 1580 // collect again later. |
| 1581 clean_temp_dir = false; |
| 1582 base::MessageLoop::current()->PostDelayedTask( |
| 1583 FROM_HERE, |
| 1584 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 1585 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay)); |
| 1586 } |
| 1587 |
| 1588 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( |
| 1589 extension_prefs_->GetInstalledExtensionsInfo()); |
| 1590 |
| 1591 std::multimap<std::string, base::FilePath> extension_paths; |
| 1592 for (size_t i = 0; i < info->size(); ++i) |
| 1593 extension_paths.insert(std::make_pair(info->at(i)->extension_id, |
| 1594 info->at(i)->extension_path)); |
| 1595 |
| 1596 info = extension_prefs_->GetAllDelayedInstallInfo(); |
| 1597 for (size_t i = 0; i < info->size(); ++i) |
| 1598 extension_paths.insert(std::make_pair(info->at(i)->extension_id, |
| 1599 info->at(i)->extension_path)); |
| 1600 |
| 1601 if (!GetFileTaskRunner()->PostTask( |
| 1602 FROM_HERE, |
| 1603 base::Bind( |
| 1604 &extension_file_util::GarbageCollectExtensions, |
| 1605 install_directory_, |
| 1606 extension_paths, |
| 1607 clean_temp_dir))) { |
| 1608 NOTREACHED(); |
| 1609 } |
| 1610 } |
| 1611 |
1548 void ExtensionService::SetReadyAndNotifyListeners() { | 1612 void ExtensionService::SetReadyAndNotifyListeners() { |
1549 ready_->Signal(); | 1613 ready_->Signal(); |
1550 content::NotificationService::current()->Notify( | 1614 content::NotificationService::current()->Notify( |
1551 chrome::NOTIFICATION_EXTENSIONS_READY, | 1615 chrome::NOTIFICATION_EXTENSIONS_READY, |
1552 content::Source<Profile>(profile_), | 1616 content::Source<Profile>(profile_), |
1553 content::NotificationService::NoDetails()); | 1617 content::NotificationService::NoDetails()); |
1554 } | 1618 } |
1555 | 1619 |
1556 void ExtensionService::OnLoadedInstalledExtensions() { | 1620 void ExtensionService::OnLoadedInstalledExtensions() { |
1557 if (updater_) | 1621 if (updater_) |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2023 // Transfer ownership of |extension|. | 2087 // Transfer ownership of |extension|. |
2024 delayed_installs_.Insert(extension); | 2088 delayed_installs_.Insert(extension); |
2025 | 2089 |
2026 // Notify observers that app update is available. | 2090 // Notify observers that app update is available. |
2027 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, | 2091 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
2028 OnAppUpdateAvailable(extension)); | 2092 OnAppUpdateAvailable(extension)); |
2029 return; | 2093 return; |
2030 } | 2094 } |
2031 | 2095 |
2032 ImportStatus status = SatisfyImports(extension); | 2096 ImportStatus status = SatisfyImports(extension); |
2033 if (installs_delayed_for_gc_) { | 2097 if (installs_delayed_for_gc()) { |
2034 extension_prefs_->SetDelayedInstallInfo( | 2098 extension_prefs_->SetDelayedInstallInfo( |
2035 extension, | 2099 extension, |
2036 initial_state, | 2100 initial_state, |
2037 blacklisted_for_malware, | 2101 blacklisted_for_malware, |
2038 extensions::ExtensionPrefs::DELAY_REASON_GC, | 2102 extensions::ExtensionPrefs::DELAY_REASON_GC, |
2039 page_ordinal, | 2103 page_ordinal, |
2040 install_parameter); | 2104 install_parameter); |
2041 delayed_installs_.Insert(extension); | 2105 delayed_installs_.Insert(extension); |
2042 } else if (status != IMPORT_STATUS_OK) { | 2106 } else if (status != IMPORT_STATUS_OK) { |
2043 if (status == IMPORT_STATUS_UNSATISFIED) { | 2107 if (status == IMPORT_STATUS_UNSATISFIED) { |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2478 // Delay installation if the extension listens for the onUpdateAvailable | 2542 // Delay installation if the extension listens for the onUpdateAvailable |
2479 // event. | 2543 // event. |
2480 return system_->event_router()->ExtensionHasEventListener( | 2544 return system_->event_router()->ExtensionHasEventListener( |
2481 extension_id, kOnUpdateAvailableEvent); | 2545 extension_id, kOnUpdateAvailableEvent); |
2482 } else { | 2546 } else { |
2483 // Delay installation if the extension is not idle. | 2547 // Delay installation if the extension is not idle. |
2484 return !extensions::util::IsExtensionIdle(extension_id, profile_); | 2548 return !extensions::util::IsExtensionIdle(extension_id, profile_); |
2485 } | 2549 } |
2486 } | 2550 } |
2487 | 2551 |
2488 void ExtensionService::OnGarbageCollectIsolatedStorageStart() { | 2552 void ExtensionService::GarbageCollectIsolatedStorage() { |
2489 DCHECK(!installs_delayed_for_gc_); | 2553 scoped_ptr<base::hash_set<base::FilePath> > active_paths( |
2490 installs_delayed_for_gc_ = true; | 2554 new base::hash_set<base::FilePath>()); |
| 2555 const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 2556 for (ExtensionSet::const_iterator it = extensions.begin(); |
| 2557 it != extensions.end(); ++it) { |
| 2558 if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) { |
| 2559 active_paths->insert(BrowserContext::GetStoragePartitionForSite( |
| 2560 profile_, |
| 2561 extensions::util::GetSiteForExtensionId( |
| 2562 (*it)->id(), profile()))->GetPath()); |
| 2563 } |
| 2564 } |
| 2565 |
| 2566 // The data of ephemeral apps can outlive their cache lifetime. Ensure |
| 2567 // they are not garbage collected. |
| 2568 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> evicted_apps_info( |
| 2569 extension_prefs_->GetEvictedEphemeralAppsInfo()); |
| 2570 for (size_t i = 0; i < evicted_apps_info->size(); ++i) { |
| 2571 extensions::ExtensionInfo* info = evicted_apps_info->at(i).get(); |
| 2572 if (extensions::util::HasIsolatedStorage(*info)) { |
| 2573 active_paths->insert(BrowserContext::GetStoragePartitionForSite( |
| 2574 profile_, |
| 2575 extensions::util::GetSiteForExtensionId( |
| 2576 info->extension_id, profile()))->GetPath()); |
| 2577 } |
| 2578 } |
| 2579 |
| 2580 DCHECK(!installs_delayed_for_gc()); |
| 2581 set_installs_delayed_for_gc(true); |
| 2582 BrowserContext::GarbageCollectStoragePartitions( |
| 2583 profile_, active_paths.Pass(), |
| 2584 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, |
| 2585 AsWeakPtr())); |
2491 } | 2586 } |
2492 | 2587 |
2493 void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { | 2588 void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { |
2494 DCHECK(installs_delayed_for_gc_); | 2589 set_installs_delayed_for_gc(false); |
2495 installs_delayed_for_gc_ = false; | |
2496 MaybeFinishDelayedInstallations(); | 2590 MaybeFinishDelayedInstallations(); |
2497 } | 2591 } |
2498 | 2592 |
2499 void ExtensionService::MaybeFinishDelayedInstallations() { | 2593 void ExtensionService::MaybeFinishDelayedInstallations() { |
2500 std::vector<std::string> to_be_installed; | 2594 std::vector<std::string> to_be_installed; |
2501 for (ExtensionSet::const_iterator it = delayed_installs_.begin(); | 2595 for (ExtensionSet::const_iterator it = delayed_installs_.begin(); |
2502 it != delayed_installs_.end(); | 2596 it != delayed_installs_.end(); |
2503 ++it) { | 2597 ++it) { |
2504 to_be_installed.push_back((*it)->id()); | 2598 to_be_installed.push_back((*it)->id()); |
2505 } | 2599 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 void ExtensionService::UnloadAllExtensionsInternal() { | 2757 void ExtensionService::UnloadAllExtensionsInternal() { |
2664 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2758 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2665 | 2759 |
2666 registry_->ClearAll(); | 2760 registry_->ClearAll(); |
2667 system_->runtime_data()->ClearAll(); | 2761 system_->runtime_data()->ClearAll(); |
2668 | 2762 |
2669 // TODO(erikkay) should there be a notification for this? We can't use | 2763 // TODO(erikkay) should there be a notification for this? We can't use |
2670 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2764 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2671 // or uninstalled. | 2765 // or uninstalled. |
2672 } | 2766 } |
OLD | NEW |