| 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_impl.h" | 5 #include "chrome/browser/profiles/profile_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 55 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 56 #include "chrome/browser/policy/schema_registry_service.h" | 56 #include "chrome/browser/policy/schema_registry_service.h" |
| 57 #include "chrome/browser/policy/schema_registry_service_factory.h" | 57 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 58 #include "chrome/browser/prefs/browser_prefs.h" | 58 #include "chrome/browser/prefs/browser_prefs.h" |
| 59 #include "chrome/browser/prefs/chrome_pref_service_factory.h" | 59 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 60 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 60 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 61 #include "chrome/browser/prerender/prerender_manager_factory.h" | 61 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 62 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" | 62 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" |
| 63 #include "chrome/browser/profiles/chrome_version_service.h" | 63 #include "chrome/browser/profiles/chrome_version_service.h" |
| 64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" | 64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" |
| 65 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 66 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 65 #include "chrome/browser/profiles/profile_destroyer.h" | 67 #include "chrome/browser/profiles/profile_destroyer.h" |
| 66 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 67 #include "chrome/browser/profiles/profile_manager.h" | 68 #include "chrome/browser/profiles/profile_manager.h" |
| 68 #include "chrome/browser/profiles/profile_metrics.h" | 69 #include "chrome/browser/profiles/profile_metrics.h" |
| 69 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 70 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 70 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 71 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 71 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 72 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 72 #include "chrome/browser/sessions/session_service_factory.h" | 73 #include "chrome/browser/sessions/session_service_factory.h" |
| 73 #include "chrome/browser/signin/signin_manager_factory.h" | 74 #include "chrome/browser/signin/signin_manager_factory.h" |
| 74 #include "chrome/browser/signin/signin_ui_util.h" | 75 #include "chrome/browser/signin/signin_ui_util.h" |
| 75 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 76 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 76 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 77 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 479 } |
| 479 | 480 |
| 480 void ProfileImpl::DoFinalInit() { | 481 void ProfileImpl::DoFinalInit() { |
| 481 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit") | 482 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit") |
| 482 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit"); | 483 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit"); |
| 483 | 484 |
| 484 PrefService* prefs = GetPrefs(); | 485 PrefService* prefs = GetPrefs(); |
| 485 pref_change_registrar_.Init(prefs); | 486 pref_change_registrar_.Init(prefs); |
| 486 pref_change_registrar_.Add( | 487 pref_change_registrar_.Add( |
| 487 prefs::kSupervisedUserId, | 488 prefs::kSupervisedUserId, |
| 488 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, | 489 base::Bind(&ProfileImpl::UpdateSupervisedUserIdInStorage, |
| 489 base::Unretained(this))); | 490 base::Unretained(this))); |
| 490 | 491 |
| 491 // Changes in the profile avatar. | 492 // Changes in the profile avatar. |
| 492 pref_change_registrar_.Add( | 493 pref_change_registrar_.Add( |
| 493 prefs::kProfileAvatarIndex, | 494 prefs::kProfileAvatarIndex, |
| 494 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 495 base::Bind(&ProfileImpl::UpdateAvatarInStorage, |
| 495 base::Unretained(this))); | 496 base::Unretained(this))); |
| 496 pref_change_registrar_.Add( | 497 pref_change_registrar_.Add( |
| 497 prefs::kProfileUsingDefaultAvatar, | 498 prefs::kProfileUsingDefaultAvatar, |
| 498 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 499 base::Bind(&ProfileImpl::UpdateAvatarInStorage, |
| 499 base::Unretained(this))); | 500 base::Unretained(this))); |
| 500 pref_change_registrar_.Add( | 501 pref_change_registrar_.Add( |
| 501 prefs::kProfileUsingGAIAAvatar, | 502 prefs::kProfileUsingGAIAAvatar, |
| 502 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, | 503 base::Bind(&ProfileImpl::UpdateAvatarInStorage, |
| 503 base::Unretained(this))); | 504 base::Unretained(this))); |
| 504 | 505 |
| 505 // Changes in the profile name. | 506 // Changes in the profile name. |
| 506 pref_change_registrar_.Add( | 507 pref_change_registrar_.Add( |
| 507 prefs::kProfileUsingDefaultName, | 508 prefs::kProfileUsingDefaultName, |
| 508 base::Bind(&ProfileImpl::UpdateProfileNameCache, | 509 base::Bind(&ProfileImpl::UpdateNameInStorage, |
| 509 base::Unretained(this))); | 510 base::Unretained(this))); |
| 510 pref_change_registrar_.Add( | 511 pref_change_registrar_.Add( |
| 511 prefs::kProfileName, | 512 prefs::kProfileName, |
| 512 base::Bind(&ProfileImpl::UpdateProfileNameCache, | 513 base::Bind(&ProfileImpl::UpdateNameInStorage, |
| 513 base::Unretained(this))); | 514 base::Unretained(this))); |
| 514 | 515 |
| 515 pref_change_registrar_.Add( | 516 pref_change_registrar_.Add( |
| 516 prefs::kForceEphemeralProfiles, | 517 prefs::kForceEphemeralProfiles, |
| 517 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache, | 518 base::Bind(&ProfileImpl::UpdateIsEphemeralInStorage, |
| 518 base::Unretained(this))); | 519 base::Unretained(this))); |
| 519 | 520 |
| 520 // It would be nice to use PathService for fetching this directory, but | 521 // It would be nice to use PathService for fetching this directory, but |
| 521 // the cache directory depends on the profile directory, which isn't available | 522 // the cache directory depends on the profile directory, which isn't available |
| 522 // to PathService. | 523 // to PathService. |
| 523 chrome::GetUserCacheDirectory(path_, &base_cache_path_); | 524 chrome::GetUserCacheDirectory(path_, &base_cache_path_); |
| 524 // Always create the cache directory asynchronously. | 525 // Always create the cache directory asynchronously. |
| 525 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = | 526 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = |
| 526 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_, | 527 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_, |
| 527 BrowserThread::GetBlockingPool()); | 528 BrowserThread::GetBlockingPool()); |
| 528 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false); | 529 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false); |
| 529 | 530 |
| 530 // Initialize components that depend on the current value. | 531 // Initialize components that depend on the current value. |
| 531 UpdateProfileSupervisedUserIdCache(); | 532 UpdateSupervisedUserIdInStorage(); |
| 532 UpdateProfileIsEphemeralCache(); | 533 UpdateIsEphemeralInStorage(); |
| 533 GAIAInfoUpdateServiceFactory::GetForProfile(this); | 534 GAIAInfoUpdateServiceFactory::GetForProfile(this); |
| 534 | 535 |
| 535 PrefService* local_state = g_browser_process->local_state(); | 536 PrefService* local_state = g_browser_process->local_state(); |
| 536 ssl_config_service_manager_.reset( | 537 ssl_config_service_manager_.reset( |
| 537 ssl_config::SSLConfigServiceManager::CreateDefaultManager( | 538 ssl_config::SSLConfigServiceManager::CreateDefaultManager( |
| 538 local_state, | 539 local_state, |
| 539 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 540 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 540 | 541 |
| 541 #if BUILDFLAG(ENABLE_BACKGROUND) | 542 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 542 // Initialize the BackgroundModeManager - this has to be done here before | 543 // Initialize the BackgroundModeManager - this has to be done here before |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 | 1164 |
| 1164 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) | 1165 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 1165 return GURL(chrome::kChromeUINewTabURL); | 1166 return GURL(chrome::kChromeUINewTabURL); |
| 1166 GURL home_page(url_formatter::FixupURL( | 1167 GURL home_page(url_formatter::FixupURL( |
| 1167 GetPrefs()->GetString(prefs::kHomePage), std::string())); | 1168 GetPrefs()->GetString(prefs::kHomePage), std::string())); |
| 1168 if (!home_page.is_valid()) | 1169 if (!home_page.is_valid()) |
| 1169 return GURL(chrome::kChromeUINewTabURL); | 1170 return GURL(chrome::kChromeUINewTabURL); |
| 1170 return home_page; | 1171 return home_page; |
| 1171 } | 1172 } |
| 1172 | 1173 |
| 1173 void ProfileImpl::UpdateProfileSupervisedUserIdCache() { | 1174 void ProfileImpl::UpdateSupervisedUserIdInStorage() { |
| 1174 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1175 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1175 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1176 ProfileAttributesEntry* entry; |
| 1176 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1177 bool has_entry = profile_manager->GetProfileAttributesStorage(). |
| 1177 if (index != std::string::npos) { | 1178 GetProfileAttributesWithPath(GetPath(), &entry); |
| 1178 std::string supervised_user_id = | 1179 if (has_entry) { |
| 1179 GetPrefs()->GetString(prefs::kSupervisedUserId); | 1180 entry->SetSupervisedUserId(GetPrefs()->GetString(prefs::kSupervisedUserId)); |
| 1180 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id); | |
| 1181 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); | 1181 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); |
| 1182 } | 1182 } |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 void ProfileImpl::UpdateProfileNameCache() { | 1185 void ProfileImpl::UpdateNameInStorage() { |
| 1186 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1186 ProfileAttributesEntry* entry; |
| 1187 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1187 bool has_entry = |
| 1188 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1188 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 1189 if (index != std::string::npos) { | 1189 GetProfileAttributesWithPath(GetPath(), &entry); |
| 1190 std::string profile_name = | 1190 if (has_entry) { |
| 1191 GetPrefs()->GetString(prefs::kProfileName); | 1191 entry->SetName( |
| 1192 cache.SetNameOfProfileAtIndex(index, base::UTF8ToUTF16(profile_name)); | 1192 base::UTF8ToUTF16(GetPrefs()->GetString(prefs::kProfileName))); |
| 1193 bool default_name = | 1193 entry->SetIsUsingDefaultName( |
| 1194 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName); | 1194 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName)); |
| 1195 cache.SetProfileIsUsingDefaultNameAtIndex(index, default_name); | |
| 1196 } | 1195 } |
| 1197 } | 1196 } |
| 1198 | 1197 |
| 1199 void ProfileImpl::UpdateProfileAvatarCache() { | 1198 void ProfileImpl::UpdateAvatarInStorage() { |
| 1200 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1199 ProfileAttributesEntry* entry; |
| 1201 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1200 bool has_entry = |
| 1202 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1201 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 1203 if (index != std::string::npos) { | 1202 GetProfileAttributesWithPath(GetPath(), &entry); |
| 1204 size_t avatar_index = | 1203 if (has_entry) { |
| 1205 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); | 1204 entry->SetAvatarIconIndex( |
| 1206 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index); | 1205 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex)); |
| 1207 bool default_avatar = | 1206 entry->SetIsUsingDefaultAvatar( |
| 1208 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar); | 1207 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar)); |
| 1209 cache.SetProfileIsUsingDefaultAvatarAtIndex(index, default_avatar); | 1208 entry->SetIsUsingGAIAPicture( |
| 1210 bool gaia_avatar = | 1209 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar)); |
| 1211 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar); | |
| 1212 cache.SetIsUsingGAIAPictureOfProfileAtIndex(index, gaia_avatar); | |
| 1213 } | 1210 } |
| 1214 } | 1211 } |
| 1215 | 1212 |
| 1216 void ProfileImpl::UpdateProfileIsEphemeralCache() { | 1213 void ProfileImpl::UpdateIsEphemeralInStorage() { |
| 1217 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1214 ProfileAttributesEntry* entry; |
| 1218 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1215 bool has_entry = |
| 1219 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1216 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 1220 if (index != std::string::npos) { | 1217 GetProfileAttributesWithPath(GetPath(), &entry); |
| 1221 bool is_ephemeral = GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles); | 1218 if (has_entry) { |
| 1222 cache.SetProfileIsEphemeralAtIndex(index, is_ephemeral); | 1219 entry->SetIsEphemeral( |
| 1220 GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)); |
| 1223 } | 1221 } |
| 1224 } | 1222 } |
| 1225 | 1223 |
| 1226 // Gets the cache parameters from the command line. If |is_media_context| is | 1224 // Gets the cache parameters from the command line. If |is_media_context| is |
| 1227 // set to true then settings for the media context type is what we need, | 1225 // set to true then settings for the media context type is what we need, |
| 1228 // |cache_path| will be set to the user provided path, or will not be touched if | 1226 // |cache_path| will be set to the user provided path, or will not be touched if |
| 1229 // there is not an argument. |max_size| will be the user provided value or zero | 1227 // there is not an argument. |max_size| will be the user provided value or zero |
| 1230 // by default. | 1228 // by default. |
| 1231 void ProfileImpl::GetCacheParameters(bool is_media_context, | 1229 void ProfileImpl::GetCacheParameters(bool is_media_context, |
| 1232 base::FilePath* cache_path, | 1230 base::FilePath* cache_path, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1255 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { | 1253 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { |
| 1256 domain_reliability::DomainReliabilityService* service = | 1254 domain_reliability::DomainReliabilityService* service = |
| 1257 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> | 1255 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> |
| 1258 GetForBrowserContext(this); | 1256 GetForBrowserContext(this); |
| 1259 if (!service) | 1257 if (!service) |
| 1260 return std::unique_ptr<domain_reliability::DomainReliabilityMonitor>(); | 1258 return std::unique_ptr<domain_reliability::DomainReliabilityMonitor>(); |
| 1261 | 1259 |
| 1262 return service->CreateMonitor( | 1260 return service->CreateMonitor( |
| 1263 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 1261 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 1264 } | 1262 } |
| OLD | NEW |