1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/keyed_service/content/browser_context_dependency_manager.h"
7 #include "base/debug/trace_event.h"
8 #include "base/memory/singleton.h"
9 #include "content/public/browser/browser_context.h"
12 #include "base/command_line.h"
13 #include "base/files/file_util.h"
15 // Dumps dependency information about our browser context keyed services
16 // into a dot file in the browser context directory.
17 const char kDumpBrowserContextDependencyGraphFlag
[] =
18 "dump-browser-context-graph";
21 void BrowserContextDependencyManager::RegisterProfilePrefsForServices(
22 const content::BrowserContext
* context
,
23 user_prefs::PrefRegistrySyncable
* pref_registry
) {
24 RegisterPrefsForServices(context
, pref_registry
);
27 void BrowserContextDependencyManager::CreateBrowserContextServices(
28 content::BrowserContext
* context
) {
29 DoCreateBrowserContextServices(context
, false);
32 void BrowserContextDependencyManager::CreateBrowserContextServicesForTest(
33 content::BrowserContext
* context
) {
34 DoCreateBrowserContextServices(context
, true);
37 void BrowserContextDependencyManager::DoCreateBrowserContextServices(
38 content::BrowserContext
* context
,
39 bool is_testing_context
) {
42 "BrowserContextDependencyManager::DoCreateBrowserContextServices")
43 will_create_browser_context_services_callbacks_
.Notify(context
);
44 DependencyManager::CreateContextServices(context
, is_testing_context
);
47 void BrowserContextDependencyManager::DestroyBrowserContextServices(
48 content::BrowserContext
* context
) {
49 DependencyManager::DestroyContextServices(context
);
52 scoped_ptr
<base::CallbackList
<void(content::BrowserContext
*)>::Subscription
>
53 BrowserContextDependencyManager::
54 RegisterWillCreateBrowserContextServicesCallbackForTesting(
55 const base::Callback
<void(content::BrowserContext
*)>& callback
) {
56 return will_create_browser_context_services_callbacks_
.Add(callback
);
60 void BrowserContextDependencyManager::AssertBrowserContextWasntDestroyed(
61 content::BrowserContext
* context
) {
62 DependencyManager::AssertContextWasntDestroyed(context
);
65 void BrowserContextDependencyManager::MarkBrowserContextLiveForTesting(
66 content::BrowserContext
* context
) {
67 DependencyManager::MarkContextLiveForTesting(context
);
72 BrowserContextDependencyManager
*
73 BrowserContextDependencyManager::GetInstance() {
74 return Singleton
<BrowserContextDependencyManager
>::get();
77 BrowserContextDependencyManager::BrowserContextDependencyManager() {}
79 BrowserContextDependencyManager::~BrowserContextDependencyManager() {}
82 void BrowserContextDependencyManager::DumpContextDependencies(
83 const base::SupportsUserData
* context
) const {
84 // Whenever we try to build a destruction ordering, we should also dump a
85 // dependency graph to "/path/to/context/context-dependencies.dot".
86 if (CommandLine::ForCurrentProcess()->HasSwitch(
87 kDumpBrowserContextDependencyGraphFlag
)) {
88 base::FilePath dot_file
=
89 static_cast<const content::BrowserContext
*>(context
)
91 .AppendASCII("browser-context-dependencies.dot");
92 DumpDependenciesAsGraphviz("BrowserContext", dot_file
);