Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 #include "extensions/browser/blacklist_state.h" | |
| 16 #include "extensions/common/extension.h" | |
| 17 | |
| 18 class Profile; | |
| 19 | |
| 20 namespace extensions { | |
| 21 | |
| 22 class RequirementsChecker; | |
| 23 | |
| 24 // Performs common checks for an extension. Extensions that violate these checks | |
| 25 // would be disabled or not even installed. | |
| 26 // | |
| 27 // TODO(tmdiep): This is an upgrade of ExtensionInstaller. CrxInstaller and | |
|
asargent_no_longer_on_chrome
2014/06/18 20:25:10
can you add a crbug entry and link to it here in t
tmdiep
2014/06/19 01:48:36
Done.
| |
| 28 // UnpackedInstaller should be refactored to use this class. | |
| 29 class ExtensionInstallChecker { | |
| 30 public: | |
| 31 // Called when checks are complete. The returned value is a bitmask of | |
| 32 // failed checks. | |
| 33 typedef base::Callback<void(int)> Callback; | |
| 34 | |
| 35 enum CheckType { | |
| 36 // Check the blacklist state of the extension. | |
| 37 CHECK_BLACKLIST = 1 << 0, | |
| 38 // Check whether the extension has requirement errors. | |
| 39 CHECK_REQUIREMENTS = 1 << 1, | |
| 40 // Check whether the extension can be installed and loaded, according to | |
| 41 // management policies. | |
| 42 CHECK_MANAGEMENT_POLICY = 1 << 2, | |
| 43 // Perform all checks. | |
| 44 CHECK_ALL = (1 << 3) - 1 | |
| 45 }; | |
| 46 | |
| 47 explicit ExtensionInstallChecker(Profile* profile); | |
| 48 virtual ~ExtensionInstallChecker(); | |
| 49 | |
| 50 // Start a set of checks. |enabled_checks| is a bitmask of CheckTypes to run. | |
| 51 // If |fail_fast| is true, the callback will be invoked once any check fails. | |
| 52 // Otherwise it will be invoked when all checks have completed. |callback| | |
| 53 // will only be called once. | |
| 54 // This function must be called on the UI thread. The callback also occurs on | |
| 55 // the UI thread. Checks may run asynchronously in parallel. | |
| 56 // If checks are currently running, the caller must wait for the callback to | |
| 57 // be invoked before starting another set of checks. | |
| 58 void Start(int enabled_checks, bool fail_fast, const Callback& callback); | |
| 59 | |
| 60 Profile* profile() const { return profile_; } | |
| 61 | |
| 62 scoped_refptr<const Extension> extension() { return extension_; } | |
| 63 void set_extension(const Extension* extension) { extension_ = extension; } | |
| 64 | |
| 65 // Returns true if any checks are currently running. | |
| 66 bool is_running() const { return running_checks_ != 0; } | |
| 67 | |
| 68 // Returns the requirement violations. A non-empty list is considered to be | |
| 69 // a check failure. | |
| 70 const std::vector<std::string>& requirement_errors() const { | |
| 71 return requirement_errors_; | |
| 72 } | |
| 73 | |
| 74 // Returns the blacklist state of the extension. A blacklist state of | |
| 75 // BLACKLISTED_MALWARE is considered to be a check failure. | |
| 76 BlacklistState blacklist_state() const { return blacklist_state_; } | |
| 77 | |
| 78 // Returns whether management policy permits installation of the extension. | |
| 79 bool policy_allows_load() const { return policy_allows_load_; } | |
| 80 const std::string& policy_error() const { return policy_error_; } | |
| 81 | |
| 82 protected: | |
| 83 virtual void CheckManagementPolicy(); | |
| 84 void OnManagementPolicyCheckDone(bool allows_load, const std::string& error); | |
| 85 | |
| 86 virtual void CheckRequirements(); | |
| 87 void OnRequirementsCheckDone(std::vector<std::string> errors); | |
| 88 | |
| 89 virtual void CheckBlacklistState(); | |
| 90 void OnBlacklistStateCheckDone(BlacklistState state); | |
| 91 | |
| 92 virtual void ResetResults(); | |
| 93 | |
| 94 private: | |
| 95 void MaybeInvokeCallback(); | |
| 96 | |
| 97 scoped_ptr<RequirementsChecker> requirements_checker_; | |
| 98 | |
| 99 // The Profile where the extension is being installed in. | |
| 100 Profile* profile_; | |
| 101 | |
| 102 // The extension to run checks for. | |
| 103 scoped_refptr<const Extension> extension_; | |
| 104 | |
| 105 // Requirement violations. | |
| 106 std::vector<std::string> requirement_errors_; | |
| 107 | |
| 108 // Result of the blacklist state check. | |
| 109 BlacklistState blacklist_state_; | |
| 110 | |
| 111 // Whether the extension can be installed, according to management policies. | |
| 112 bool policy_allows_load_; | |
| 113 std::string policy_error_; | |
| 114 | |
| 115 // Bitmask of currently running checks. | |
| 116 int running_checks_; | |
| 117 | |
| 118 // If true, the callback is invoked when the first check fails. | |
| 119 bool fail_fast_; | |
| 120 | |
| 121 // The callback to invoke when checks are complete. | |
| 122 Callback callback_; | |
| 123 | |
| 124 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); | |
| 127 }; | |
| 128 | |
| 129 } // namespace extensions | |
| 130 | |
| 131 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ | |
| OLD | NEW |