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

Side by Side Diff: components/browser_context_keyed_service/browser_context_dependency_manager.cc

Issue 15517005: Remove references to Profile from browser_context_keyed_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase & style Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 5 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <iterator> 9 #include <iterator>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa ctory.h" 12 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa ctory.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 14
15 #ifndef NDEBUG 15 #ifndef NDEBUG
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #endif 19 #endif
20 20
21 class Profile; 21 void BrowserContextDependencyManager::AddComponent(
22 22 BrowserContextKeyedBaseFactory* component) {
23 void ProfileDependencyManager::AddComponent(
24 ProfileKeyedBaseFactory* component) {
25 dependency_graph_.AddNode(component); 23 dependency_graph_.AddNode(component);
26 } 24 }
27 25
28 void ProfileDependencyManager::RemoveComponent( 26 void BrowserContextDependencyManager::RemoveComponent(
29 ProfileKeyedBaseFactory* component) { 27 BrowserContextKeyedBaseFactory* component) {
30 dependency_graph_.RemoveNode(component); 28 dependency_graph_.RemoveNode(component);
31 } 29 }
32 30
33 void ProfileDependencyManager::AddEdge(ProfileKeyedBaseFactory* depended, 31 void BrowserContextDependencyManager::AddEdge(
34 ProfileKeyedBaseFactory* dependee) { 32 BrowserContextKeyedBaseFactory* depended,
33 BrowserContextKeyedBaseFactory* dependee) {
35 dependency_graph_.AddEdge(depended, dependee); 34 dependency_graph_.AddEdge(depended, dependee);
36 } 35 }
37 36
38 void ProfileDependencyManager::CreateProfileServices( 37 void BrowserContextDependencyManager::CreateBrowserContextServices(
39 content::BrowserContext* profile, bool is_testing_profile) { 38 content::BrowserContext* context, bool is_testing_context) {
40 #ifndef NDEBUG 39 #ifndef NDEBUG
41 // Unmark |profile| as dead. This exists because of unit tests, which will 40 // Unmark |context| as dead. This exists because of unit tests, which will
42 // often have similar stack structures. 0xWhatever might be created, go out 41 // often have similar stack structures. 0xWhatever might be created, go out
43 // of scope, and then a new Profile object might be created at 0xWhatever. 42 // of scope, and then a new BrowserContext object might be created
44 dead_profile_pointers_.erase(profile); 43 // at 0xWhatever.
44 dead_context_pointers_.erase(context);
45 #endif 45 #endif
46 46
47 std::vector<DependencyNode*> construction_order; 47 std::vector<DependencyNode*> construction_order;
48 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { 48 if (!dependency_graph_.GetConstructionOrder(&construction_order)) {
49 NOTREACHED(); 49 NOTREACHED();
50 } 50 }
51 51
52 #ifndef NDEBUG 52 #ifndef NDEBUG
53 DumpProfileDependencies(profile); 53 DumpBrowserContextDependencies(context);
54 #endif 54 #endif
55 55
56 for (size_t i = 0; i < construction_order.size(); i++) { 56 for (size_t i = 0; i < construction_order.size(); i++) {
57 ProfileKeyedBaseFactory* factory = 57 BrowserContextKeyedBaseFactory* factory =
58 static_cast<ProfileKeyedBaseFactory*>(construction_order[i]); 58 static_cast<BrowserContextKeyedBaseFactory*>(construction_order[i]);
59 59
60 if (!profile->IsOffTheRecord()) { 60 if (!context->IsOffTheRecord()) {
61 // We only register preferences on normal profiles because the incognito 61 // We only register preferences on normal contexts because the incognito
62 // profile shares the pref service with the normal one. 62 // context shares the pref service with the normal one.
63 factory->RegisterUserPrefsOnProfile(profile); 63 factory->RegisterUserPrefsOnBrowserContext(context);
64 } 64 }
65 65
66 if (is_testing_profile && factory->ServiceIsNULLWhileTesting()) { 66 if (is_testing_context && factory->ServiceIsNULLWhileTesting()) {
67 factory->SetEmptyTestingFactory(profile); 67 factory->SetEmptyTestingFactory(context);
68 } else if (factory->ServiceIsCreatedWithProfile()) { 68 } else if (factory->ServiceIsCreatedWithBrowserContext()) {
69 // Create the service. 69 // Create the service.
70 factory->CreateServiceNow(profile); 70 factory->CreateServiceNow(context);
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 void ProfileDependencyManager::DestroyProfileServices( 75 void BrowserContextDependencyManager::DestroyBrowserContextServices(
76 content::BrowserContext* profile) { 76 content::BrowserContext* context) {
77 std::vector<DependencyNode*> destruction_order; 77 std::vector<DependencyNode*> destruction_order;
78 if (!dependency_graph_.GetDestructionOrder(&destruction_order)) { 78 if (!dependency_graph_.GetDestructionOrder(&destruction_order)) {
79 NOTREACHED(); 79 NOTREACHED();
80 } 80 }
81 81
82 #ifndef NDEBUG 82 #ifndef NDEBUG
83 DumpProfileDependencies(profile); 83 DumpBrowserContextDependencies(context);
84 #endif 84 #endif
85 85
86 for (size_t i = 0; i < destruction_order.size(); i++) { 86 for (size_t i = 0; i < destruction_order.size(); i++) {
87 ProfileKeyedBaseFactory* factory = 87 BrowserContextKeyedBaseFactory* factory =
88 static_cast<ProfileKeyedBaseFactory*>(destruction_order[i]); 88 static_cast<BrowserContextKeyedBaseFactory*>(destruction_order[i]);
89 factory->ProfileShutdown(profile); 89 factory->BrowserContextShutdown(context);
90 } 90 }
91 91
92 #ifndef NDEBUG 92 #ifndef NDEBUG
93 // The profile is now dead to the rest of the program. 93 // The context is now dead to the rest of the program.
94 dead_profile_pointers_.insert(profile); 94 dead_context_pointers_.insert(context);
95 #endif 95 #endif
96 96
97 for (size_t i = 0; i < destruction_order.size(); i++) { 97 for (size_t i = 0; i < destruction_order.size(); i++) {
98 ProfileKeyedBaseFactory* factory = 98 BrowserContextKeyedBaseFactory* factory =
99 static_cast<ProfileKeyedBaseFactory*>(destruction_order[i]); 99 static_cast<BrowserContextKeyedBaseFactory*>(destruction_order[i]);
100 factory->ProfileDestroyed(profile); 100 factory->BrowserContextDestroyed(context);
101 } 101 }
102 } 102 }
103 103
104 #ifndef NDEBUG 104 #ifndef NDEBUG
105 void ProfileDependencyManager::AssertProfileWasntDestroyed( 105 void BrowserContextDependencyManager::AssertBrowserContextWasntDestroyed(
106 content::BrowserContext* profile) { 106 content::BrowserContext* context) {
107 if (dead_profile_pointers_.find(profile) != dead_profile_pointers_.end()) { 107 if (dead_context_pointers_.find(context) != dead_context_pointers_.end()) {
108 NOTREACHED() << "Attempted to access a Profile that was ShutDown(). This " 108 NOTREACHED() << "Attempted to access a BrowserContext that was ShutDown(). "
109 << "is most likely a heap smasher in progress. After " 109 << "This is most likely a heap smasher in progress. After "
110 << "ProfileKeyedService::Shutdown() completes, your service " 110 << "BrowserContextKeyedService::Shutdown() completes, your "
111 << "MUST NOT refer to depended Profile services again."; 111 << "service MUST NOT refer to depended BrowserContext "
112 << "services again.";
112 } 113 }
113 } 114 }
114 #endif 115 #endif
115 116
116 // static 117 // static
117 ProfileDependencyManager* ProfileDependencyManager::GetInstance() { 118 BrowserContextDependencyManager*
118 return Singleton<ProfileDependencyManager>::get(); 119 BrowserContextDependencyManager::GetInstance() {
120 return Singleton<BrowserContextDependencyManager>::get();
119 } 121 }
120 122
121 ProfileDependencyManager::ProfileDependencyManager() { 123 BrowserContextDependencyManager::BrowserContextDependencyManager() {
122 } 124 }
123 125
124 ProfileDependencyManager::~ProfileDependencyManager() { 126 BrowserContextDependencyManager::~BrowserContextDependencyManager() {
125 } 127 }
126 128
127 #ifndef NDEBUG 129 #ifndef NDEBUG
128 namespace { 130 namespace {
129 131
130 std::string ProfileKeyedBaseFactoryGetNodeName(DependencyNode* node) { 132 std::string BrowserContextKeyedBaseFactoryGetNodeName(DependencyNode* node) {
131 return static_cast<ProfileKeyedBaseFactory*>(node)->name(); 133 return static_cast<BrowserContextKeyedBaseFactory*>(node)->name();
132 } 134 }
133 135
134 } // namespace 136 } // namespace
135 137
136 void ProfileDependencyManager::DumpProfileDependencies( 138 void BrowserContextDependencyManager::DumpBrowserContextDependencies(
137 content::BrowserContext* profile) { 139 content::BrowserContext* context) {
138 // Whenever we try to build a destruction ordering, we should also dump a 140 // Whenever we try to build a destruction ordering, we should also dump a
139 // dependency graph to "/path/to/profile/profile-dependencies.dot". 141 // dependency graph to "/path/to/context/context-dependencies.dot".
140 if (CommandLine::ForCurrentProcess()->HasSwitch( 142 if (CommandLine::ForCurrentProcess()->HasSwitch(
141 switches::kDumpBrowserContextDependencyGraph)) { 143 switches::kDumpBrowserContextDependencyGraph)) {
142 base::FilePath dot_file = 144 base::FilePath dot_file =
143 profile->GetPath().AppendASCII("browser-context-dependencies.dot"); 145 context->GetPath().AppendASCII("browser-context-dependencies.dot");
144 std::string contents = dependency_graph_.DumpAsGraphviz( 146 std::string contents = dependency_graph_.DumpAsGraphviz(
145 "Profile", base::Bind(&ProfileKeyedBaseFactoryGetNodeName)); 147 "BrowserContext",
148 base::Bind(&BrowserContextKeyedBaseFactoryGetNodeName));
146 file_util::WriteFile(dot_file, contents.c_str(), contents.size()); 149 file_util::WriteFile(dot_file, contents.c_str(), contents.size());
147 } 150 }
148 } 151 }
149 #endif // NDEBUG 152 #endif // NDEBUG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698