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