Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/extensions/extension_install_checker.h

Issue 2769813004: Revert of Simplify ExtensionInstallChecker into a single-use class (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/blacklist_state.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 an extension. Extensions that violate these checks
26 // This class should be Start()-ed at most once. 26 // would be disabled or not even installed.
27 class ExtensionInstallChecker { 27 class ExtensionInstallChecker {
28 public: 28 public:
29 // Called when checks are complete. The returned value is a bitmask of 29 // Called when checks are complete. The returned value is a bitmask of
30 // failed checks. 30 // failed checks.
31 typedef base::Callback<void(int)> Callback; 31 typedef base::Callback<void(int)> Callback;
32 32
33 enum CheckType { 33 enum CheckType {
34 // Check the blacklist state of the extension. 34 // Check the blacklist state of the extension.
35 CHECK_BLACKLIST = 1 << 0, 35 CHECK_BLACKLIST = 1 << 0,
36 // Check whether the extension has requirement errors. 36 // Check whether the extension has requirement errors.
37 CHECK_REQUIREMENTS = 1 << 1, 37 CHECK_REQUIREMENTS = 1 << 1,
38 // Check whether the extension can be installed and loaded, according to 38 // Check whether the extension can be installed and loaded, according to
39 // management policies. 39 // management policies.
40 CHECK_MANAGEMENT_POLICY = 1 << 2, 40 CHECK_MANAGEMENT_POLICY = 1 << 2,
41 // Perform all checks. 41 // Perform all checks.
42 CHECK_ALL = (1 << 3) - 1 42 CHECK_ALL = (1 << 3) - 1
43 }; 43 };
44 44
45 // |enabled_checks| is a bitmask of CheckTypes to run. 45 explicit ExtensionInstallChecker(Profile* profile);
46 // If |fail_fast| is true, the callback to Start() will be invoked once any
47 // check fails. Otherwise it will be invoked when all checks have completed.
48 ExtensionInstallChecker(Profile* profile,
49 scoped_refptr<const Extension> extension,
50 int enabled_checks,
51 bool fail_fast);
52 virtual ~ExtensionInstallChecker(); 46 virtual ~ExtensionInstallChecker();
53 47
54 // Starts the set of checks. |callback| will only be called once. 48 // Start a set of checks. |enabled_checks| is a bitmask of CheckTypes to run.
49 // If |fail_fast| is true, the callback will be invoked once any check fails.
50 // Otherwise it will be invoked when all checks have completed. |callback|
51 // will only be called once.
55 // This function must be called on the UI thread. The callback also occurs on 52 // This function must be called on the UI thread. The callback also occurs on
56 // the UI thread. Checks may run asynchronously in parallel. 53 // the UI thread. Checks may run asynchronously in parallel.
57 // This function should be invoked at most once. 54 // If checks are currently running, the caller must wait for the callback to
58 void Start(const Callback& callback); 55 // be invoked before starting another set of checks.
56 void Start(int enabled_checks, bool fail_fast, const Callback& callback);
57
58 Profile* profile() const { return profile_; }
59
60 const scoped_refptr<const Extension>& extension() { return extension_; }
61 void set_extension(const scoped_refptr<const Extension>& extension) {
62 extension_ = extension;
63 }
59 64
60 // Returns true if any checks are currently running. 65 // Returns true if any checks are currently running.
61 bool is_running() const { return running_checks_ != 0; } 66 bool is_running() const { return running_checks_ != 0; }
62 67
63 // Returns the requirement violations. A non-empty list is considered to be 68 // Returns the requirement violations. A non-empty list is considered to be
64 // a check failure. 69 // a check failure.
65 const std::vector<std::string>& requirement_errors() const { 70 const std::vector<std::string>& requirement_errors() const {
66 return requirement_errors_; 71 return requirement_errors_;
67 } 72 }
68 73
69 // Returns the blacklist state of the extension. A blacklist state of 74 // Returns the blacklist state of the extension. A blacklist state of
70 // BLACKLISTED_MALWARE is considered to be a check failure. 75 // BLACKLISTED_MALWARE is considered to be a check failure.
71 BlacklistState blacklist_state() const { return blacklist_state_; } 76 BlacklistState blacklist_state() const { return blacklist_state_; }
72 77
73 // Returns whether management policy permits installation of the extension. 78 // Returns whether management policy permits installation of the extension.
74 bool policy_allows_load() const { return policy_allows_load_; } 79 bool policy_allows_load() const { return policy_allows_load_; }
75 const std::string& policy_error() const { return policy_error_; } 80 const std::string& policy_error() const { return policy_error_; }
76 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(bool allows_load, const std::string& error);
80 85
81 virtual void CheckRequirements(); 86 virtual void CheckRequirements();
82 void OnRequirementsCheckDone(const std::vector<std::string>& errors); 87 void OnRequirementsCheckDone(int sequence_number,
88 const std::vector<std::string>& errors);
83 89
84 virtual void CheckBlacklistState(); 90 virtual void CheckBlacklistState();
85 void OnBlacklistStateCheckDone(BlacklistState state); 91 void OnBlacklistStateCheckDone(int sequence_number, BlacklistState state);
92
93 virtual void ResetResults();
94 int current_sequence_number() const { return current_sequence_number_; }
86 95
87 private: 96 private:
88 void MaybeInvokeCallback(); 97 void MaybeInvokeCallback();
89 98
90 std::unique_ptr<RequirementsChecker> requirements_checker_; 99 std::unique_ptr<RequirementsChecker> requirements_checker_;
91 100
92 // The Profile where the extension is being installed in. 101 // The Profile where the extension is being installed in.
93 Profile* profile_; 102 Profile* profile_;
94 103
95 // The extension to run checks for. 104 // The extension to run checks for.
96 scoped_refptr<const Extension> extension_; 105 scoped_refptr<const Extension> extension_;
97 106
98 // Requirement violations. 107 // Requirement violations.
99 std::vector<std::string> requirement_errors_; 108 std::vector<std::string> requirement_errors_;
100 109
101 // Result of the blacklist state check. 110 // Result of the blacklist state check.
102 BlacklistState blacklist_state_; 111 BlacklistState blacklist_state_;
103 112
104 // Whether the extension can be installed, according to management policies. 113 // Whether the extension can be installed, according to management policies.
105 bool policy_allows_load_; 114 bool policy_allows_load_;
106 std::string policy_error_; 115 std::string policy_error_;
107 116
108 // Bitmask of enabled checks. 117 // The sequence number of the currently running checks.
109 int enabled_checks_; 118 int current_sequence_number_;
110 119
111 // Bitmask of currently running checks. 120 // Bitmask of currently running checks.
112 // TODO(michaelpg): Consolidate this with enabled_checks_.
113 int running_checks_; 121 int running_checks_;
114 122
115 // If true, the callback is invoked when the first check fails. 123 // If true, the callback is invoked when the first check fails.
116 bool fail_fast_; 124 bool fail_fast_;
117 125
118 // The callback to invoke when checks are complete. 126 // The callback to invoke when checks are complete.
119 Callback callback_; 127 Callback callback_;
120 128
121 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; 129 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_;
122 130
123 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); 131 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker);
124 }; 132 };
125 133
126 } // namespace extensions 134 } // namespace extensions
127 135
128 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ 136 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_install_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698