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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 7 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 linked_ptr<extensions::RulesRegistry::Rule> rule( 53 linked_ptr<extensions::RulesRegistry::Rule> rule(
54 new extensions::RulesRegistry::Rule()); 54 new extensions::RulesRegistry::Rule());
55 if (extensions::RulesRegistry::Rule::Populate(*dict, rule.get())) 55 if (extensions::RulesRegistry::Rule::Populate(*dict, rule.get()))
56 rules.push_back(rule); 56 rules.push_back(rule);
57 } 57 }
58 58
59 return rules; 59 return rules;
60 } 60 }
61 61
62 // Returns the key to use for storing declarative rules in the state store. 62 // Returns the key to use for storing declarative rules in the state store.
63 std::string GetDeclarativeRuleStorageKey(const std::string& event_name, 63 std::string GetDeclarativeRuleStorageKey(
64 bool incognito) { 64 const std::string& event_name,
65 if (incognito) 65 bool incognito,
66 return "declarative_rules.incognito." + event_name; 66 const extensions::RulesRegistry::WebViewKey& webview_key) {
67 else 67 return base::StringPrintf("declarative_rules%s.%s.%d.%d",
68 return "declarative_rules." + event_name; 68 incognito ? ".incognito" : "",
69 event_name.c_str(), webview_key.first, webview_key.second);
vabr (Chromium) 2013/10/25 20:40:24 Is this stable across browser restarts? As far as
Fady Samuel 2013/10/25 22:48:08 I was hoping to chat with someone about these chan
69 } 70 }
70 71
71 } // namespace 72 } // namespace
72 73
73 74
74 namespace extensions { 75 namespace extensions {
75 76
76 // RulesRegistryWithCache 77 // RulesRegistryWithCache
77 78
78 RulesRegistryWithCache::RulesRegistryWithCache( 79 RulesRegistryWithCache::RulesRegistryWithCache(
79 Profile* profile, 80 Profile* profile,
80 const std::string& event_name, 81 const std::string& event_name,
81 content::BrowserThread::ID owner_thread, 82 content::BrowserThread::ID owner_thread,
82 bool log_storage_init_delay, 83 bool log_storage_init_delay,
83 scoped_ptr<RuleStorageOnUI>* ui_part) 84 scoped_ptr<RuleStorageOnUI>* ui_part,
84 : RulesRegistry(owner_thread, event_name), 85 const WebViewKey& webview_key)
86 : RulesRegistry(owner_thread, event_name, webview_key),
85 weak_ptr_factory_(profile ? this : NULL), 87 weak_ptr_factory_(profile ? this : NULL),
86 storage_on_ui_( 88 storage_on_ui_(
87 (profile ? (new RuleStorageOnUI(profile, 89 (profile ? (new RuleStorageOnUI(profile,
88 event_name, 90 event_name,
89 owner_thread, 91 owner_thread,
90 weak_ptr_factory_.GetWeakPtr(), 92 weak_ptr_factory_.GetWeakPtr(),
91 log_storage_init_delay))->GetWeakPtr() 93 log_storage_init_delay,
94 webview_key))->GetWeakPtr()
92 : base::WeakPtr<RuleStorageOnUI>())), 95 : base::WeakPtr<RuleStorageOnUI>())),
93 process_changed_rules_requested_(profile ? NOT_SCHEDULED_FOR_PROCESSING 96 process_changed_rules_requested_(profile ? NOT_SCHEDULED_FOR_PROCESSING
94 : NEVER_PROCESS) { 97 : NEVER_PROCESS) {
95 if (!profile) { 98 if (!profile) {
96 CHECK(!ui_part); 99 CHECK(!ui_part);
97 return; 100 return;
98 } 101 }
99 102
100 ui_part->reset(storage_on_ui_.get()); 103 ui_part->reset(storage_on_ui_.get());
101 104
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // RulesRegistryWithCache::RuleStorageOnUI 272 // RulesRegistryWithCache::RuleStorageOnUI
270 273
271 const char RulesRegistryWithCache::RuleStorageOnUI::kRulesStoredKey[] = 274 const char RulesRegistryWithCache::RuleStorageOnUI::kRulesStoredKey[] =
272 "has_declarative_rules"; 275 "has_declarative_rules";
273 276
274 RulesRegistryWithCache::RuleStorageOnUI::RuleStorageOnUI( 277 RulesRegistryWithCache::RuleStorageOnUI::RuleStorageOnUI(
275 Profile* profile, 278 Profile* profile,
276 const std::string& event_name, 279 const std::string& event_name,
277 content::BrowserThread::ID rules_registry_thread, 280 content::BrowserThread::ID rules_registry_thread,
278 base::WeakPtr<RulesRegistryWithCache> registry, 281 base::WeakPtr<RulesRegistryWithCache> registry,
279 bool log_storage_init_delay) 282 bool log_storage_init_delay,
283 const WebViewKey& webview_key)
280 : profile_(profile), 284 : profile_(profile),
281 storage_key_(GetDeclarativeRuleStorageKey(event_name, 285 storage_key_(GetDeclarativeRuleStorageKey(event_name,
282 profile->IsOffTheRecord())), 286 profile->IsOffTheRecord(),
287 webview_key)),
283 rules_stored_key_(GetRulesStoredKey(event_name, 288 rules_stored_key_(GetRulesStoredKey(event_name,
284 profile->IsOffTheRecord())), 289 profile->IsOffTheRecord(),
290 webview_key)),
285 log_storage_init_delay_(log_storage_init_delay), 291 log_storage_init_delay_(log_storage_init_delay),
286 registry_(registry), 292 registry_(registry),
287 rules_registry_thread_(rules_registry_thread), 293 rules_registry_thread_(rules_registry_thread),
288 notified_registry_(false), 294 notified_registry_(false),
289 weak_ptr_factory_(this) {} 295 weak_ptr_factory_(this) {}
290 296
291 RulesRegistryWithCache::RuleStorageOnUI::~RuleStorageOnUI() {} 297 RulesRegistryWithCache::RuleStorageOnUI::~RuleStorageOnUI() {}
292 298
293 // Returns the key to use for storing whether the rules have been stored. 299 // Returns the key to use for storing whether the rules have been stored.
294 // static 300 // static
295 std::string RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey( 301 std::string RulesRegistryWithCache::RuleStorageOnUI::GetRulesStoredKey(
296 const std::string& event_name, 302 const std::string& event_name,
297 bool incognito) { 303 bool incognito,
298 std::string result(kRulesStoredKey); 304 const WebViewKey& webview_key) {
299 result += incognito ? ".incognito." : "."; 305 return base::StringPrintf("%s.%s%s.%d.%d",
300 return result + event_name; 306 kRulesStoredKey, incognito ? "incognito." : "",
307 event_name.c_str(),
308 webview_key.first, webview_key.second);
301 } 309 }
302 310
303 // This is called from the constructor of RulesRegistryWithCache, so it is 311 // This is called from the constructor of RulesRegistryWithCache, so it is
304 // important that it both 312 // important that it both
305 // 1. calls no (in particular virtual) methods of the rules registry, and 313 // 1. calls no (in particular virtual) methods of the rules registry, and
306 // 2. does not create scoped_refptr holding the registry. (A short-lived 314 // 2. does not create scoped_refptr holding the registry. (A short-lived
307 // scoped_refptr might delete the rules registry before it is constructed.) 315 // scoped_refptr might delete the rules registry before it is constructed.)
308 void RulesRegistryWithCache::RuleStorageOnUI::Init() { 316 void RulesRegistryWithCache::RuleStorageOnUI::Init() {
309 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 317 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
310 318
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 bool rules_stored) { 483 bool rules_stored) {
476 CHECK(profile_); 484 CHECK(profile_);
477 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); 485 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
478 extension_prefs->UpdateExtensionPref( 486 extension_prefs->UpdateExtensionPref(
479 extension_id, 487 extension_id,
480 rules_stored_key_, 488 rules_stored_key_,
481 new base::FundamentalValue(rules_stored)); 489 new base::FundamentalValue(rules_stored));
482 } 490 }
483 491
484 } // namespace extensions 492 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698