| 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/preload_check.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; | |
| 24 | |
| 25 // Performs common checks for validating whether an extension may be installed. | 23 // Performs common checks for validating whether an extension may be installed. |
| 26 // This class should be Start()-ed at most once. | 24 // This class should be Start()-ed at most once. |
| 27 class ExtensionInstallChecker { | 25 class ExtensionInstallChecker { |
| 28 public: | 26 public: |
| 29 // Called when checks are complete. The returned value is a bitmask of | 27 // Called when checks are complete. The returned value is a bitmask of |
| 30 // failed checks. | 28 // failed checks. |
| 31 typedef base::Callback<void(int)> Callback; | 29 typedef base::Callback<void(int)> Callback; |
| 32 | 30 |
| 33 enum CheckType { | 31 enum CheckType { |
| 34 // Check the blacklist state of the extension. | 32 // Check the blacklist state of the extension. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 | 51 |
| 54 // Starts the set of checks. |callback| will only be called once. | 52 // Starts the set of checks. |callback| will only be called once. |
| 55 // This function must be called on the UI thread. The callback also occurs on | 53 // This function must be called on the UI thread. The callback also occurs on |
| 56 // the UI thread. Checks may run asynchronously in parallel. | 54 // the UI thread. Checks may run asynchronously in parallel. |
| 57 // This function should be invoked at most once. | 55 // This function should be invoked at most once. |
| 58 void Start(const Callback& callback); | 56 void Start(const Callback& callback); |
| 59 | 57 |
| 60 // Returns true if any checks are currently running. | 58 // Returns true if any checks are currently running. |
| 61 bool is_running() const { return running_checks_ != 0; } | 59 bool is_running() const { return running_checks_ != 0; } |
| 62 | 60 |
| 63 // Returns the requirement violations. A non-empty list is considered to be | 61 // Returns the error message for requirement violations, if any were found. |
| 64 // a check failure. | 62 const base::string16& requirements_error_message() const { |
| 65 const std::vector<std::string>& requirement_errors() const { | 63 return requirements_error_message_; |
| 66 return requirement_errors_; | |
| 67 } | 64 } |
| 68 | 65 |
| 69 // Returns the blacklist error of the extension. Note that there is only an | 66 // Returns the blacklist error of the extension. Note that there is only an |
| 70 // error if the BlacklistState is BLACKLISTED_MALWARE or BLACKLISTED_UNKNOWN. | 67 // error if the BlacklistState is BLACKLISTED_MALWARE or BLACKLISTED_UNKNOWN. |
| 71 PreloadCheck::Error blacklist_error() const { return blacklist_error_; } | 68 PreloadCheck::Error blacklist_error() const { return blacklist_error_; } |
| 72 | 69 |
| 73 // Returns whether management policy permits installation of the extension. | 70 // Returns whether management policy permits installation of the extension. |
| 74 const std::string& policy_error() const { return policy_error_; } | 71 const base::string16& policy_error() const { return policy_error_; } |
| 75 | 72 |
| 76 void SetBlacklistCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { | 73 void SetBlacklistCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { |
| 77 blacklist_check_ = std::move(policy_check); | 74 blacklist_check_ = std::move(policy_check); |
| 78 } | 75 } |
| 79 void SetPolicyCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { | 76 void SetPolicyCheckForTesting(std::unique_ptr<PreloadCheck> policy_check) { |
| 80 policy_check_ = std::move(policy_check); | 77 policy_check_ = std::move(policy_check); |
| 81 } | 78 } |
| 79 void SetRequirementsCheckForTesting( |
| 80 std::unique_ptr<PreloadCheck> requirements_check) { |
| 81 requirements_check_ = std::move(requirements_check); |
| 82 } |
| 82 | 83 |
| 83 protected: | 84 protected: |
| 84 virtual void CheckManagementPolicy(); | 85 virtual void CheckManagementPolicy(); |
| 85 void OnManagementPolicyCheckDone(PreloadCheck::Errors errors); | 86 void OnManagementPolicyCheckDone(PreloadCheck::Errors errors); |
| 86 | 87 |
| 87 virtual void CheckRequirements(); | 88 virtual void CheckRequirements(); |
| 88 void OnRequirementsCheckDone(const std::vector<std::string>& errors); | 89 void OnRequirementsCheckDone(PreloadCheck::Errors errors); |
| 89 | 90 |
| 90 virtual void CheckBlacklistState(); | 91 virtual void CheckBlacklistState(); |
| 91 void OnBlacklistStateCheckDone(PreloadCheck::Errors errors); | 92 void OnBlacklistStateCheckDone(PreloadCheck::Errors errors); |
| 92 | 93 |
| 93 private: | 94 private: |
| 94 void MaybeInvokeCallback(); | 95 void MaybeInvokeCallback(); |
| 95 | 96 |
| 96 // The Profile where the extension is being installed in. | 97 // The Profile where the extension is being installed in. |
| 97 Profile* profile_; | 98 Profile* profile_; |
| 98 | 99 |
| 99 // The extension to run checks for. | 100 // The extension to run checks for. |
| 100 scoped_refptr<const Extension> extension_; | 101 scoped_refptr<const Extension> extension_; |
| 101 | 102 |
| 102 // Checks requirements specified in the manifest. | 103 // Checks requirements specified in the manifest. |
| 103 std::unique_ptr<RequirementsChecker> requirements_checker_; | 104 std::unique_ptr<PreloadCheck> requirements_check_; |
| 104 std::vector<std::string> requirement_errors_; | 105 base::string16 requirements_error_message_; |
| 105 | 106 |
| 106 // Checks if the extension is blacklisted. | 107 // Checks if the extension is blacklisted. |
| 107 std::unique_ptr<PreloadCheck> blacklist_check_; | 108 std::unique_ptr<PreloadCheck> blacklist_check_; |
| 108 PreloadCheck::Error blacklist_error_ = PreloadCheck::NONE; | 109 PreloadCheck::Error blacklist_error_ = PreloadCheck::NONE; |
| 109 | 110 |
| 110 // Checks whether management policies allow the extension to be installed. | 111 // Checks whether management policies allow the extension to be installed. |
| 111 std::unique_ptr<PreloadCheck> policy_check_; | 112 std::unique_ptr<PreloadCheck> policy_check_; |
| 112 std::string policy_error_; | 113 base::string16 policy_error_; |
| 113 | 114 |
| 114 // Bitmask of enabled checks. | 115 // Bitmask of enabled checks. |
| 115 int enabled_checks_; | 116 int enabled_checks_; |
| 116 | 117 |
| 117 // Bitmask of currently running checks. | 118 // Bitmask of currently running checks. |
| 118 // TODO(michaelpg): Consolidate this with enabled_checks_. | 119 // TODO(michaelpg): Consolidate this with enabled_checks_. |
| 119 int running_checks_; | 120 int running_checks_; |
| 120 | 121 |
| 121 // If true, the callback is invoked when the first check fails. | 122 // If true, the callback is invoked when the first check fails. |
| 122 bool fail_fast_; | 123 bool fail_fast_; |
| 123 | 124 |
| 124 // The callback to invoke when checks are complete. | 125 // The callback to invoke when checks are complete. |
| 125 Callback callback_; | 126 Callback callback_; |
| 126 | 127 |
| 127 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; | 128 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; |
| 128 | 129 |
| 129 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); | 130 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 } // namespace extensions | 133 } // namespace extensions |
| 133 | 134 |
| 134 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | 135 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ |
| OLD | NEW |