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