OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ |
6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 163 |
164 // Insert new values before this line. | 164 // Insert new values before this line. |
165 MAX, | 165 MAX, |
166 }; | 166 }; |
167 | 167 |
168 // Creates a new instance that will immediately publish the most recently | 168 // Creates a new instance that will immediately publish the most recently |
169 // indexed version of the ruleset if one is available according to prefs. | 169 // indexed version of the ruleset if one is available according to prefs. |
170 // See class comments for details of arguments. | 170 // See class comments for details of arguments. |
171 RulesetService(PrefService* local_state, | 171 RulesetService(PrefService* local_state, |
172 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 172 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
173 std::unique_ptr<RulesetServiceDelegate> delegate, | 173 RulesetServiceDelegate* delegate, |
174 const base::FilePath& indexed_ruleset_base_dir); | 174 const base::FilePath& indexed_ruleset_base_dir); |
175 virtual ~RulesetService(); | 175 virtual ~RulesetService(); |
176 | 176 |
177 // Indexes, stores, and publishes the given unindexed ruleset, unless its | 177 // Indexes, stores, and publishes the given unindexed ruleset, unless its |
178 // |content_version| matches that of the most recently indexed version, in | 178 // |content_version| matches that of the most recently indexed version, in |
179 // which case it does nothing. The files comprising the unindexed ruleset | 179 // which case it does nothing. The files comprising the unindexed ruleset |
180 // need to remain accessible even after the method returns. | 180 // need to remain accessible even after the method returns. |
181 // | 181 // |
182 // Computation-heavy steps and I/O are performed on a background thread. | 182 // Computation-heavy steps and I/O are performed on a background thread. |
183 // Furthermore, to prevent start-up congestion, new rulesets provided via this | 183 // Furthermore, to prevent start-up congestion, new rulesets provided via this |
184 // method will not be processed until after start-up. | 184 // method will not be processed until after start-up. |
185 // | 185 // |
186 // Virtual so that it can be mocked out in tests. | 186 // Virtual so that it can be mocked out in tests. |
187 virtual void IndexAndStoreAndPublishRulesetIfNeeded( | 187 virtual void IndexAndStoreAndPublishRulesetIfNeeded( |
188 const UnindexedRulesetInfo& unindexed_ruleset_info); | 188 const UnindexedRulesetInfo& unindexed_ruleset_info); |
189 | 189 |
190 // Exposed for browser tests. | |
191 RulesetServiceDelegate* delegate() { return delegate_.get(); } | |
192 | |
193 private: | 190 private: |
194 friend class SubresourceFilteringRulesetServiceTest; | 191 friend class SubresourceFilteringRulesetServiceTest; |
195 FRIEND_TEST_ALL_PREFIXES(SubresourceFilteringRulesetServiceTest, | 192 FRIEND_TEST_ALL_PREFIXES(SubresourceFilteringRulesetServiceTest, |
196 NewRuleset_WriteFailure); | 193 NewRuleset_WriteFailure); |
197 FRIEND_TEST_ALL_PREFIXES(SubresourceFilteringRulesetServiceDeathTest, | 194 FRIEND_TEST_ALL_PREFIXES(SubresourceFilteringRulesetServiceDeathTest, |
198 NewRuleset_IndexingCrash); | 195 NewRuleset_IndexingCrash); |
199 | 196 |
200 using WriteRulesetCallback = | 197 using WriteRulesetCallback = |
201 base::Callback<void(const IndexedRulesetVersion&)>; | 198 base::Callback<void(const IndexedRulesetVersion&)>; |
202 | 199 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 const WriteRulesetCallback& success_callback); | 242 const WriteRulesetCallback& success_callback); |
246 | 243 |
247 void OnWrittenRuleset(const WriteRulesetCallback& result_callback, | 244 void OnWrittenRuleset(const WriteRulesetCallback& result_callback, |
248 const IndexedRulesetVersion& version); | 245 const IndexedRulesetVersion& version); |
249 | 246 |
250 void OpenAndPublishRuleset(const IndexedRulesetVersion& version); | 247 void OpenAndPublishRuleset(const IndexedRulesetVersion& version); |
251 void OnOpenedRuleset(base::File::Error error); | 248 void OnOpenedRuleset(base::File::Error error); |
252 | 249 |
253 PrefService* const local_state_; | 250 PrefService* const local_state_; |
254 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 251 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
255 std::unique_ptr<RulesetServiceDelegate> delegate_; | 252 |
253 // Must outlive this class. | |
pkalinnikov
2017/03/09 16:09:01
nit: Must outlive |this| object.
Charlie Harrison
2017/03/09 16:12:44
Done.
| |
254 RulesetServiceDelegate* delegate_; | |
256 | 255 |
257 UnindexedRulesetInfo queued_unindexed_ruleset_info_; | 256 UnindexedRulesetInfo queued_unindexed_ruleset_info_; |
258 bool is_after_startup_; | 257 bool is_after_startup_; |
259 | 258 |
260 const base::FilePath indexed_ruleset_base_dir_; | 259 const base::FilePath indexed_ruleset_base_dir_; |
261 std::unique_ptr<base::FileProxy> ruleset_data_; | 260 std::unique_ptr<base::FileProxy> ruleset_data_; |
262 | 261 |
263 DISALLOW_COPY_AND_ASSIGN(RulesetService); | 262 DISALLOW_COPY_AND_ASSIGN(RulesetService); |
264 }; | 263 }; |
265 | 264 |
266 } // namespace subresource_filter | 265 } // namespace subresource_filter |
267 | 266 |
268 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ | 267 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_RULESET_SERVICE_H_ |
OLD | NEW |