Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_install_checker.h" | 5 #include "chrome/browser/extensions/extension_install_checker.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/blacklist.h" | 11 #include "chrome/browser/extensions/blacklist.h" |
| 12 #include "chrome/browser/extensions/blacklist_check.h" | 12 #include "chrome/browser/extensions/blacklist_check.h" |
| 13 #include "chrome/browser/extensions/chrome_requirements_checker.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/browser/policy_check.h" | 16 #include "extensions/browser/policy_check.h" |
| 17 #include "extensions/browser/requirements_checker.h" | |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 ExtensionInstallChecker::ExtensionInstallChecker( | 21 ExtensionInstallChecker::ExtensionInstallChecker( |
| 22 Profile* profile, | 22 Profile* profile, |
| 23 scoped_refptr<const Extension> extension, | 23 scoped_refptr<const Extension> extension, |
| 24 int enabled_checks, | 24 int enabled_checks, |
| 25 bool fail_fast) | 25 bool fail_fast) |
| 26 : profile_(profile), | 26 : profile_(profile), |
| 27 extension_(extension), | 27 extension_(extension), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 if (!errors.empty()) { | 83 if (!errors.empty()) { |
| 84 DCHECK_EQ(1u, errors.count(PreloadCheck::DISALLOWED_BY_POLICY)); | 84 DCHECK_EQ(1u, errors.count(PreloadCheck::DISALLOWED_BY_POLICY)); |
| 85 policy_error_ = base::UTF16ToUTF8(policy_check_->GetErrorMessage()); | 85 policy_error_ = base::UTF16ToUTF8(policy_check_->GetErrorMessage()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 running_checks_ &= ~CHECK_MANAGEMENT_POLICY; | 88 running_checks_ &= ~CHECK_MANAGEMENT_POLICY; |
| 89 MaybeInvokeCallback(); | 89 MaybeInvokeCallback(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ExtensionInstallChecker::CheckRequirements() { | 92 void ExtensionInstallChecker::CheckRequirements() { |
| 93 requirements_checker_ = base::MakeUnique<ChromeRequirementsChecker>(); | 93 // In tests, this check may already be stubbed. |
| 94 requirements_checker_->Check( | 94 if (!requirements_check_) { |
| 95 extension_, base::Bind(&ExtensionInstallChecker::OnRequirementsCheckDone, | 95 requirements_check_ = |
| 96 weak_ptr_factory_.GetWeakPtr())); | 96 base::MakeUnique<RequirementsChecker>(extension_.get()); |
| 97 } | |
| 98 requirements_check_->Start( | |
| 99 base::BindOnce(&ExtensionInstallChecker::OnRequirementsCheckDone, | |
| 100 weak_ptr_factory_.GetWeakPtr())); | |
| 97 } | 101 } |
| 98 | 102 |
| 99 void ExtensionInstallChecker::OnRequirementsCheckDone( | 103 void ExtensionInstallChecker::OnRequirementsCheckDone( |
| 100 const std::vector<std::string>& errors) { | 104 PreloadCheck::Errors errors) { |
| 101 DCHECK(is_running()); | 105 DCHECK(is_running()); |
| 102 | 106 |
| 103 requirement_errors_ = errors; | 107 requirements_error_message_ = |
| 108 base::UTF16ToUTF8(requirements_check_->GetErrorMessage()); | |
|
Devlin
2017/03/30 17:10:55
This back and forth between conversions is a shame
michaelpg
2017/03/30 22:49:01
Done.
| |
| 104 | 109 |
| 105 running_checks_ &= ~CHECK_REQUIREMENTS; | 110 running_checks_ &= ~CHECK_REQUIREMENTS; |
| 106 MaybeInvokeCallback(); | 111 MaybeInvokeCallback(); |
| 107 } | 112 } |
| 108 | 113 |
| 109 void ExtensionInstallChecker::CheckBlacklistState() { | 114 void ExtensionInstallChecker::CheckBlacklistState() { |
| 110 // In tests, this check may already be stubbed. | 115 // In tests, this check may already be stubbed. |
| 111 if (!blacklist_check_) { | 116 if (!blacklist_check_) { |
| 112 blacklist_check_ = base::MakeUnique<BlacklistCheck>( | 117 blacklist_check_ = base::MakeUnique<BlacklistCheck>( |
| 113 Blacklist::Get(profile_), extension_.get()); | 118 Blacklist::Get(profile_), extension_.get()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 133 } | 138 } |
| 134 | 139 |
| 135 void ExtensionInstallChecker::MaybeInvokeCallback() { | 140 void ExtensionInstallChecker::MaybeInvokeCallback() { |
| 136 if (callback_.is_null()) | 141 if (callback_.is_null()) |
| 137 return; | 142 return; |
| 138 | 143 |
| 139 // Set bits for failed checks. | 144 // Set bits for failed checks. |
| 140 int failed_mask = 0; | 145 int failed_mask = 0; |
| 141 if (blacklist_error_ == PreloadCheck::BLACKLISTED_ID) | 146 if (blacklist_error_ == PreloadCheck::BLACKLISTED_ID) |
| 142 failed_mask |= CHECK_BLACKLIST; | 147 failed_mask |= CHECK_BLACKLIST; |
| 143 if (!requirement_errors_.empty()) | 148 if (requirements_error_message_.size()) |
|
Devlin
2017/03/30 17:10:55
nit: I think we have a slight preference to prefer
michaelpg
2017/03/30 22:49:00
Done. It's not slight -- apparently it's about 35:
| |
| 144 failed_mask |= CHECK_REQUIREMENTS; | 149 failed_mask |= CHECK_REQUIREMENTS; |
| 145 if (!policy_error_.empty()) | 150 if (!policy_error_.empty()) |
| 146 failed_mask |= CHECK_MANAGEMENT_POLICY; | 151 failed_mask |= CHECK_MANAGEMENT_POLICY; |
| 147 | 152 |
| 148 // Invoke callback if all checks are complete or there was at least one | 153 // Invoke callback if all checks are complete or there was at least one |
| 149 // failure and |fail_fast_| is true. | 154 // failure and |fail_fast_| is true. |
| 150 if (!is_running() || (failed_mask && fail_fast_)) { | 155 if (!is_running() || (failed_mask && fail_fast_)) { |
| 151 running_checks_ = 0; | 156 running_checks_ = 0; |
| 152 | 157 |
| 153 // If we are failing fast, discard any pending results. | 158 // If we are failing fast, discard any pending results. |
| 154 blacklist_check_.reset(); | 159 blacklist_check_.reset(); |
| 155 policy_check_.reset(); | 160 policy_check_.reset(); |
| 156 requirements_checker_.reset(); | 161 requirements_check_.reset(); |
| 157 weak_ptr_factory_.InvalidateWeakPtrs(); | 162 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 158 base::ResetAndReturn(&callback_).Run(failed_mask); | 163 base::ResetAndReturn(&callback_).Run(failed_mask); |
| 159 } | 164 } |
| 160 } | 165 } |
| 161 | 166 |
| 162 } // namespace extensions | 167 } // namespace extensions |
| OLD | NEW |