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

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

Issue 2737053002: Update ExtensionInstallChecker to use PreloadCheck classes (Closed)
Patch Set: rebase Created 3 years, 9 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
index d027389d6e26b672969e8e8c84a9c644216ccfc1..bb9feb00051d34b07b4fc8621849fcefa833aad1 100644
--- a/chrome/browser/extensions/extension_install_checker.cc
+++ b/chrome/browser/extensions/extension_install_checker.cc
@@ -5,13 +5,15 @@
#include "chrome/browser/extensions/extension_install_checker.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/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/management_policy.h"
+#include "extensions/browser/policy_check.h"
namespace extensions {
@@ -22,8 +24,7 @@ ExtensionInstallChecker::ExtensionInstallChecker(
bool fail_fast)
: profile_(profile),
extension_(extension),
- blacklist_state_(NOT_BLACKLISTED),
- policy_allows_load_(true),
+ blacklist_error_(PreloadCheck::NONE),
enabled_checks_(enabled_checks),
running_checks_(0),
fail_fast_(fail_fast),
@@ -71,18 +72,17 @@ void ExtensionInstallChecker::Start(const Callback& callback) {
void ExtensionInstallChecker::CheckManagementPolicy() {
DCHECK(extension_.get());
- base::string16 error;
- bool allow = ExtensionSystem::Get(profile_)->management_policy()->UserMayLoad(
- extension_.get(), &error);
- OnManagementPolicyCheckDone(allow, base::UTF16ToUTF8(error));
+ 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(
- bool allows_load,
- const std::string& error) {
- policy_allows_load_ = allows_load;
- policy_error_ = error;
- DCHECK(policy_allows_load_ || !policy_error_.empty());
+ PreloadCheck::Errors errors) {
+ if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY))
+ policy_error_ = base::UTF16ToUTF8(policy_check_->GetErrorMessage());
running_checks_ &= ~CHECK_MANAGEMENT_POLICY;
MaybeInvokeCallback();
@@ -110,17 +110,23 @@ void ExtensionInstallChecker::OnRequirementsCheckDone(
void ExtensionInstallChecker::CheckBlacklistState() {
DCHECK(extension_.get());
- extensions::Blacklist* blacklist = Blacklist::Get(profile_);
- blacklist->IsBlacklisted(
- extension_->id(),
- base::Bind(&ExtensionInstallChecker::OnBlacklistStateCheckDone,
- weak_ptr_factory_.GetWeakPtr()));
+ if (!blacklist_check_) {
+ blacklist_check_ = base::MakeUnique<BlacklistCheck>(
+ Blacklist::Get(profile_), extension_.get());
+ }
+ blacklist_check_->Start(
+ base::BindOnce(&ExtensionInstallChecker::OnBlacklistStateCheckDone,
+ weak_ptr_factory_.GetWeakPtr()));
}
-void ExtensionInstallChecker::OnBlacklistStateCheckDone(BlacklistState state) {
+void ExtensionInstallChecker::OnBlacklistStateCheckDone(
+ PreloadCheck::Errors errors) {
DCHECK(is_running());
- blacklist_state_ = state;
+ if (errors.empty())
+ blacklist_error_ = PreloadCheck::NONE;
+ else
+ blacklist_error_ = *errors.begin();
running_checks_ &= ~CHECK_BLACKLIST;
MaybeInvokeCallback();
@@ -132,11 +138,11 @@ void ExtensionInstallChecker::MaybeInvokeCallback() {
// Set bits for failed checks.
int failed_mask = 0;
- if (blacklist_state_ == BLACKLISTED_MALWARE)
+ if (blacklist_error_ == PreloadCheck::BLACKLISTED_ID)
failed_mask |= CHECK_BLACKLIST;
if (!requirement_errors_.empty())
failed_mask |= CHECK_REQUIREMENTS;
- if (!policy_allows_load_)
+ if (!policy_error_.empty())
failed_mask |= CHECK_MANAGEMENT_POLICY;
// Invoke callback if all checks are complete or there was at least one
@@ -145,6 +151,8 @@ void ExtensionInstallChecker::MaybeInvokeCallback() {
// If we are failing fast, discard any pending results.
weak_ptr_factory_.InvalidateWeakPtrs();
running_checks_ = 0;
+ policy_check_.reset();
+ blacklist_check_.reset();
base::ResetAndReturn(&callback_).Run(failed_mask);
}
}
« no previous file with comments | « chrome/browser/extensions/extension_install_checker.h ('k') | chrome/browser/extensions/extension_install_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698