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

Unified Diff: chrome/browser/extensions/extension_install_checker.cc

Issue 2783143005: Replace ExtensionInstallChecker with generic PreloadCheckGroup (Closed)
Patch Set: (no change) Created 3 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 side-by-side diff with in-line comments
Download patch
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
deleted file mode 100644
index d529647e853fd48ce8f745a60b534e192a23e165..0000000000000000000000000000000000000000
--- a/chrome/browser/extensions/extension_install_checker.cc
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/extension_install_checker.h"
-
-#include "base/bind_helpers.h"
-#include "base/callback_helpers.h"
-#include "base/memory/ptr_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/extensions/blacklist.h"
-#include "chrome/browser/extensions/blacklist_check.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,
- scoped_refptr<const Extension> extension,
- int enabled_checks,
- bool fail_fast)
- : profile_(profile),
- extension_(extension),
- enabled_checks_(enabled_checks),
- running_checks_(0),
- fail_fast_(fail_fast),
- weak_ptr_factory_(this) {}
-
-ExtensionInstallChecker::~ExtensionInstallChecker() {
-}
-
-void ExtensionInstallChecker::Start(const Callback& callback) {
- // Profile is null in tests.
- if (profile_) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // TODO(michaelpg): change NOTREACHED to [D]CHECK here and below.
- if (!extension_.get()) {
- NOTREACHED();
- return;
- }
- }
-
- if (is_running() || !enabled_checks_ || callback.is_null()) {
- NOTREACHED();
- return;
- }
-
- running_checks_ = enabled_checks_;
- callback_ = callback;
-
- // Execute the management policy check first as it is synchronous.
- if (enabled_checks_ & CHECK_MANAGEMENT_POLICY) {
- CheckManagementPolicy();
- if (!is_running())
- return;
- }
-
- if (enabled_checks_ & CHECK_REQUIREMENTS) {
- CheckRequirements();
- if (!is_running())
- return;
- }
-
- if (enabled_checks_ & CHECK_BLACKLIST)
- CheckBlacklistState();
-}
-
-void ExtensionInstallChecker::CheckManagementPolicy() {
- // In tests, this check may already be stubbed.
- if (!policy_check_)
- policy_check_ = base::MakeUnique<PolicyCheck>(profile_, extension_);
- policy_check_->Start(
- base::BindOnce(&ExtensionInstallChecker::OnManagementPolicyCheckDone,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void ExtensionInstallChecker::OnManagementPolicyCheckDone(
- PreloadCheck::Errors errors) {
- if (!errors.empty()) {
- DCHECK_EQ(1u, errors.count(PreloadCheck::DISALLOWED_BY_POLICY));
- policy_error_ = policy_check_->GetErrorMessage();
- }
-
- running_checks_ &= ~CHECK_MANAGEMENT_POLICY;
- MaybeInvokeCallback();
-}
-
-void ExtensionInstallChecker::CheckRequirements() {
- // In tests, this check may already be stubbed.
- if (!requirements_check_)
- requirements_check_ = base::MakeUnique<RequirementsChecker>(extension_);
- requirements_check_->Start(
- base::BindOnce(&ExtensionInstallChecker::OnRequirementsCheckDone,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void ExtensionInstallChecker::OnRequirementsCheckDone(
- PreloadCheck::Errors errors) {
- DCHECK(is_running());
-
- requirements_error_message_ = requirements_check_->GetErrorMessage();
-
- running_checks_ &= ~CHECK_REQUIREMENTS;
- MaybeInvokeCallback();
-}
-
-void ExtensionInstallChecker::CheckBlacklistState() {
- // In tests, this check may already be stubbed.
- if (!blacklist_check_) {
- blacklist_check_ =
- base::MakeUnique<BlacklistCheck>(Blacklist::Get(profile_), extension_);
- }
- blacklist_check_->Start(
- base::BindOnce(&ExtensionInstallChecker::OnBlacklistStateCheckDone,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void ExtensionInstallChecker::OnBlacklistStateCheckDone(
- PreloadCheck::Errors errors) {
- DCHECK(is_running());
-
- if (errors.empty()) {
- blacklist_error_ = PreloadCheck::NONE;
- } else {
- DCHECK_EQ(1u, errors.size());
- blacklist_error_ = *errors.begin();
- }
-
- running_checks_ &= ~CHECK_BLACKLIST;
- MaybeInvokeCallback();
-}
-
-void ExtensionInstallChecker::MaybeInvokeCallback() {
- if (callback_.is_null())
- return;
-
- // Set bits for failed checks.
- int failed_mask = 0;
- if (blacklist_error_ == PreloadCheck::BLACKLISTED_ID)
- failed_mask |= CHECK_BLACKLIST;
- if (!requirements_error_message_.empty())
- failed_mask |= CHECK_REQUIREMENTS;
- if (!policy_error_.empty())
- 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_)) {
- running_checks_ = 0;
-
- // If we are failing fast, discard any pending results.
- blacklist_check_.reset();
- policy_check_.reset();
- requirements_check_.reset();
- weak_ptr_factory_.InvalidateWeakPtrs();
- base::ResetAndReturn(&callback_).Run(failed_mask);
- }
-}
-
-} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698