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

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

Issue 535203003: Replace Profile* in declarative_api with BrowserContext* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove changes to unit-test; those have to wait until move. Created 6 years, 3 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 (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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" 18 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
25 #include "extensions/browser/extension_prefs.h" 24 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
27 #include "extensions/browser/state_store.h" 26 #include "extensions/browser/state_store.h"
28 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
29 28
30 namespace { 29 namespace {
31 30
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return base::StringPrintf("_%d_", identifier); 65 return base::StringPrintf("_%d_", identifier);
67 } 66 }
68 67
69 } // namespace 68 } // namespace
70 69
71 70
72 namespace extensions { 71 namespace extensions {
73 72
74 // RulesRegistry 73 // RulesRegistry
75 74
76 RulesRegistry::RulesRegistry(Profile* profile, 75 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context,
77 const std::string& event_name, 76 const std::string& event_name,
78 content::BrowserThread::ID owner_thread, 77 content::BrowserThread::ID owner_thread,
79 RulesCacheDelegate* cache_delegate, 78 RulesCacheDelegate* cache_delegate,
80 const WebViewKey& webview_key) 79 const WebViewKey& webview_key)
81 : profile_(profile), 80 : browser_context_(browser_context),
82 owner_thread_(owner_thread), 81 owner_thread_(owner_thread),
83 event_name_(event_name), 82 event_name_(event_name),
84 webview_key_(webview_key), 83 webview_key_(webview_key),
85 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache 84 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache
86 // delegate to wait for. 85 // delegate to wait for.
87 weak_ptr_factory_(profile ? this : NULL), 86 weak_ptr_factory_(browser_context_ ? this : NULL),
88 last_generated_rule_identifier_id_(0) { 87 last_generated_rule_identifier_id_(0) {
89 if (cache_delegate) { 88 if (cache_delegate) {
90 cache_delegate_ = cache_delegate->GetWeakPtr(); 89 cache_delegate_ = cache_delegate->GetWeakPtr();
91 cache_delegate->Init(this); 90 cache_delegate->Init(this);
92 } 91 }
93 } 92 }
94 93
95 std::string RulesRegistry::AddRulesNoFill( 94 std::string RulesRegistry::AddRulesNoFill(
96 const std::string& extension_id, 95 const std::string& extension_id,
97 const std::vector<linked_ptr<Rule> >& rules) { 96 const std::vector<linked_ptr<Rule> >& rules) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 base::Passed(RulesToValue(new_rules)))); 287 base::Passed(RulesToValue(new_rules))));
289 } 288 }
290 289
291 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { 290 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) {
292 // Read and initialize |process_changed_rules_requested_[extension_id]| if 291 // Read and initialize |process_changed_rules_requested_[extension_id]| if
293 // necessary. (Note that the insertion below will not overwrite 292 // necessary. (Note that the insertion below will not overwrite
294 // |process_changed_rules_requested_[extension_id]| if that already exists. 293 // |process_changed_rules_requested_[extension_id]| if that already exists.
295 std::pair<ProcessStateMap::iterator, bool> insertion = 294 std::pair<ProcessStateMap::iterator, bool> insertion =
296 process_changed_rules_requested_.insert(std::make_pair( 295 process_changed_rules_requested_.insert(std::make_pair(
297 extension_id, 296 extension_id,
298 profile_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS)); 297 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS));
299 if (insertion.first->second != NOT_SCHEDULED_FOR_PROCESSING) 298 if (insertion.first->second != NOT_SCHEDULED_FOR_PROCESSING)
300 return; 299 return;
301 300
302 process_changed_rules_requested_[extension_id] = SCHEDULED_FOR_PROCESSING; 301 process_changed_rules_requested_[extension_id] = SCHEDULED_FOR_PROCESSING;
303 ready_.Post(FROM_HERE, 302 ready_.Post(FROM_HERE,
304 base::Bind(&RulesRegistry::ProcessChangedRules, 303 base::Bind(&RulesRegistry::ProcessChangedRules,
305 weak_ptr_factory_.GetWeakPtr(), 304 weak_ptr_factory_.GetWeakPtr(),
306 extension_id)); 305 extension_id));
307 } 306 }
308 307
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 for (i = identifiers.begin(); i != identifiers.end(); ++i) 371 for (i = identifiers.begin(); i != identifiers.end(); ++i)
373 used_rule_identifiers_[extension_id].erase(*i); 372 used_rule_identifiers_[extension_id].erase(*i);
374 } 373 }
375 374
376 void RulesRegistry::RemoveAllUsedRuleIdentifiers( 375 void RulesRegistry::RemoveAllUsedRuleIdentifiers(
377 const std::string& extension_id) { 376 const std::string& extension_id) {
378 used_rule_identifiers_.erase(extension_id); 377 used_rule_identifiers_.erase(extension_id);
379 } 378 }
380 379
381 } // namespace extensions 380 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698