| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" | 13 #include "components/browser_context_keyed_service/browser_context_keyed_base_fa
ctory.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 | 15 |
| 16 #ifndef NDEBUG | 16 #ifndef NDEBUG |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "content/public/common/content_switches.h" | 19 |
| 20 #endif | 20 // Dumps dependency information about our browser context keyed services |
| 21 // into a dot file in the browser context directory. |
| 22 const char kDumpBrowserContextDependencyGraphFlag[] = |
| 23 "dump-browser-context-graph"; |
| 24 #endif // NDEBUG |
| 21 | 25 |
| 22 void BrowserContextDependencyManager::AddComponent( | 26 void BrowserContextDependencyManager::AddComponent( |
| 23 BrowserContextKeyedBaseFactory* component) { | 27 BrowserContextKeyedBaseFactory* component) { |
| 24 dependency_graph_.AddNode(component); | 28 dependency_graph_.AddNode(component); |
| 25 } | 29 } |
| 26 | 30 |
| 27 void BrowserContextDependencyManager::RemoveComponent( | 31 void BrowserContextDependencyManager::RemoveComponent( |
| 28 BrowserContextKeyedBaseFactory* component) { | 32 BrowserContextKeyedBaseFactory* component) { |
| 29 dependency_graph_.RemoveNode(component); | 33 dependency_graph_.RemoveNode(component); |
| 30 } | 34 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return static_cast<BrowserContextKeyedBaseFactory*>(node)->name(); | 140 return static_cast<BrowserContextKeyedBaseFactory*>(node)->name(); |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace | 143 } // namespace |
| 140 | 144 |
| 141 void BrowserContextDependencyManager::DumpBrowserContextDependencies( | 145 void BrowserContextDependencyManager::DumpBrowserContextDependencies( |
| 142 content::BrowserContext* context) { | 146 content::BrowserContext* context) { |
| 143 // Whenever we try to build a destruction ordering, we should also dump a | 147 // Whenever we try to build a destruction ordering, we should also dump a |
| 144 // dependency graph to "/path/to/context/context-dependencies.dot". | 148 // dependency graph to "/path/to/context/context-dependencies.dot". |
| 145 if (CommandLine::ForCurrentProcess()->HasSwitch( | 149 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 146 switches::kDumpBrowserContextDependencyGraph)) { | 150 kDumpBrowserContextDependencyGraphFlag)) { |
| 147 base::FilePath dot_file = | 151 base::FilePath dot_file = |
| 148 context->GetPath().AppendASCII("browser-context-dependencies.dot"); | 152 context->GetPath().AppendASCII("browser-context-dependencies.dot"); |
| 149 std::string contents = dependency_graph_.DumpAsGraphviz( | 153 std::string contents = dependency_graph_.DumpAsGraphviz( |
| 150 "BrowserContext", | 154 "BrowserContext", |
| 151 base::Bind(&BrowserContextKeyedBaseFactoryGetNodeName)); | 155 base::Bind(&BrowserContextKeyedBaseFactoryGetNodeName)); |
| 152 file_util::WriteFile(dot_file, contents.c_str(), contents.size()); | 156 file_util::WriteFile(dot_file, contents.c_str(), contents.size()); |
| 153 } | 157 } |
| 154 } | 158 } |
| 155 #endif // NDEBUG | 159 #endif // NDEBUG |
| OLD | NEW |