| Index: chrome/browser/extensions/extension_install_checker.cc
|
| diff --git a/chrome/browser/extensions/extension_install_checker.cc b/chrome/browser/extensions/extension_install_checker.cc
|
| index 8498e3cbcf72a7de0a50d96f8ec3529817729b38..f24372aad937e21e210a060d894c6c808ff37fe1 100644
|
| --- a/chrome/browser/extensions/extension_install_checker.cc
|
| +++ b/chrome/browser/extensions/extension_install_checker.cc
|
| @@ -8,32 +8,33 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/extensions/blacklist.h"
|
| #include "chrome/browser/extensions/blacklist_check.h"
|
| -#include "chrome/browser/extensions/chrome_requirements_checker.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "extensions/browser/extension_system.h"
|
| #include "extensions/browser/policy_check.h"
|
| +#include "extensions/browser/requirements_checker.h"
|
|
|
| namespace extensions {
|
|
|
| ExtensionInstallChecker::ExtensionInstallChecker(Profile* profile)
|
| : profile_(profile),
|
| - blacklist_error_(PolicyCheck::NONE),
|
| - current_sequence_number_(0),
|
| - running_checks_(0),
|
| - fail_fast_(false),
|
| - weak_ptr_factory_(this) {}
|
| + blacklist_error_(PreloadCheck::NONE),
|
| + is_running_(false),
|
| + fail_fast_(false)/*,
|
| + weak_ptr_factory_(this)*/ {
|
| +}
|
|
|
| ExtensionInstallChecker::~ExtensionInstallChecker() {
|
| }
|
|
|
| -void ExtensionInstallChecker::Start(int enabled_checks,
|
| +void ExtensionInstallChecker::Start(scoped_refptr<const Extension> extension,
|
| + int enabled_checks,
|
| bool fail_fast,
|
| const Callback& callback) {
|
| // Profile is null in tests.
|
| if (profile_) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| - if (!extension_.get()) {
|
| + if (!extension.get()) {
|
| NOTREACHED();
|
| return;
|
| }
|
| @@ -44,137 +45,90 @@ void ExtensionInstallChecker::Start(int enabled_checks,
|
| return;
|
| }
|
|
|
| - running_checks_ = enabled_checks;
|
| + extension_ = extension;
|
| +
|
| fail_fast_ = fail_fast;
|
| callback_ = callback;
|
| - ResetResults();
|
| + preload_check_group_ =
|
| + base::MakeUnique<PreloadCheckGroup>(extension_.get(), fail_fast_);
|
|
|
| - // Execute the management policy check first as it is synchronous.
|
| + // Add the management policy check first as it is synchronous.
|
| if (enabled_checks & CHECK_MANAGEMENT_POLICY) {
|
| - CheckManagementPolicy();
|
| - if (!is_running())
|
| - return;
|
| + if (!policy_check_)
|
| + policy_check_ = base::MakeUnique<PolicyCheck>(profile_, extension_.get());
|
| + preload_check_group_->AddCheck(policy_check_.get());
|
| }
|
|
|
| if (enabled_checks & CHECK_REQUIREMENTS) {
|
| - CheckRequirements();
|
| - if (!is_running())
|
| - return;
|
| + if (!requirements_checker_) {
|
| + requirements_checker_ =
|
| + base::MakeUnique<RequirementsChecker>(extension_.get());
|
| + }
|
| + preload_check_group_->AddCheck(requirements_checker_.get());
|
| }
|
|
|
| - if (enabled_checks & CHECK_BLACKLIST)
|
| - CheckBlacklistState();
|
| -}
|
| -
|
| -void ExtensionInstallChecker::CheckManagementPolicy() {
|
| - DCHECK(extension_.get());
|
| -
|
| - if (!policy_check_)
|
| - policy_check_ = base::MakeUnique<PolicyCheck>(profile_, extension_.get());
|
| - policy_check_->Start(
|
| - base::BindOnce(&ExtensionInstallChecker::OnManagementPolicyCheckDone,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| -}
|
| -
|
| -void ExtensionInstallChecker::OnManagementPolicyCheckDone(
|
| - PreloadCheck::Errors errors) {
|
| - if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY))
|
| - policy_error_ = base::UTF16ToUTF8(policy_check_->GetErrorMessage());
|
| -
|
| - running_checks_ &= ~CHECK_MANAGEMENT_POLICY;
|
| - MaybeInvokeCallback();
|
| -}
|
| -
|
| -void ExtensionInstallChecker::CheckRequirements() {
|
| - DCHECK(extension_.get());
|
| -
|
| - if (!requirements_checker_.get())
|
| - requirements_checker_.reset(new ChromeRequirementsChecker());
|
| - requirements_checker_->Check(
|
| - extension_,
|
| - base::Bind(&ExtensionInstallChecker::OnRequirementsCheckDone,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - current_sequence_number_));
|
| -}
|
| -
|
| -void ExtensionInstallChecker::OnRequirementsCheckDone(
|
| - int sequence_number,
|
| - const std::vector<std::string>& errors) {
|
| - // Some pending results may arrive after fail fast.
|
| - if (sequence_number != current_sequence_number_)
|
| - return;
|
| -
|
| - requirement_errors_ = errors;
|
| -
|
| - running_checks_ &= ~CHECK_REQUIREMENTS;
|
| - MaybeInvokeCallback();
|
| -}
|
| -
|
| -void ExtensionInstallChecker::CheckBlacklistState() {
|
| - DCHECK(extension_.get());
|
| -
|
| - if (!blacklist_check_) {
|
| - blacklist_check_ = base::MakeUnique<BlacklistCheck>(
|
| - Blacklist::Get(profile_), extension_.get());
|
| + if (enabled_checks & CHECK_BLACKLIST) {
|
| + if (!blacklist_check_) {
|
| + blacklist_check_ = base::MakeUnique<BlacklistCheck>(
|
| + Blacklist::Get(profile_), extension_.get());
|
| + }
|
| + preload_check_group_->AddCheck(blacklist_check_.get());
|
| }
|
| - blacklist_check_->Start(
|
| - base::BindOnce(&ExtensionInstallChecker::OnBlacklistStateCheckDone,
|
| - weak_ptr_factory_.GetWeakPtr(), current_sequence_number_));
|
| +
|
| + is_running_ = true;
|
| + preload_check_group_->Start(
|
| + base::BindOnce(&ExtensionInstallChecker::OnInstallChecksComplete,
|
| + base::Unretained(this)));
|
| }
|
|
|
| -void ExtensionInstallChecker::OnBlacklistStateCheckDone(
|
| - int sequence_number,
|
| +void ExtensionInstallChecker::OnInstallChecksComplete(
|
| PreloadCheck::Errors errors) {
|
| - // Some pending results may arrive after fail fast.
|
| - if (sequence_number != current_sequence_number_)
|
| - return;
|
| + is_running_ = false;
|
|
|
| - if (errors.empty())
|
| - blacklist_error_ = PreloadCheck::NONE;
|
| - else
|
| - blacklist_error_ = *errors.begin();
|
| + int failed_mask = ProcessErrors(errors);
|
|
|
| - running_checks_ &= ~CHECK_BLACKLIST;
|
| - MaybeInvokeCallback();
|
| -}
|
| + // Discard any pending results.
|
| + preload_check_group_.reset();
|
| + requirements_checker_.reset();
|
| + policy_check_.reset();
|
| + blacklist_check_.reset();
|
|
|
| -void ExtensionInstallChecker::ResetResults() {
|
| - requirement_errors_.clear();
|
| - blacklist_error_ = PreloadCheck::NONE;
|
| - policy_error_.clear();
|
| + // This instance may be owned by the callback recipient and deleted here,
|
| + // so reset |callback_| first and invoke a copy of the callback.
|
| + Callback callback_copy = callback_;
|
| + callback_.Reset();
|
| + callback_copy.Run(failed_mask);
|
| }
|
|
|
| -void ExtensionInstallChecker::MaybeInvokeCallback() {
|
| - if (callback_.is_null())
|
| - return;
|
| -
|
| +int ExtensionInstallChecker::ProcessErrors(PreloadCheck::Errors errors) {
|
| // Set bits for failed checks.
|
| int failed_mask = 0;
|
| - if (blacklist_error_ == PreloadCheck::BLACKLISTED_ID)
|
| - failed_mask |= CHECK_BLACKLIST;
|
| - if (!requirement_errors_.empty())
|
| - failed_mask |= CHECK_REQUIREMENTS;
|
| - if (!policy_error_.empty())
|
| +
|
| + if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY)) {
|
| + DCHECK(policy_check_);
|
| + policy_error_ = policy_check_->GetErrorMessage();
|
| failed_mask |= CHECK_MANAGEMENT_POLICY;
|
|
|
| - // Invoke callback if all checks are complete or there was at least one
|
| - // failure and |fail_fast_| is true.
|
| - if (!is_running() || (failed_mask && fail_fast_)) {
|
| - // If we are failing fast, discard any pending results.
|
| - weak_ptr_factory_.InvalidateWeakPtrs();
|
| - running_checks_ = 0;
|
| - ++current_sequence_number_;
|
| + if (fail_fast_)
|
| + return failed_mask;
|
| + }
|
|
|
| - policy_check_.reset();
|
| - blacklist_check_.reset();
|
| + if (requirements_checker_)
|
| + requirement_error_message_ = requirements_checker_->GetErrorMessage();
|
| + if (requirement_error_message_.size()) {
|
| + failed_mask |= CHECK_REQUIREMENTS;
|
| + if (fail_fast_)
|
| + return failed_mask;
|
| + }
|
|
|
| - Callback callback_copy = callback_;
|
| - callback_.Reset();
|
| + if (errors.count(PreloadCheck::BLACKLISTED_ID))
|
| + blacklist_error_ = PreloadCheck::BLACKLISTED_ID;
|
| + else if (errors.count(PreloadCheck::BLACKLISTED_UNKNOWN))
|
| + blacklist_error_ = PreloadCheck::BLACKLISTED_UNKNOWN;
|
| + if (blacklist_error_ != PreloadCheck::NONE)
|
| + failed_mask |= CHECK_BLACKLIST;
|
|
|
| - // This instance may be owned by the callback recipient and deleted here,
|
| - // so reset |callback_| first and invoke a copy of the callback.
|
| - callback_copy.Run(failed_mask);
|
| - }
|
| + return failed_mask;
|
| }
|
|
|
| } // namespace extensions
|
|
|