| 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/command_line.h" |
| 7 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/prefs/pref_registry_syncable.h" | 9 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_dependency_manager.h" | 11 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
| 11 | 13 |
| 12 ProfileKeyedBaseFactory::ProfileKeyedBaseFactory( | 14 ProfileKeyedBaseFactory::ProfileKeyedBaseFactory( |
| 13 const char* name, ProfileDependencyManager* manager) | 15 const char* name, ProfileDependencyManager* manager) |
| 14 : dependency_manager_(manager) | 16 : dependency_manager_(manager) |
| 15 #ifndef NDEBUG | 17 #ifndef NDEBUG |
| 16 , service_name_(name) | 18 , service_name_(name) |
| 17 #endif | 19 #endif |
| 18 { | 20 { |
| 19 dependency_manager_->AddComponent(this); | 21 dependency_manager_->AddComponent(this); |
| 20 } | 22 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 #ifndef NDEBUG | 44 #ifndef NDEBUG |
| 43 dependency_manager_->AssertProfileWasntDestroyed(profile); | 45 dependency_manager_->AssertProfileWasntDestroyed(profile); |
| 44 #endif | 46 #endif |
| 45 } else if (ServiceHasOwnInstanceInIncognito()) { | 47 } else if (ServiceHasOwnInstanceInIncognito()) { |
| 46 // No-op; the pointers are already set correctly. | 48 // No-op; the pointers are already set correctly. |
| 47 } else { | 49 } else { |
| 48 return NULL; | 50 return NULL; |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 54 // If this is the import process, most services are not created to avoid |
| 55 // conflicts with non-shareable resources used by the same service running in |
| 56 // the browser process. |
| 57 if (ProfileManager::IsImportProcess(*CommandLine::ForCurrentProcess()) && |
| 58 ServiceIsNULLOnImportProcess()) { |
| 59 return NULL; |
| 60 } |
| 61 |
| 52 return profile; | 62 return profile; |
| 53 } | 63 } |
| 54 | 64 |
| 55 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile(Profile* profile) { | 65 void ProfileKeyedBaseFactory::RegisterUserPrefsOnProfile(Profile* profile) { |
| 56 // Safe timing for pref registration is hard. Previously, we made Profile | 66 // Safe timing for pref registration is hard. Previously, we made Profile |
| 57 // responsible for all pref registration on every service that used | 67 // responsible for all pref registration on every service that used |
| 58 // Profile. Now we don't and there are timing issues. | 68 // Profile. Now we don't and there are timing issues. |
| 59 // | 69 // |
| 60 // With normal profiles, prefs can simply be registered at | 70 // With normal profiles, prefs can simply be registered at |
| 61 // ProfileDependencyManager::CreateProfileServices time. With incognito | 71 // ProfileDependencyManager::CreateProfileServices time. With incognito |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 105 } |
| 96 | 106 |
| 97 bool ProfileKeyedBaseFactory::ServiceIsCreatedWithProfile() const { | 107 bool ProfileKeyedBaseFactory::ServiceIsCreatedWithProfile() const { |
| 98 return false; | 108 return false; |
| 99 } | 109 } |
| 100 | 110 |
| 101 bool ProfileKeyedBaseFactory::ServiceIsNULLWhileTesting() const { | 111 bool ProfileKeyedBaseFactory::ServiceIsNULLWhileTesting() const { |
| 102 return false; | 112 return false; |
| 103 } | 113 } |
| 104 | 114 |
| 115 bool ProfileKeyedBaseFactory::ServiceIsNULLOnImportProcess() const { |
| 116 return true; |
| 117 } |
| 118 |
| 105 void ProfileKeyedBaseFactory::ProfileDestroyed(Profile* profile) { | 119 void ProfileKeyedBaseFactory::ProfileDestroyed(Profile* profile) { |
| 106 // While object destruction can be customized in ways where the object is | 120 // While object destruction can be customized in ways where the object is |
| 107 // only dereferenced, this still must run on the UI thread. | 121 // only dereferenced, this still must run on the UI thread. |
| 108 DCHECK(CalledOnValidThread()); | 122 DCHECK(CalledOnValidThread()); |
| 109 | 123 |
| 110 registered_preferences_.erase(profile); | 124 registered_preferences_.erase(profile); |
| 111 } | 125 } |
| 112 | 126 |
| 113 bool ProfileKeyedBaseFactory::ArePreferencesSetOn(Profile* profile) const { | 127 bool ProfileKeyedBaseFactory::ArePreferencesSetOn(Profile* profile) const { |
| 114 return registered_preferences_.find(profile) != | 128 return registered_preferences_.find(profile) != |
| 115 registered_preferences_.end(); | 129 registered_preferences_.end(); |
| 116 } | 130 } |
| 117 | 131 |
| 118 void ProfileKeyedBaseFactory::MarkPreferencesSetOn(Profile* profile) { | 132 void ProfileKeyedBaseFactory::MarkPreferencesSetOn(Profile* profile) { |
| 119 DCHECK(!ArePreferencesSetOn(profile)); | 133 DCHECK(!ArePreferencesSetOn(profile)); |
| 120 registered_preferences_.insert(profile); | 134 registered_preferences_.insert(profile); |
| 121 } | 135 } |
| OLD | NEW |