| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 virtual bool MustRemainEnabled(const Extension* extension, | 182 virtual bool MustRemainEnabled(const Extension* extension, |
| 183 base::string16* error) const OVERRIDE { | 183 base::string16* error) const OVERRIDE { |
| 184 return IsCWSSharedModule(extension); | 184 return IsCWSSharedModule(extension); |
| 185 } | 185 } |
| 186 | 186 |
| 187 private: | 187 private: |
| 188 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); | 188 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 enum VerifyAllSuccess { |
| 192 VERIFY_ALL_BOOTSTRAP_SUCCESS = 0, |
| 193 VERIFY_ALL_BOOTSTRAP_FAILURE, |
| 194 VERIFY_ALL_NON_BOOTSTRAP_SUCCESS, |
| 195 VERIFY_ALL_NON_BOOTSTRAP_FAILURE, |
| 196 |
| 197 // Used in histograms. Do not remove/reorder any entries above, and the below |
| 198 // MAX entry should always come last. |
| 199 |
| 200 VERIFY_ALL_SUCCESS_MAX |
| 201 }; |
| 202 |
| 203 void LogVerifyAllSuccessHistogram(bool bootstrap, bool success) { |
| 204 VerifyAllSuccess result; |
| 205 if (bootstrap && success) |
| 206 result = VERIFY_ALL_BOOTSTRAP_SUCCESS; |
| 207 else if (bootstrap && !success) |
| 208 result = VERIFY_ALL_BOOTSTRAP_FAILURE; |
| 209 else if (!bootstrap && success) |
| 210 result = VERIFY_ALL_NON_BOOTSTRAP_SUCCESS; |
| 211 else |
| 212 result = VERIFY_ALL_NON_BOOTSTRAP_FAILURE; |
| 213 |
| 214 UMA_HISTOGRAM_ENUMERATION("ExtensionService.VerifyAllSuccess", |
| 215 result, VERIFY_ALL_SUCCESS_MAX); |
| 216 } |
| 217 |
| 218 void LogAddVerifiedSuccess(bool success) { |
| 219 UMA_HISTOGRAM_BOOLEAN("ExtensionService.AddVerified", success); |
| 220 } |
| 191 | 221 |
| 192 } // namespace | 222 } // namespace |
| 193 | 223 |
| 194 // ExtensionService. | 224 // ExtensionService. |
| 195 | 225 |
| 196 void ExtensionService::CheckExternalUninstall(const std::string& id) { | 226 void ExtensionService::CheckExternalUninstall(const std::string& id) { |
| 197 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 227 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 198 | 228 |
| 199 // Check if the providers know about this extension. | 229 // Check if the providers know about this extension. |
| 200 extensions::ProviderCollection::const_iterator i; | 230 extensions::ProviderCollection::const_iterator i; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 574 |
| 545 SetReadyAndNotifyListeners(); | 575 SetReadyAndNotifyListeners(); |
| 546 | 576 |
| 547 // TODO(erikkay) this should probably be deferred to a future point | 577 // TODO(erikkay) this should probably be deferred to a future point |
| 548 // rather than running immediately at startup. | 578 // rather than running immediately at startup. |
| 549 CheckForExternalUpdates(); | 579 CheckForExternalUpdates(); |
| 550 | 580 |
| 551 InstallVerifier* verifier = | 581 InstallVerifier* verifier = |
| 552 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 582 extensions::ExtensionSystem::Get(profile_)->install_verifier(); |
| 553 if (verifier->NeedsBootstrap()) | 583 if (verifier->NeedsBootstrap()) |
| 554 VerifyAllExtensions(); | 584 VerifyAllExtensions(true); // bootstrap=true. |
| 555 base::MessageLoop::current()->PostDelayedTask( | 585 base::MessageLoop::current()->PostDelayedTask( |
| 556 FROM_HERE, | 586 FROM_HERE, |
| 557 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), | 587 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 558 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); | 588 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); |
| 559 | 589 |
| 560 if (extension_prefs_->NeedsStorageGarbageCollection()) { | 590 if (extension_prefs_->NeedsStorageGarbageCollection()) { |
| 561 GarbageCollectIsolatedStorage(); | 591 GarbageCollectIsolatedStorage(); |
| 562 extension_prefs_->SetNeedsStorageGarbageCollection(false); | 592 extension_prefs_->SetNeedsStorageGarbageCollection(false); |
| 563 } | 593 } |
| 564 system_->management_policy()->RegisterProvider( | 594 system_->management_policy()->RegisterProvider( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 578 it != all_extensions->end(); ++it) { | 608 it != all_extensions->end(); ++it) { |
| 579 extensions::BlacklistState state = | 609 extensions::BlacklistState state = |
| 580 extension_prefs_->GetExtensionBlacklistState((*it)->id()); | 610 extension_prefs_->GetExtensionBlacklistState((*it)->id()); |
| 581 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || | 611 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || |
| 582 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || | 612 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || |
| 583 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) | 613 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) |
| 584 greylist_.Insert(*it); | 614 greylist_.Insert(*it); |
| 585 } | 615 } |
| 586 } | 616 } |
| 587 | 617 |
| 588 void ExtensionService::VerifyAllExtensions() { | 618 void ExtensionService::VerifyAllExtensions(bool bootstrap) { |
| 589 ExtensionIdSet to_add; | 619 ExtensionIdSet to_add; |
| 590 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); | 620 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); |
| 591 | 621 |
| 592 for (ExtensionSet::const_iterator i = all_extensions->begin(); | 622 for (ExtensionSet::const_iterator i = all_extensions->begin(); |
| 593 i != all_extensions->end(); ++i) { | 623 i != all_extensions->end(); ++i) { |
| 594 const Extension& extension = **i; | 624 const Extension& extension = **i; |
| 595 | 625 |
| 596 if (InstallVerifier::NeedsVerification(extension)) | 626 if (InstallVerifier::NeedsVerification(extension)) |
| 597 to_add.insert(extension.id()); | 627 to_add.insert(extension.id()); |
| 598 } | 628 } |
| 599 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany( | 629 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany( |
| 600 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions, | 630 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions, |
| 601 AsWeakPtr())); | 631 AsWeakPtr(), bootstrap)); |
| 602 } | 632 } |
| 603 | 633 |
| 604 void ExtensionService::FinishVerifyAllExtensions(bool success) { | 634 void ExtensionService::FinishVerifyAllExtensions(bool bootstrap, bool success) { |
| 635 LogVerifyAllSuccessHistogram(bootstrap, success); |
| 605 if (success) { | 636 if (success) { |
| 606 // Check to see if any currently unverified extensions became verified. | 637 // Check to see if any currently unverified extensions became verified. |
| 607 InstallVerifier* verifier = | 638 InstallVerifier* verifier = |
| 608 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 639 extensions::ExtensionSystem::Get(profile_)->install_verifier(); |
| 609 const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); | 640 const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); |
| 610 for (ExtensionSet::const_iterator i = disabled_extensions.begin(); | 641 for (ExtensionSet::const_iterator i = disabled_extensions.begin(); |
| 611 i != disabled_extensions.end(); ++i) { | 642 i != disabled_extensions.end(); ++i) { |
| 612 const Extension& extension = **i; | 643 const Extension& extension = **i; |
| 613 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); | 644 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); |
| 614 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED && | 645 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED && |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2210 const bool blacklisted_for_malware = | 2241 const bool blacklisted_for_malware = |
| 2211 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2242 blacklist_state == extensions::BLACKLISTED_MALWARE; |
| 2212 extension_prefs_->OnExtensionInstalled(extension, | 2243 extension_prefs_->OnExtensionInstalled(extension, |
| 2213 initial_state, | 2244 initial_state, |
| 2214 blacklisted_for_malware, | 2245 blacklisted_for_malware, |
| 2215 page_ordinal); | 2246 page_ordinal); |
| 2216 delayed_installs_.Remove(extension->id()); | 2247 delayed_installs_.Remove(extension->id()); |
| 2217 if (InstallVerifier::NeedsVerification(*extension)) { | 2248 if (InstallVerifier::NeedsVerification(*extension)) { |
| 2218 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( | 2249 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( |
| 2219 extension->id(), InstallVerifier::AddResultCallback()); | 2250 extension->id(), base::Bind(LogAddVerifiedSuccess)); |
| 2220 } | 2251 } |
| 2221 FinishInstallation(extension); | 2252 FinishInstallation(extension); |
| 2222 } | 2253 } |
| 2223 | 2254 |
| 2224 void ExtensionService::MaybeFinishDelayedInstallation( | 2255 void ExtensionService::MaybeFinishDelayedInstallation( |
| 2225 const std::string& extension_id) { | 2256 const std::string& extension_id) { |
| 2226 // Check if the extension already got installed. | 2257 // Check if the extension already got installed. |
| 2227 if (!delayed_installs_.Contains(extension_id)) | 2258 if (!delayed_installs_.Contains(extension_id)) |
| 2228 return; | 2259 return; |
| 2229 extensions::ExtensionPrefs::DelayReason reason = | 2260 extensions::ExtensionPrefs::DelayReason reason = |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2844 void ExtensionService::UnloadAllExtensionsInternal() { | 2875 void ExtensionService::UnloadAllExtensionsInternal() { |
| 2845 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2876 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2846 | 2877 |
| 2847 registry_->ClearAll(); | 2878 registry_->ClearAll(); |
| 2848 system_->runtime_data()->ClearAll(); | 2879 system_->runtime_data()->ClearAll(); |
| 2849 | 2880 |
| 2850 // TODO(erikkay) should there be a notification for this? We can't use | 2881 // TODO(erikkay) should there be a notification for this? We can't use |
| 2851 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2882 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2852 // or uninstalled. | 2883 // or uninstalled. |
| 2853 } | 2884 } |
| OLD | NEW |