OLD | NEW |
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.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return base::StringPrintf("_%d_", identifier); | 66 return base::StringPrintf("_%d_", identifier); |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 | 71 |
72 namespace extensions { | 72 namespace extensions { |
73 | 73 |
74 // RulesRegistry | 74 // RulesRegistry |
75 | 75 |
76 RulesRegistry::RulesRegistry( | 76 RulesRegistry::RulesRegistry(Profile* profile, |
77 Profile* profile, | 77 const std::string& event_name, |
78 const std::string& event_name, | 78 content::BrowserThread::ID owner_thread, |
79 content::BrowserThread::ID owner_thread, | 79 RulesCacheDelegate* cache_delegate, |
80 RulesCacheDelegate* cache_delegate, | 80 const WebViewKey& webview_key) |
81 const WebViewKey& webview_key) | |
82 : profile_(profile), | 81 : profile_(profile), |
83 owner_thread_(owner_thread), | 82 owner_thread_(owner_thread), |
84 event_name_(event_name), | 83 event_name_(event_name), |
85 webview_key_(webview_key), | 84 webview_key_(webview_key), |
| 85 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache |
| 86 // delegate to wait for. |
86 weak_ptr_factory_(profile ? this : NULL), | 87 weak_ptr_factory_(profile ? this : NULL), |
87 last_generated_rule_identifier_id_(0) { | 88 last_generated_rule_identifier_id_(0) { |
88 if (cache_delegate) { | 89 if (cache_delegate) { |
89 cache_delegate_ = cache_delegate->GetWeakPtr(); | 90 cache_delegate_ = cache_delegate->GetWeakPtr(); |
90 cache_delegate->Init(this); | 91 cache_delegate->Init(this); |
91 } else { | |
92 content::BrowserThread::PostTask( | |
93 owner_thread, | |
94 FROM_HERE, | |
95 base::Bind(&RulesRegistry::MarkReady, this, base::Time::Now())); | |
96 } | 92 } |
97 } | 93 } |
98 | 94 |
99 std::string RulesRegistry::AddRulesNoFill( | 95 std::string RulesRegistry::AddRulesNoFill( |
100 const std::string& extension_id, | 96 const std::string& extension_id, |
101 const std::vector<linked_ptr<Rule> >& rules) { | 97 const std::vector<linked_ptr<Rule> >& rules) { |
102 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); | 98 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); |
103 | 99 |
104 // Verify that all rule IDs are new. | 100 // Verify that all rule IDs are new. |
105 for (std::vector<linked_ptr<Rule> >::const_iterator i = | 101 for (std::vector<linked_ptr<Rule> >::const_iterator i = |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 for (i = identifiers.begin(); i != identifiers.end(); ++i) | 372 for (i = identifiers.begin(); i != identifiers.end(); ++i) |
377 used_rule_identifiers_[extension_id].erase(*i); | 373 used_rule_identifiers_[extension_id].erase(*i); |
378 } | 374 } |
379 | 375 |
380 void RulesRegistry::RemoveAllUsedRuleIdentifiers( | 376 void RulesRegistry::RemoveAllUsedRuleIdentifiers( |
381 const std::string& extension_id) { | 377 const std::string& extension_id) { |
382 used_rule_identifiers_.erase(extension_id); | 378 used_rule_identifiers_.erase(extension_id); |
383 } | 379 } |
384 | 380 |
385 } // namespace extensions | 381 } // namespace extensions |
OLD | NEW |