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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 16 #include "extensions/browser/blacklist_state.h" | 15 #include "extensions/browser/preload_check.h" |
| 17 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 18 | 17 |
| 19 class Profile; | 18 class Profile; |
| 20 | 19 |
| 21 namespace extensions { | 20 namespace extensions { |
| 22 | 21 |
| 23 class RequirementsChecker; | 22 class RequirementsChecker; |
| 24 | 23 |
| 25 // Performs common checks for validating whether an extension may be installed. | 24 // Performs common checks for validating whether an extension may be installed. |
| 26 // This class should be Start()-ed at most once. | 25 // This class should be Start()-ed at most once. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 58 |
| 60 // Returns true if any checks are currently running. | 59 // Returns true if any checks are currently running. |
| 61 bool is_running() const { return running_checks_ != 0; } | 60 bool is_running() const { return running_checks_ != 0; } |
| 62 | 61 |
| 63 // Returns the requirement violations. A non-empty list is considered to be | 62 // Returns the requirement violations. A non-empty list is considered to be |
| 64 // a check failure. | 63 // a check failure. |
| 65 const std::vector<std::string>& requirement_errors() const { | 64 const std::vector<std::string>& requirement_errors() const { |
| 66 return requirement_errors_; | 65 return requirement_errors_; |
| 67 } | 66 } |
| 68 | 67 |
| 69 // Returns the blacklist state of the extension. A blacklist state of | 68 // Returns the blacklist error of the extension. A blacklist state of |
| 70 // BLACKLISTED_MALWARE is considered to be a check failure. | 69 // BLACKLISTED_MALWARE is considered to be a check failure. |
|
Devlin
2017/03/22 15:08:46
BLACKLISTED_ID
michaelpg
2017/03/24 02:34:16
I see why this is confusing, so I've changed the c
| |
| 71 BlacklistState blacklist_state() const { return blacklist_state_; } | 70 PreloadCheck::Error blacklist_error() const { return blacklist_error_; } |
| 72 | 71 |
| 73 // Returns whether management policy permits installation of the extension. | 72 // Returns whether management policy permits installation of the extension. |
| 74 bool policy_allows_load() const { return policy_allows_load_; } | |
| 75 const std::string& policy_error() const { return policy_error_; } | 73 const std::string& policy_error() const { return policy_error_; } |
| 76 | 74 |
| 75 void SetBlacklistCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { | |
| 76 blacklist_check_ = std::move(policy_check); | |
| 77 } | |
| 78 void SetPolicyCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { | |
| 79 policy_check_ = std::move(policy_check); | |
| 80 } | |
| 81 | |
| 77 protected: | 82 protected: |
| 78 virtual void CheckManagementPolicy(); | 83 virtual void CheckManagementPolicy(); |
| 79 void OnManagementPolicyCheckDone(bool allows_load, const std::string& error); | 84 void OnManagementPolicyCheckDone(PreloadCheck::Errors errors); |
| 80 | 85 |
| 81 virtual void CheckRequirements(); | 86 virtual void CheckRequirements(); |
| 82 void OnRequirementsCheckDone(const std::vector<std::string>& errors); | 87 void OnRequirementsCheckDone(const std::vector<std::string>& errors); |
| 83 | 88 |
| 84 virtual void CheckBlacklistState(); | 89 virtual void CheckBlacklistState(); |
| 85 void OnBlacklistStateCheckDone(BlacklistState state); | 90 void OnBlacklistStateCheckDone(PreloadCheck::Errors errors); |
| 86 | 91 |
| 87 private: | 92 private: |
| 88 void MaybeInvokeCallback(); | 93 void MaybeInvokeCallback(); |
| 89 | 94 |
| 90 std::unique_ptr<RequirementsChecker> requirements_checker_; | |
| 91 | |
| 92 // The Profile where the extension is being installed in. | 95 // The Profile where the extension is being installed in. |
| 93 Profile* profile_; | 96 Profile* profile_; |
| 94 | 97 |
| 95 // The extension to run checks for. | 98 // The extension to run checks for. |
| 96 scoped_refptr<const Extension> extension_; | 99 scoped_refptr<const Extension> extension_; |
| 97 | 100 |
| 98 // Requirement violations. | 101 // Checks requirements specified in the manifest. |
| 102 std::unique_ptr<RequirementsChecker> requirements_checker_; | |
| 99 std::vector<std::string> requirement_errors_; | 103 std::vector<std::string> requirement_errors_; |
| 100 | 104 |
| 101 // Result of the blacklist state check. | 105 // Checks if the extension is blacklisted. |
| 102 BlacklistState blacklist_state_; | 106 std::unique_ptr<PreloadCheck> blacklist_check_; |
| 107 PreloadCheck::Error blacklist_error_; | |
| 103 | 108 |
| 104 // Whether the extension can be installed, according to management policies. | 109 // Checks whether management policies allow the extension to be installed. |
| 105 bool policy_allows_load_; | 110 std::unique_ptr<PreloadCheck> policy_check_; |
| 106 std::string policy_error_; | 111 std::string policy_error_; |
| 107 | 112 |
| 108 // Bitmask of enabled checks. | 113 // Bitmask of enabled checks. |
| 109 int enabled_checks_; | 114 int enabled_checks_; |
| 110 | 115 |
| 111 // Bitmask of currently running checks. | 116 // Bitmask of currently running checks. |
| 112 int running_checks_; | 117 int running_checks_; |
| 113 | 118 |
| 114 // If true, the callback is invoked when the first check fails. | 119 // If true, the callback is invoked when the first check fails. |
| 115 bool fail_fast_; | 120 bool fail_fast_; |
| 116 | 121 |
| 117 // The callback to invoke when checks are complete. | 122 // The callback to invoke when checks are complete. |
| 118 Callback callback_; | 123 Callback callback_; |
| 119 | 124 |
| 120 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); | 125 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); |
| 123 }; | 126 }; |
| 124 | 127 |
| 125 } // namespace extensions | 128 } // namespace extensions |
| 126 | 129 |
| 127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | 130 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ |
| OLD | NEW |