OLD | NEW |
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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 dependency_graph_.RemoveNode(component); | 33 dependency_graph_.RemoveNode(component); |
34 } | 34 } |
35 | 35 |
36 void BrowserContextDependencyManager::AddEdge( | 36 void BrowserContextDependencyManager::AddEdge( |
37 BrowserContextKeyedBaseFactory* depended, | 37 BrowserContextKeyedBaseFactory* depended, |
38 BrowserContextKeyedBaseFactory* dependee) { | 38 BrowserContextKeyedBaseFactory* dependee) { |
39 dependency_graph_.AddEdge(depended, dependee); | 39 dependency_graph_.AddEdge(depended, dependee); |
40 } | 40 } |
41 | 41 |
42 void BrowserContextDependencyManager::CreateBrowserContextServices( | 42 void BrowserContextDependencyManager::CreateBrowserContextServices( |
43 content::BrowserContext* context, bool is_testing_context) { | 43 content::BrowserContext* context) { |
| 44 DoCreateBrowserContextServices(context, false, false); |
| 45 } |
| 46 |
| 47 void BrowserContextDependencyManager::CreateBrowserContextServicesForTest( |
| 48 content::BrowserContext* context, |
| 49 bool force_register_prefs) { |
| 50 DoCreateBrowserContextServices(context, true, force_register_prefs); |
| 51 } |
| 52 |
| 53 void BrowserContextDependencyManager::DoCreateBrowserContextServices( |
| 54 content::BrowserContext* context, |
| 55 bool is_testing_context, |
| 56 bool force_register_prefs) { |
44 TRACE_EVENT0("browser", | 57 TRACE_EVENT0("browser", |
45 "BrowserContextDependencyManager::CreateBrowserContextServices") | 58 "BrowserContextDependencyManager::DoCreateBrowserContextServices") |
46 #ifndef NDEBUG | 59 #ifndef NDEBUG |
47 // Unmark |context| as dead. This exists because of unit tests, which will | 60 // Unmark |context| as dead. This exists because of unit tests, which will |
48 // often have similar stack structures. 0xWhatever might be created, go out | 61 // often have similar stack structures. 0xWhatever might be created, go out |
49 // of scope, and then a new BrowserContext object might be created | 62 // of scope, and then a new BrowserContext object might be created |
50 // at 0xWhatever. | 63 // at 0xWhatever. |
51 dead_context_pointers_.erase(context); | 64 dead_context_pointers_.erase(context); |
52 #endif | 65 #endif |
53 | 66 |
54 std::vector<DependencyNode*> construction_order; | 67 std::vector<DependencyNode*> construction_order; |
55 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { | 68 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { |
56 NOTREACHED(); | 69 NOTREACHED(); |
57 } | 70 } |
58 | 71 |
59 #ifndef NDEBUG | 72 #ifndef NDEBUG |
60 DumpBrowserContextDependencies(context); | 73 DumpBrowserContextDependencies(context); |
61 #endif | 74 #endif |
62 | 75 |
63 for (size_t i = 0; i < construction_order.size(); i++) { | 76 for (size_t i = 0; i < construction_order.size(); i++) { |
64 BrowserContextKeyedBaseFactory* factory = | 77 BrowserContextKeyedBaseFactory* factory = |
65 static_cast<BrowserContextKeyedBaseFactory*>(construction_order[i]); | 78 static_cast<BrowserContextKeyedBaseFactory*>(construction_order[i]); |
66 | 79 |
67 if (!context->IsOffTheRecord()) { | 80 if (!context->IsOffTheRecord() || force_register_prefs) { |
68 // We only register preferences on normal contexts because the incognito | 81 // We only register preferences on normal contexts because the incognito |
69 // context shares the pref service with the normal one. | 82 // context shares the pref service with the normal one. Always register |
| 83 // for standalone testing contexts (testing contexts that don't have an |
| 84 // "original" profile set) as otherwise the preferences won't be |
| 85 // registered. |
70 factory->RegisterUserPrefsOnBrowserContext(context); | 86 factory->RegisterUserPrefsOnBrowserContext(context); |
71 } | 87 } |
72 | 88 |
73 if (is_testing_context && factory->ServiceIsNULLWhileTesting()) { | 89 if (is_testing_context && factory->ServiceIsNULLWhileTesting()) { |
74 factory->SetEmptyTestingFactory(context); | 90 factory->SetEmptyTestingFactory(context); |
75 } else if (factory->ServiceIsCreatedWithBrowserContext()) { | 91 } else if (factory->ServiceIsCreatedWithBrowserContext()) { |
76 // Create the service. | 92 // Create the service. |
77 factory->CreateServiceNow(context); | 93 factory->CreateServiceNow(context); |
78 } | 94 } |
79 } | 95 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 kDumpBrowserContextDependencyGraphFlag)) { | 166 kDumpBrowserContextDependencyGraphFlag)) { |
151 base::FilePath dot_file = | 167 base::FilePath dot_file = |
152 context->GetPath().AppendASCII("browser-context-dependencies.dot"); | 168 context->GetPath().AppendASCII("browser-context-dependencies.dot"); |
153 std::string contents = dependency_graph_.DumpAsGraphviz( | 169 std::string contents = dependency_graph_.DumpAsGraphviz( |
154 "BrowserContext", | 170 "BrowserContext", |
155 base::Bind(&BrowserContextKeyedBaseFactoryGetNodeName)); | 171 base::Bind(&BrowserContextKeyedBaseFactoryGetNodeName)); |
156 file_util::WriteFile(dot_file, contents.c_str(), contents.size()); | 172 file_util::WriteFile(dot_file, contents.c_str(), contents.size()); |
157 } | 173 } |
158 } | 174 } |
159 #endif // NDEBUG | 175 #endif // NDEBUG |
OLD | NEW |