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

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

Issue 53273002: Decouple RulesCacheDelegate from RulesRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_rules_registry_with_cache
Patch Set: Merge with ToT 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_service.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 27 matching lines...) Expand all
38 if (profile) { 38 if (profile) {
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
40 content::Source<Profile>(profile->GetOriginalProfile())); 40 content::Source<Profile>(profile->GetOriginalProfile()));
41 RegisterDefaultRulesRegistries(); 41 RegisterDefaultRulesRegistries();
42 } 42 }
43 } 43 }
44 44
45 RulesRegistryService::~RulesRegistryService() {} 45 RulesRegistryService::~RulesRegistryService() {}
46 46
47 void RulesRegistryService::RegisterDefaultRulesRegistries() { 47 void RulesRegistryService::RegisterDefaultRulesRegistries() {
48 scoped_ptr<RulesCacheDelegate> ui_part;
49 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 48 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
50 new WebRequestRulesRegistry(profile_, &ui_part)); 49 new WebRequestRulesRegistry(profile_));
51 ui_parts_of_registries_.push_back(ui_part.release()); 50
51 scoped_ptr<RulesCacheDelegate> web_request_cache_delegate(
52 new RulesCacheDelegate(web_request_rules_registry->GetWeakPtr(),
53 true /*log_storage_init_delay*/));
54 web_request_rules_registry->SetCacheDelegate(
55 web_request_cache_delegate->GetWeakPtr());
56 cache_delegates_.push_back(web_request_cache_delegate.release());
52 57
53 RegisterRulesRegistry(web_request_rules_registry); 58 RegisterRulesRegistry(web_request_rules_registry);
54 content::BrowserThread::PostTask( 59 content::BrowserThread::PostTask(
55 content::BrowserThread::IO, FROM_HERE, 60 content::BrowserThread::IO, FROM_HERE,
56 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 61 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
57 profile_, web_request_rules_registry)); 62 profile_, web_request_rules_registry));
58 63
59 #if defined(ENABLE_EXTENSIONS) 64 #if defined(ENABLE_EXTENSIONS)
60 scoped_refptr<ContentRulesRegistry> content_rules_registry( 65 scoped_refptr<ContentRulesRegistry> content_rules_registry(
61 new ContentRulesRegistry(profile_, &ui_part)); 66 new ContentRulesRegistry(profile_));
62 ui_parts_of_registries_.push_back(ui_part.release()); 67
68 scoped_ptr<RulesCacheDelegate> content_rules_cache_delegate(
69 new RulesCacheDelegate(content_rules_registry->GetWeakPtr(),
70 false /*log_storage_init_delay*/));
71 content_rules_registry->SetCacheDelegate(
72 content_rules_cache_delegate->GetWeakPtr());
73 cache_delegates_.push_back(content_rules_cache_delegate.release());
63 74
64 RegisterRulesRegistry(content_rules_registry); 75 RegisterRulesRegistry(content_rules_registry);
65 content_rules_registry_ = content_rules_registry.get(); 76 content_rules_registry_ = content_rules_registry.get();
66 #endif // defined(ENABLE_EXTENSIONS) 77 #endif // defined(ENABLE_EXTENSIONS)
67 } 78 }
68 79
69 void RulesRegistryService::Shutdown() { 80 void RulesRegistryService::Shutdown() {
70 // Release the references to all registries. This would happen soon during 81 // Release the references to all registries. This would happen soon during
71 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to 82 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to
72 // be the last to reference the WebRequestRulesRegistry objects, so that 83 // be the last to reference the WebRequestRulesRegistry objects, so that
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 OnExtensionUnloaded(extension->id()); 153 OnExtensionUnloaded(extension->id());
143 break; 154 break;
144 } 155 }
145 default: 156 default:
146 NOTREACHED(); 157 NOTREACHED();
147 break; 158 break;
148 } 159 }
149 } 160 }
150 161
151 } // namespace extensions 162 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698