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