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/memory/singleton.h"
8 #include "base/trace_event/trace_event.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
) {
26 "BrowserContextDependencyManager::RegisterProfilePrefsForServices");
27 RegisterPrefsForServices(context
, pref_registry
);
30 void BrowserContextDependencyManager::CreateBrowserContextServices(
31 content::BrowserContext
* context
) {
32 DoCreateBrowserContextServices(context
, false);
35 void BrowserContextDependencyManager::CreateBrowserContextServicesForTest(
36 content::BrowserContext
* context
) {
37 DoCreateBrowserContextServices(context
, true);
40 void BrowserContextDependencyManager::DoCreateBrowserContextServices(
41 content::BrowserContext
* context
,
42 bool is_testing_context
) {
45 "BrowserContextDependencyManager::DoCreateBrowserContextServices")
46 will_create_browser_context_services_callbacks_
.Notify(context
);
47 DependencyManager::CreateContextServices(context
, is_testing_context
);
50 void BrowserContextDependencyManager::DestroyBrowserContextServices(
51 content::BrowserContext
* context
) {
52 DependencyManager::DestroyContextServices(context
);
55 scoped_ptr
<base::CallbackList
<void(content::BrowserContext
*)>::Subscription
>
56 BrowserContextDependencyManager::
57 RegisterWillCreateBrowserContextServicesCallbackForTesting(
58 const base::Callback
<void(content::BrowserContext
*)>& callback
) {
59 return will_create_browser_context_services_callbacks_
.Add(callback
);
63 void BrowserContextDependencyManager::AssertBrowserContextWasntDestroyed(
64 content::BrowserContext
* context
) {
65 DependencyManager::AssertContextWasntDestroyed(context
);
68 void BrowserContextDependencyManager::MarkBrowserContextLiveForTesting(
69 content::BrowserContext
* context
) {
70 DependencyManager::MarkContextLiveForTesting(context
);
75 BrowserContextDependencyManager
*
76 BrowserContextDependencyManager::GetInstance() {
77 return Singleton
<BrowserContextDependencyManager
>::get();
80 BrowserContextDependencyManager::BrowserContextDependencyManager() {}
82 BrowserContextDependencyManager::~BrowserContextDependencyManager() {}
85 void BrowserContextDependencyManager::DumpContextDependencies(
86 const base::SupportsUserData
* context
) const {
87 // Whenever we try to build a destruction ordering, we should also dump a
88 // dependency graph to "/path/to/context/context-dependencies.dot".
89 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
90 kDumpBrowserContextDependencyGraphFlag
)) {
91 base::FilePath dot_file
=
92 static_cast<const content::BrowserContext
*>(context
)
94 .AppendASCII("browser-context-dependencies.dot");
95 DumpDependenciesAsGraphviz("BrowserContext", dot_file
);