OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile_keyed_base_factory.h" | 5 #include "chrome/browser/profiles/profile_keyed_base_factory.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/profiles/profile_dependency_manager.h" | 8 #include "chrome/browser/profiles/profile_dependency_manager.h" |
10 #include "components/user_prefs/pref_registry_syncable.h" | 9 #include "components/user_prefs/pref_registry_syncable.h" |
11 #include "components/user_prefs/user_prefs.h" | 10 #include "components/user_prefs/user_prefs.h" |
| 11 #include "content/public/browser/browser_context.h" |
12 | 12 |
13 ProfileKeyedBaseFactory::ProfileKeyedBaseFactory( | 13 ProfileKeyedBaseFactory::ProfileKeyedBaseFactory( |
14 const char* name, ProfileDependencyManager* manager) | 14 const char* name, ProfileDependencyManager* manager) |
15 : dependency_manager_(manager) | 15 : dependency_manager_(manager) |
16 #ifndef NDEBUG | 16 #ifndef NDEBUG |
17 , service_name_(name) | 17 , service_name_(name) |
18 #endif | 18 #endif |
19 { | 19 { |
20 dependency_manager_->AddComponent(this); | 20 dependency_manager_->AddComponent(this); |
21 } | 21 } |
22 | 22 |
23 ProfileKeyedBaseFactory::~ProfileKeyedBaseFactory() { | 23 ProfileKeyedBaseFactory::~ProfileKeyedBaseFactory() { |
24 dependency_manager_->RemoveComponent(this); | 24 dependency_manager_->RemoveComponent(this); |
25 } | 25 } |
26 | 26 |
27 void ProfileKeyedBaseFactory::DependsOn(ProfileKeyedBaseFactory* rhs) { | 27 void ProfileKeyedBaseFactory::DependsOn(ProfileKeyedBaseFactory* rhs) { |
28 dependency_manager_->AddEdge(rhs, this); | 28 dependency_manager_->AddEdge(rhs, this); |
29 } | 29 } |
30 | 30 |
31 content::BrowserContext* ProfileKeyedBaseFactory::GetBrowserContextToUse( | 31 content::BrowserContext* ProfileKeyedBaseFactory::GetBrowserContextToUse( |
32 content::BrowserContext* context) const { | 32 content::BrowserContext* context) const { |
33 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
34 | 34 |
35 Profile* profile = static_cast<Profile*>(context); | |
36 | |
37 #ifndef NDEBUG | 35 #ifndef NDEBUG |
38 dependency_manager_->AssertProfileWasntDestroyed(profile); | 36 dependency_manager_->AssertProfileWasntDestroyed(context); |
39 #endif | 37 #endif |
40 | 38 |
41 // Safe default for the Incognito mode: no service. | 39 // Safe default for the Incognito mode: no service. |
42 if (profile->IsOffTheRecord()) | 40 if (context->IsOffTheRecord()) |
43 return NULL; | 41 return NULL; |
44 | 42 |
45 return profile; | 43 return context; |
46 } | 44 } |
47 | 45 |
48 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile( | 46 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile( |
49 content::BrowserContext* profile) { | 47 content::BrowserContext* profile) { |
50 // Safe timing for pref registration is hard. Previously, we made Profile | 48 // Safe timing for pref registration is hard. Previously, we made Profile |
51 // responsible for all pref registration on every service that used | 49 // responsible for all pref registration on every service that used |
52 // Profile. Now we don't and there are timing issues. | 50 // Profile. Now we don't and there are timing issues. |
53 // | 51 // |
54 // With normal profiles, prefs can simply be registered at | 52 // With normal profiles, prefs can simply be registered at |
55 // ProfileDependencyManager::CreateProfileServices time. With incognito | 53 // ProfileDependencyManager::CreateProfileServices time. With incognito |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 content::BrowserContext* profile) const { | 101 content::BrowserContext* profile) const { |
104 return registered_preferences_.find(profile) != | 102 return registered_preferences_.find(profile) != |
105 registered_preferences_.end(); | 103 registered_preferences_.end(); |
106 } | 104 } |
107 | 105 |
108 void ProfileKeyedBaseFactory::MarkPreferencesSetOn( | 106 void ProfileKeyedBaseFactory::MarkPreferencesSetOn( |
109 content::BrowserContext* profile) { | 107 content::BrowserContext* profile) { |
110 DCHECK(!ArePreferencesSetOn(profile)); | 108 DCHECK(!ArePreferencesSetOn(profile)); |
111 registered_preferences_.insert(profile); | 109 registered_preferences_.insert(profile); |
112 } | 110 } |
OLD | NEW |