 Chromium Code Reviews
 Chromium Code Reviews Issue 149353002:
  Change default mode of extension install verification  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 149353002:
  Change default mode of extension install verification  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 | 538 | 
| 539 SetReadyAndNotifyListeners(); | 539 SetReadyAndNotifyListeners(); | 
| 540 | 540 | 
| 541 // TODO(erikkay) this should probably be deferred to a future point | 541 // TODO(erikkay) this should probably be deferred to a future point | 
| 542 // rather than running immediately at startup. | 542 // rather than running immediately at startup. | 
| 543 CheckForExternalUpdates(); | 543 CheckForExternalUpdates(); | 
| 544 | 544 | 
| 545 InstallVerifier* verifier = | 545 InstallVerifier* verifier = | 
| 546 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 546 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 
| 547 if (verifier->NeedsBootstrap()) | 547 if (verifier->NeedsBootstrap()) | 
| 548 VerifyAllExtensions(); | 548 VerifyAllExtensions(true /* bootstrap */); | 
| 
Finnur
2014/01/29 10:35:42
nit: I thought we generally shied away from multi-
 
asargent_no_longer_on_chrome
2014/01/29 19:52:51
Done.
 | |
| 549 base::MessageLoop::current()->PostDelayedTask( | 549 base::MessageLoop::current()->PostDelayedTask( | 
| 550 FROM_HERE, | 550 FROM_HERE, | 
| 551 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), | 551 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), | 
| 552 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); | 552 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); | 
| 553 | 553 | 
| 554 if (extension_prefs_->NeedsStorageGarbageCollection()) { | 554 if (extension_prefs_->NeedsStorageGarbageCollection()) { | 
| 555 GarbageCollectIsolatedStorage(); | 555 GarbageCollectIsolatedStorage(); | 
| 556 extension_prefs_->SetNeedsStorageGarbageCollection(false); | 556 extension_prefs_->SetNeedsStorageGarbageCollection(false); | 
| 557 } | 557 } | 
| 558 system_->management_policy()->RegisterProvider( | 558 system_->management_policy()->RegisterProvider( | 
| 559 shared_module_policy_provider_.get()); | 559 shared_module_policy_provider_.get()); | 
| 560 } | 560 } | 
| 561 | 561 | 
| 562 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", | 562 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", | 
| 563 base::Time::Now() - begin_time); | 563 base::Time::Now() - begin_time); | 
| 564 } | 564 } | 
| 565 | 565 | 
| 566 void ExtensionService::VerifyAllExtensions() { | 566 void ExtensionService::VerifyAllExtensions(bool bootstrap) { | 
| 567 ExtensionIdSet to_add; | 567 ExtensionIdSet to_add; | 
| 568 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); | 568 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); | 
| 569 | 569 | 
| 570 for (ExtensionSet::const_iterator i = all_extensions->begin(); | 570 for (ExtensionSet::const_iterator i = all_extensions->begin(); | 
| 571 i != all_extensions->end(); ++i) { | 571 i != all_extensions->end(); ++i) { | 
| 572 const Extension& extension = **i; | 572 const Extension& extension = **i; | 
| 573 | 573 | 
| 574 if (InstallVerifier::NeedsVerification(extension)) | 574 if (InstallVerifier::NeedsVerification(extension)) | 
| 575 to_add.insert(extension.id()); | 575 to_add.insert(extension.id()); | 
| 576 } | 576 } | 
| 577 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany( | 577 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany( | 
| 578 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions, | 578 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions, | 
| 579 AsWeakPtr())); | 579 AsWeakPtr(), bootstrap)); | 
| 580 } | 580 } | 
| 581 | 581 | 
| 582 void ExtensionService::FinishVerifyAllExtensions(bool success) { | 582 namespace { | 
| 583 | |
| 584 enum VerifyAllSuccess { | |
| 585 VERIFY_ALL_BOOTSTRAP_SUCCESS, | |
| 
Finnur
2014/01/29 10:35:42
Nit: We're not consistent on this throughout Chrom
 
asargent_no_longer_on_chrome
2014/01/29 19:52:51
Good advice, done.
 | |
| 586 VERIFY_ALL_BOOTSTRAP_FAILURE, | |
| 587 VERIFY_ALL_NON_BOOTSTRAP_SUCCESS, | |
| 588 VERIFY_ALL_NON_BOOTSTRAP_FAILURE, | |
| 589 | |
| 590 // Used in histograms. Do not remove/reorder any entries above, and the below | |
| 591 // MAX entry should always come last. | |
| 592 | |
| 593 VERIFY_ALL_SUCCESS_MAX | |
| 594 }; | |
| 595 | |
| 596 void LogVerifyAllSuccessHistogram(bool bootstrap, bool success) { | |
| 597 VerifyAllSuccess result; | |
| 598 if (bootstrap && success) | |
| 599 result = VERIFY_ALL_BOOTSTRAP_SUCCESS; | |
| 600 else if (bootstrap && !success) | |
| 601 result = VERIFY_ALL_BOOTSTRAP_FAILURE; | |
| 602 else if (!bootstrap && success) | |
| 603 result = VERIFY_ALL_NON_BOOTSTRAP_SUCCESS; | |
| 604 else | |
| 605 result = VERIFY_ALL_NON_BOOTSTRAP_FAILURE; | |
| 606 | |
| 607 UMA_HISTOGRAM_ENUMERATION("ExtensionService.VerifyAllSuccess", | |
| 608 result, VERIFY_ALL_SUCCESS_MAX); | |
| 609 } | |
| 610 | |
| 611 } // namespace | |
| 612 | |
| 613 void ExtensionService::FinishVerifyAllExtensions(bool bootstrap, bool success) { | |
| 614 LogVerifyAllSuccessHistogram(bootstrap, success); | |
| 583 if (success) { | 615 if (success) { | 
| 584 // Check to see if any currently unverified extensions became verified. | 616 // Check to see if any currently unverified extensions became verified. | 
| 585 InstallVerifier* verifier = | 617 InstallVerifier* verifier = | 
| 586 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 618 extensions::ExtensionSystem::Get(profile_)->install_verifier(); | 
| 587 const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); | 619 const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); | 
| 588 for (ExtensionSet::const_iterator i = disabled_extensions.begin(); | 620 for (ExtensionSet::const_iterator i = disabled_extensions.begin(); | 
| 589 i != disabled_extensions.end(); ++i) { | 621 i != disabled_extensions.end(); ++i) { | 
| 590 const Extension& extension = **i; | 622 const Extension& extension = **i; | 
| 591 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); | 623 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id()); | 
| 592 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED && | 624 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED && | 
| (...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2171 delayed_installs_.Insert(extension); | 2203 delayed_installs_.Insert(extension); | 
| 2172 } | 2204 } | 
| 2173 } else { | 2205 } else { | 
| 2174 AddNewOrUpdatedExtension(extension, | 2206 AddNewOrUpdatedExtension(extension, | 
| 2175 initial_state, | 2207 initial_state, | 
| 2176 blacklist_state, | 2208 blacklist_state, | 
| 2177 page_ordinal); | 2209 page_ordinal); | 
| 2178 } | 2210 } | 
| 2179 } | 2211 } | 
| 2180 | 2212 | 
| 2213 namespace { | |
| 2214 | |
| 2215 void LogAddVerifiedSuccess(bool success) { | |
| 2216 UMA_HISTOGRAM_BOOLEAN("ExtensionService.AddVerified", success); | |
| 2217 } | |
| 
Finnur
2014/01/29 10:35:42
nit: I would probably prefer to group these utilit
 
asargent_no_longer_on_chrome
2014/01/29 19:52:51
Done.
 | |
| 2218 | |
| 2219 } // namespace | |
| 2220 | |
| 2181 void ExtensionService::AddNewOrUpdatedExtension( | 2221 void ExtensionService::AddNewOrUpdatedExtension( | 
| 2182 const Extension* extension, | 2222 const Extension* extension, | 
| 2183 Extension::State initial_state, | 2223 Extension::State initial_state, | 
| 2184 extensions::BlacklistState blacklist_state, | 2224 extensions::BlacklistState blacklist_state, | 
| 2185 const syncer::StringOrdinal& page_ordinal) { | 2225 const syncer::StringOrdinal& page_ordinal) { | 
| 2186 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2226 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| 2187 const bool blacklisted_for_malware = | 2227 const bool blacklisted_for_malware = | 
| 2188 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2228 blacklist_state == extensions::BLACKLISTED_MALWARE; | 
| 2189 extension_prefs_->OnExtensionInstalled(extension, | 2229 extension_prefs_->OnExtensionInstalled(extension, | 
| 2190 initial_state, | 2230 initial_state, | 
| 2191 blacklisted_for_malware, | 2231 blacklisted_for_malware, | 
| 2192 page_ordinal); | 2232 page_ordinal); | 
| 2193 delayed_installs_.Remove(extension->id()); | 2233 delayed_installs_.Remove(extension->id()); | 
| 2194 if (InstallVerifier::NeedsVerification(*extension)) { | 2234 if (InstallVerifier::NeedsVerification(*extension)) { | 
| 2195 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( | 2235 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add( | 
| 2196 extension->id(), InstallVerifier::AddResultCallback()); | 2236 extension->id(), base::Bind(LogAddVerifiedSuccess)); | 
| 2197 } | 2237 } | 
| 2198 FinishInstallation(extension); | 2238 FinishInstallation(extension); | 
| 2199 } | 2239 } | 
| 2200 | 2240 | 
| 2201 void ExtensionService::MaybeFinishDelayedInstallation( | 2241 void ExtensionService::MaybeFinishDelayedInstallation( | 
| 2202 const std::string& extension_id) { | 2242 const std::string& extension_id) { | 
| 2203 // Check if the extension already got installed. | 2243 // Check if the extension already got installed. | 
| 2204 if (!delayed_installs_.Contains(extension_id)) | 2244 if (!delayed_installs_.Contains(extension_id)) | 
| 2205 return; | 2245 return; | 
| 2206 extensions::ExtensionPrefs::DelayReason reason = | 2246 extensions::ExtensionPrefs::DelayReason reason = | 
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2776 void ExtensionService::UnloadAllExtensionsInternal() { | 2816 void ExtensionService::UnloadAllExtensionsInternal() { | 
| 2777 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2817 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 
| 2778 | 2818 | 
| 2779 registry_->ClearAll(); | 2819 registry_->ClearAll(); | 
| 2780 system_->runtime_data()->ClearAll(); | 2820 system_->runtime_data()->ClearAll(); | 
| 2781 | 2821 | 
| 2782 // TODO(erikkay) should there be a notification for this? We can't use | 2822 // TODO(erikkay) should there be a notification for this? We can't use | 
| 2783 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2823 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 
| 2784 // or uninstalled. | 2824 // or uninstalled. | 
| 2785 } | 2825 } | 
| OLD | NEW |