| 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" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/profiles/profile_dependency_manager.h" | 9 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 10 #include "components/user_prefs/pref_registry_syncable.h" | 10 #include "components/user_prefs/pref_registry_syncable.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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::GetProfileToUse( | 31 content::BrowserContext* ProfileKeyedBaseFactory::GetBrowserContextToUse( |
| 32 content::BrowserContext* context) { | 32 content::BrowserContext* context) const { |
| 33 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 34 | 34 |
| 35 Profile* profile = static_cast<Profile*>(context); | 35 Profile* profile = static_cast<Profile*>(context); |
| 36 | 36 |
| 37 #ifndef NDEBUG | 37 #ifndef NDEBUG |
| 38 dependency_manager_->AssertProfileWasntDestroyed(profile); | 38 dependency_manager_->AssertProfileWasntDestroyed(profile); |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 // Possibly handle Incognito mode. | 41 // Safe default for the Incognito mode: no service. |
| 42 if (profile->IsOffTheRecord()) { | 42 if (profile->IsOffTheRecord()) |
| 43 if (ServiceRedirectedInIncognito()) { | 43 return NULL; |
| 44 profile = profile->GetOriginalProfile(); | |
| 45 | |
| 46 #ifndef NDEBUG | |
| 47 dependency_manager_->AssertProfileWasntDestroyed(profile); | |
| 48 #endif | |
| 49 } else if (ServiceHasOwnInstanceInIncognito()) { | |
| 50 // No-op; the pointers are already set correctly. | |
| 51 } else { | |
| 52 return NULL; | |
| 53 } | |
| 54 } | |
| 55 | 44 |
| 56 return profile; | 45 return profile; |
| 57 } | 46 } |
| 58 | 47 |
| 59 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile( | 48 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile( |
| 60 content::BrowserContext* profile) { | 49 content::BrowserContext* profile) { |
| 61 // Safe timing for pref registration is hard. Previously, we made Profile | 50 // Safe timing for pref registration is hard. Previously, we made Profile |
| 62 // responsible for all pref registration on every service that used | 51 // responsible for all pref registration on every service that used |
| 63 // Profile. Now we don't and there are timing issues. | 52 // Profile. Now we don't and there are timing issues. |
| 64 // | 53 // |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 registered_preferences_.find(profile); | 74 registered_preferences_.find(profile); |
| 86 if (it == registered_preferences_.end()) { | 75 if (it == registered_preferences_.end()) { |
| 87 PrefService* prefs = components::UserPrefs::Get(profile); | 76 PrefService* prefs = components::UserPrefs::Get(profile); |
| 88 PrefRegistrySyncable* registry = static_cast<PrefRegistrySyncable*>( | 77 PrefRegistrySyncable* registry = static_cast<PrefRegistrySyncable*>( |
| 89 prefs->DeprecatedGetPrefRegistry()); | 78 prefs->DeprecatedGetPrefRegistry()); |
| 90 RegisterUserPrefs(registry); | 79 RegisterUserPrefs(registry); |
| 91 registered_preferences_.insert(profile); | 80 registered_preferences_.insert(profile); |
| 92 } | 81 } |
| 93 } | 82 } |
| 94 | 83 |
| 95 bool ProfileKeyedBaseFactory::ServiceRedirectedInIncognito() const { | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 bool ProfileKeyedBaseFactory::ServiceHasOwnInstanceInIncognito() const { | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 bool ProfileKeyedBaseFactory::ServiceIsCreatedWithProfile() const { | 84 bool ProfileKeyedBaseFactory::ServiceIsCreatedWithProfile() const { |
| 104 return false; | 85 return false; |
| 105 } | 86 } |
| 106 | 87 |
| 107 bool ProfileKeyedBaseFactory::ServiceIsNULLWhileTesting() const { | 88 bool ProfileKeyedBaseFactory::ServiceIsNULLWhileTesting() const { |
| 108 return false; | 89 return false; |
| 109 } | 90 } |
| 110 | 91 |
| 111 void ProfileKeyedBaseFactory::ProfileDestroyed( | 92 void ProfileKeyedBaseFactory::ProfileDestroyed( |
| 112 content::BrowserContext* profile) { | 93 content::BrowserContext* profile) { |
| 113 // While object destruction can be customized in ways where the object is | 94 // While object destruction can be customized in ways where the object is |
| 114 // only dereferenced, this still must run on the UI thread. | 95 // only dereferenced, this still must run on the UI thread. |
| 115 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
| 116 | 97 |
| 117 registered_preferences_.erase(profile); | 98 registered_preferences_.erase(profile); |
| 118 } | 99 } |
| 119 | 100 |
| 120 bool ProfileKeyedBaseFactory::ArePreferencesSetOn( | 101 bool ProfileKeyedBaseFactory::ArePreferencesSetOn( |
| 121 content::BrowserContext* profile) const { | 102 content::BrowserContext* profile) const { |
| 122 return registered_preferences_.find(profile) != | 103 return registered_preferences_.find(profile) != |
| 123 registered_preferences_.end(); | 104 registered_preferences_.end(); |
| 124 } | 105 } |
| 125 | 106 |
| 126 void ProfileKeyedBaseFactory::MarkPreferencesSetOn( | 107 void ProfileKeyedBaseFactory::MarkPreferencesSetOn( |
| 127 content::BrowserContext* profile) { | 108 content::BrowserContext* profile) { |
| 128 DCHECK(!ArePreferencesSetOn(profile)); | 109 DCHECK(!ArePreferencesSetOn(profile)); |
| 129 registered_preferences_.insert(profile); | 110 registered_preferences_.insert(profile); |
| 130 } | 111 } |
| OLD | NEW |