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

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

Issue 2751013002: 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>
(...skipping 24 matching lines...) Expand all
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 explicit ExtensionInstallChecker(Profile* profile); 45 explicit ExtensionInstallChecker(Profile* profile,
Devlin 2017/03/16 19:29:40 This no longer needs explicit.
michaelpg 2017/03/17 04:25:23 Made PG-rated.
46 scoped_refptr<const Extension> extension);
46 virtual ~ExtensionInstallChecker(); 47 virtual ~ExtensionInstallChecker();
47 48
48 // Start a set of checks. |enabled_checks| is a bitmask of CheckTypes to run. 49 // Start the set of checks. |enabled_checks| is a bitmask of CheckTypes to
Devlin 2017/03/16 19:29:41 nit: since we're updating this anyway, function co
michaelpg 2017/03/17 04:25:23 Done.
49 // If |fail_fast| is true, the callback will be invoked once any check fails. 50 // run. If |fail_fast| is true, the callback will be invoked once any check
50 // Otherwise it will be invoked when all checks have completed. |callback| 51 // fails. Otherwise it will be invoked when all checks have completed.
51 // will only be called once. 52 // |callback| will only be called once.
52 // 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
53 // the UI thread. Checks may run asynchronously in parallel. 54 // the UI thread. Checks may run asynchronously in parallel.
54 // If checks are currently running, the caller must wait for the callback to 55 // This function should be invoked at most once.
Devlin 2017/03/16 19:29:40 Let's also put something about single use in the c
michaelpg 2017/03/17 04:25:23 Done.
55 // be invoked before starting another set of checks.
56 void Start(int enabled_checks, bool fail_fast, const Callback& callback); 56 void Start(int enabled_checks, bool fail_fast, const Callback& callback);
57 57
58 Profile* profile() const { return profile_; } 58 Profile* profile() const { return profile_; }
59 59
60 const scoped_refptr<const Extension>& extension() { return extension_; } 60 const scoped_refptr<const Extension>& extension() { return extension_; }
61 void set_extension(const scoped_refptr<const Extension>& extension) {
62 extension_ = extension;
63 }
64 61
65 // Returns true if any checks are currently running. 62 // Returns true if any checks are currently running.
66 bool is_running() const { return running_checks_ != 0; } 63 bool is_running() const { return running_checks_ != 0; }
67 64
68 // 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
69 // a check failure. 66 // a check failure.
70 const std::vector<std::string>& requirement_errors() const { 67 const std::vector<std::string>& requirement_errors() const {
71 return requirement_errors_; 68 return requirement_errors_;
72 } 69 }
73 70
74 // Returns the blacklist state of the extension. A blacklist state of 71 // Returns the blacklist state of the extension. A blacklist state of
75 // BLACKLISTED_MALWARE is considered to be a check failure. 72 // BLACKLISTED_MALWARE is considered to be a check failure.
76 BlacklistState blacklist_state() const { return blacklist_state_; } 73 BlacklistState blacklist_state() const { return blacklist_state_; }
77 74
78 // Returns whether management policy permits installation of the extension. 75 // Returns whether management policy permits installation of the extension.
79 bool policy_allows_load() const { return policy_allows_load_; } 76 bool policy_allows_load() const { return policy_allows_load_; }
80 const std::string& policy_error() const { return policy_error_; } 77 const std::string& policy_error() const { return policy_error_; }
81 78
82 protected: 79 protected:
83 virtual void CheckManagementPolicy(); 80 virtual void CheckManagementPolicy();
84 void OnManagementPolicyCheckDone(bool allows_load, const std::string& error); 81 void OnManagementPolicyCheckDone(bool allows_load, const std::string& error);
85 82
86 virtual void CheckRequirements(); 83 virtual void CheckRequirements();
87 void OnRequirementsCheckDone(int sequence_number, 84 void OnRequirementsCheckDone(const std::vector<std::string>& errors);
88 const std::vector<std::string>& errors);
89 85
90 virtual void CheckBlacklistState(); 86 virtual void CheckBlacklistState();
91 void OnBlacklistStateCheckDone(int sequence_number, BlacklistState state); 87 void OnBlacklistStateCheckDone(BlacklistState state);
92
93 virtual void ResetResults();
94 int current_sequence_number() const { return current_sequence_number_; }
95 88
96 private: 89 private:
97 void MaybeInvokeCallback(); 90 void MaybeInvokeCallback();
98 91
99 std::unique_ptr<RequirementsChecker> requirements_checker_; 92 std::unique_ptr<RequirementsChecker> requirements_checker_;
100 93
101 // The Profile where the extension is being installed in. 94 // The Profile where the extension is being installed in.
102 Profile* profile_; 95 Profile* profile_;
103 96
104 // The extension to run checks for. 97 // The extension to run checks for.
105 scoped_refptr<const Extension> extension_; 98 scoped_refptr<const Extension> extension_;
106 99
107 // Requirement violations. 100 // Requirement violations.
108 std::vector<std::string> requirement_errors_; 101 std::vector<std::string> requirement_errors_;
109 102
110 // Result of the blacklist state check. 103 // Result of the blacklist state check.
111 BlacklistState blacklist_state_; 104 BlacklistState blacklist_state_;
112 105
113 // Whether the extension can be installed, according to management policies. 106 // Whether the extension can be installed, according to management policies.
114 bool policy_allows_load_; 107 bool policy_allows_load_;
115 std::string policy_error_; 108 std::string policy_error_;
116 109
117 // The sequence number of the currently running checks. 110 // Bitmask of enabled checks.
118 int current_sequence_number_; 111 int enabled_checks_;
119 112
120 // Bitmask of currently running checks. 113 // Bitmask of currently running checks.
121 int running_checks_; 114 int running_checks_;
122 115
123 // If true, the callback is invoked when the first check fails. 116 // If true, the callback is invoked when the first check fails.
124 bool fail_fast_; 117 bool fail_fast_;
125 118
126 // The callback to invoke when checks are complete. 119 // The callback to invoke when checks are complete.
127 Callback callback_; 120 Callback callback_;
128 121
129 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; 122 base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_;
130 123
131 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); 124 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker);
132 }; 125 };
133 126
134 } // namespace extensions 127 } // namespace extensions
135 128
136 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ 129 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698