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

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

Issue 204983020: Remove ExtensionService Garbage-Collecting methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove lazy global empty delta Created 6 years, 8 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) 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
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"
37 #include "chrome/browser/extensions/extension_install_ui.h" 38 #include "chrome/browser/extensions/extension_install_ui.h"
38 #include "chrome/browser/extensions/extension_special_storage_policy.h" 39 #include "chrome/browser/extensions/extension_special_storage_policy.h"
39 #include "chrome/browser/extensions/extension_sync_service.h" 40 #include "chrome/browser/extensions/extension_sync_service.h"
40 #include "chrome/browser/extensions/extension_util.h" 41 #include "chrome/browser/extensions/extension_util.h"
41 #include "chrome/browser/extensions/external_install_ui.h" 42 #include "chrome/browser/extensions/external_install_ui.h"
42 #include "chrome/browser/extensions/external_provider_impl.h" 43 #include "chrome/browser/extensions/external_provider_impl.h"
43 #include "chrome/browser/extensions/install_verifier.h" 44 #include "chrome/browser/extensions/install_verifier.h"
44 #include "chrome/browser/extensions/installed_loader.h" 45 #include "chrome/browser/extensions/installed_loader.h"
45 #include "chrome/browser/extensions/pending_extension_manager.h" 46 #include "chrome/browser/extensions/pending_extension_manager.h"
46 #include "chrome/browser/extensions/permissions_updater.h" 47 #include "chrome/browser/extensions/permissions_updater.h"
47 #include "chrome/browser/extensions/unpacked_installer.h" 48 #include "chrome/browser/extensions/unpacked_installer.h"
48 #include "chrome/browser/extensions/updater/extension_cache.h" 49 #include "chrome/browser/extensions/updater/extension_cache.h"
49 #include "chrome/browser/extensions/updater/extension_updater.h" 50 #include "chrome/browser/extensions/updater/extension_updater.h"
50 #include "chrome/browser/profiles/profile.h" 51 #include "chrome/browser/profiles/profile.h"
51 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 52 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
52 #include "chrome/browser/ui/webui/favicon_source.h" 53 #include "chrome/browser/ui/webui/favicon_source.h"
53 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 54 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
54 #include "chrome/browser/ui/webui/theme_source.h" 55 #include "chrome/browser/ui/webui/theme_source.h"
55 #include "chrome/common/chrome_switches.h" 56 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/crash_keys.h" 57 #include "chrome/common/crash_keys.h"
57 #include "chrome/common/extensions/extension_constants.h" 58 #include "chrome/common/extensions/extension_constants.h"
58 #include "chrome/common/extensions/extension_file_util.h" 59 #include "chrome/common/extensions/extension_file_util.h"
59 #include "chrome/common/extensions/features/feature_channel.h" 60 #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
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
157 static bool IsSharedModule(const Extension* extension) { 150 static bool IsSharedModule(const Extension* extension) {
158 return SharedModuleInfo::IsSharedModule(extension); 151 return SharedModuleInfo::IsSharedModule(extension);
159 } 152 }
160 153
161 static bool IsCWSSharedModule(const Extension* extension) { 154 static bool IsCWSSharedModule(const Extension* extension) {
162 return extension->from_webstore() && IsSharedModule(extension); 155 return extension->from_webstore() && IsSharedModule(extension);
163 } 156 }
164 157
165 class SharedModuleProvider : public extensions::ManagementPolicy::Provider { 158 class SharedModuleProvider : public extensions::ManagementPolicy::Provider {
166 public: 159 public:
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 registry_(extensions::ExtensionRegistry::Get(profile)), 326 registry_(extensions::ExtensionRegistry::Get(profile)),
334 pending_extension_manager_(*this, profile), 327 pending_extension_manager_(*this, profile),
335 install_directory_(install_directory), 328 install_directory_(install_directory),
336 extensions_enabled_(extensions_enabled), 329 extensions_enabled_(extensions_enabled),
337 show_extensions_prompts_(true), 330 show_extensions_prompts_(true),
338 install_updates_when_idle_(true), 331 install_updates_when_idle_(true),
339 ready_(ready), 332 ready_(ready),
340 update_once_all_providers_are_ready_(false), 333 update_once_all_providers_are_ready_(false),
341 browser_terminating_(false), 334 browser_terminating_(false),
342 installs_delayed_for_gc_(false), 335 installs_delayed_for_gc_(false),
343 is_first_run_(false) { 336 is_first_run_(false),
344 #if defined(OS_CHROMEOS) 337 garbage_collector_(new extensions::ExtensionGarbageCollector(this)) {
345 disable_garbage_collection_ = false;
346 #endif
347 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 338 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
348 339
349 // Figure out if extension installation should be enabled. 340 // Figure out if extension installation should be enabled.
350 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( 341 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
351 *command_line, profile)) 342 *command_line, profile))
352 extensions_enabled_ = false; 343 extensions_enabled_ = false;
353 344
354 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 345 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
355 content::NotificationService::AllBrowserContextsAndSources()); 346 content::NotificationService::AllBrowserContextsAndSources());
356 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 347 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 extension_prefs_->GetAllDelayedInstallInfo()); 513 extension_prefs_->GetAllDelayedInstallInfo());
523 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", 514 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
524 delayed_info2->size() - delayed_info->size()); 515 delayed_info2->size() - delayed_info->size());
525 516
526 SetReadyAndNotifyListeners(); 517 SetReadyAndNotifyListeners();
527 518
528 // TODO(erikkay) this should probably be deferred to a future point 519 // TODO(erikkay) this should probably be deferred to a future point
529 // rather than running immediately at startup. 520 // rather than running immediately at startup.
530 CheckForExternalUpdates(); 521 CheckForExternalUpdates();
531 522
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 }
541 system_->management_policy()->RegisterProvider( 523 system_->management_policy()->RegisterProvider(
542 shared_module_policy_provider_.get()); 524 shared_module_policy_provider_.get());
543 525
544 LoadGreylistFromPrefs(); 526 LoadGreylistFromPrefs();
545 } 527 }
546 528
547 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", 529 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
548 base::Time::Now() - begin_time); 530 base::Time::Now() - begin_time);
549 } 531 }
550 532
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 void ExtensionService::ReloadExtensionsForTest() { 1538 void ExtensionService::ReloadExtensionsForTest() {
1557 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit 1539 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1558 // warning about calling test code in production. 1540 // warning about calling test code in production.
1559 UnloadAllExtensionsInternal(); 1541 UnloadAllExtensionsInternal();
1560 component_loader_->LoadAll(); 1542 component_loader_->LoadAll();
1561 extensions::InstalledLoader(this).LoadAllExtensions(); 1543 extensions::InstalledLoader(this).LoadAllExtensions();
1562 // Don't call SetReadyAndNotifyListeners() since tests call this multiple 1544 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1563 // times. 1545 // times.
1564 } 1546 }
1565 1547
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
1612 void ExtensionService::SetReadyAndNotifyListeners() { 1548 void ExtensionService::SetReadyAndNotifyListeners() {
1613 ready_->Signal(); 1549 ready_->Signal();
1614 content::NotificationService::current()->Notify( 1550 content::NotificationService::current()->Notify(
1615 chrome::NOTIFICATION_EXTENSIONS_READY, 1551 chrome::NOTIFICATION_EXTENSIONS_READY,
1616 content::Source<Profile>(profile_), 1552 content::Source<Profile>(profile_),
1617 content::NotificationService::NoDetails()); 1553 content::NotificationService::NoDetails());
1618 } 1554 }
1619 1555
1620 void ExtensionService::OnLoadedInstalledExtensions() { 1556 void ExtensionService::OnLoadedInstalledExtensions() {
1621 if (updater_) 1557 if (updater_)
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 // Transfer ownership of |extension|. 2023 // Transfer ownership of |extension|.
2088 delayed_installs_.Insert(extension); 2024 delayed_installs_.Insert(extension);
2089 2025
2090 // Notify observers that app update is available. 2026 // Notify observers that app update is available.
2091 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, 2027 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2092 OnAppUpdateAvailable(extension)); 2028 OnAppUpdateAvailable(extension));
2093 return; 2029 return;
2094 } 2030 }
2095 2031
2096 ImportStatus status = SatisfyImports(extension); 2032 ImportStatus status = SatisfyImports(extension);
2097 if (installs_delayed_for_gc()) { 2033 if (installs_delayed_for_gc_) {
2098 extension_prefs_->SetDelayedInstallInfo( 2034 extension_prefs_->SetDelayedInstallInfo(
2099 extension, 2035 extension,
2100 initial_state, 2036 initial_state,
2101 blacklisted_for_malware, 2037 blacklisted_for_malware,
2102 extensions::ExtensionPrefs::DELAY_REASON_GC, 2038 extensions::ExtensionPrefs::DELAY_REASON_GC,
2103 page_ordinal, 2039 page_ordinal,
2104 install_parameter); 2040 install_parameter);
2105 delayed_installs_.Insert(extension); 2041 delayed_installs_.Insert(extension);
2106 } else if (status != IMPORT_STATUS_OK) { 2042 } else if (status != IMPORT_STATUS_OK) {
2107 if (status == IMPORT_STATUS_UNSATISFIED) { 2043 if (status == IMPORT_STATUS_UNSATISFIED) {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2542 // Delay installation if the extension listens for the onUpdateAvailable 2478 // Delay installation if the extension listens for the onUpdateAvailable
2543 // event. 2479 // event.
2544 return system_->event_router()->ExtensionHasEventListener( 2480 return system_->event_router()->ExtensionHasEventListener(
2545 extension_id, kOnUpdateAvailableEvent); 2481 extension_id, kOnUpdateAvailableEvent);
2546 } else { 2482 } else {
2547 // Delay installation if the extension is not idle. 2483 // Delay installation if the extension is not idle.
2548 return !extensions::util::IsExtensionIdle(extension_id, profile_); 2484 return !extensions::util::IsExtensionIdle(extension_id, profile_);
2549 } 2485 }
2550 } 2486 }
2551 2487
2552 void ExtensionService::GarbageCollectIsolatedStorage() { 2488 void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2553 scoped_ptr<base::hash_set<base::FilePath> > active_paths( 2489 DCHECK(!installs_delayed_for_gc_);
2554 new base::hash_set<base::FilePath>()); 2490 installs_delayed_for_gc_ = true;
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()));
2586 } 2491 }
2587 2492
2588 void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { 2493 void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
2589 set_installs_delayed_for_gc(false); 2494 DCHECK(installs_delayed_for_gc_);
2495 installs_delayed_for_gc_ = false;
2590 MaybeFinishDelayedInstallations(); 2496 MaybeFinishDelayedInstallations();
2591 } 2497 }
2592 2498
2593 void ExtensionService::MaybeFinishDelayedInstallations() { 2499 void ExtensionService::MaybeFinishDelayedInstallations() {
2594 std::vector<std::string> to_be_installed; 2500 std::vector<std::string> to_be_installed;
2595 for (ExtensionSet::const_iterator it = delayed_installs_.begin(); 2501 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2596 it != delayed_installs_.end(); 2502 it != delayed_installs_.end();
2597 ++it) { 2503 ++it) {
2598 to_be_installed.push_back((*it)->id()); 2504 to_be_installed.push_back((*it)->id());
2599 } 2505 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2757 void ExtensionService::UnloadAllExtensionsInternal() { 2663 void ExtensionService::UnloadAllExtensionsInternal() {
2758 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2664 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2759 2665
2760 registry_->ClearAll(); 2666 registry_->ClearAll();
2761 system_->runtime_data()->ClearAll(); 2667 system_->runtime_data()->ClearAll();
2762 2668
2763 // TODO(erikkay) should there be a notification for this? We can't use 2669 // TODO(erikkay) should there be a notification for this? We can't use
2764 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2670 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2765 // or uninstalled. 2671 // or uninstalled.
2766 } 2672 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698