Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 1794353003: Refactor ProfileInfoCache in c/b/profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replaced LOG(WARNING) by UMA histograms Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 484 }
484 485
485 void ProfileImpl::DoFinalInit() { 486 void ProfileImpl::DoFinalInit() {
486 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit") 487 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
487 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit"); 488 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
488 489
489 PrefService* prefs = GetPrefs(); 490 PrefService* prefs = GetPrefs();
490 pref_change_registrar_.Init(prefs); 491 pref_change_registrar_.Init(prefs);
491 pref_change_registrar_.Add( 492 pref_change_registrar_.Add(
492 prefs::kSupervisedUserId, 493 prefs::kSupervisedUserId,
493 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, 494 base::Bind(&ProfileImpl::UpdateSupervisedUserIdInStorage,
494 base::Unretained(this))); 495 base::Unretained(this)));
495 496
496 // Changes in the profile avatar. 497 // Changes in the profile avatar.
497 pref_change_registrar_.Add( 498 pref_change_registrar_.Add(
498 prefs::kProfileAvatarIndex, 499 prefs::kProfileAvatarIndex,
499 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 500 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
500 base::Unretained(this))); 501 base::Unretained(this)));
501 pref_change_registrar_.Add( 502 pref_change_registrar_.Add(
502 prefs::kProfileUsingDefaultAvatar, 503 prefs::kProfileUsingDefaultAvatar,
503 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 504 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
504 base::Unretained(this))); 505 base::Unretained(this)));
505 pref_change_registrar_.Add( 506 pref_change_registrar_.Add(
506 prefs::kProfileUsingGAIAAvatar, 507 prefs::kProfileUsingGAIAAvatar,
507 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 508 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
508 base::Unretained(this))); 509 base::Unretained(this)));
509 510
510 // Changes in the profile name. 511 // Changes in the profile name.
511 pref_change_registrar_.Add( 512 pref_change_registrar_.Add(
512 prefs::kProfileUsingDefaultName, 513 prefs::kProfileUsingDefaultName,
513 base::Bind(&ProfileImpl::UpdateProfileNameCache, 514 base::Bind(&ProfileImpl::UpdateNameInStorage,
514 base::Unretained(this))); 515 base::Unretained(this)));
515 pref_change_registrar_.Add( 516 pref_change_registrar_.Add(
516 prefs::kProfileName, 517 prefs::kProfileName,
517 base::Bind(&ProfileImpl::UpdateProfileNameCache, 518 base::Bind(&ProfileImpl::UpdateNameInStorage,
518 base::Unretained(this))); 519 base::Unretained(this)));
519 520
520 pref_change_registrar_.Add( 521 pref_change_registrar_.Add(
521 prefs::kForceEphemeralProfiles, 522 prefs::kForceEphemeralProfiles,
522 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache, 523 base::Bind(&ProfileImpl::UpdateIsEphemeralInStorage,
523 base::Unretained(this))); 524 base::Unretained(this)));
524 525
525 // It would be nice to use PathService for fetching this directory, but 526 // It would be nice to use PathService for fetching this directory, but
526 // the cache directory depends on the profile directory, which isn't available 527 // the cache directory depends on the profile directory, which isn't available
527 // to PathService. 528 // to PathService.
528 chrome::GetUserCacheDirectory(path_, &base_cache_path_); 529 chrome::GetUserCacheDirectory(path_, &base_cache_path_);
529 // Always create the cache directory asynchronously. 530 // Always create the cache directory asynchronously.
530 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = 531 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
531 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_, 532 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_,
532 BrowserThread::GetBlockingPool()); 533 BrowserThread::GetBlockingPool());
533 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false); 534 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false);
534 535
535 // Initialize components that depend on the current value. 536 // Initialize components that depend on the current value.
536 UpdateProfileSupervisedUserIdCache(); 537 UpdateSupervisedUserIdInStorage();
537 UpdateProfileIsEphemeralCache(); 538 UpdateIsEphemeralInStorage();
538 GAIAInfoUpdateServiceFactory::GetForProfile(this); 539 GAIAInfoUpdateServiceFactory::GetForProfile(this);
539 540
540 PrefService* local_state = g_browser_process->local_state(); 541 PrefService* local_state = g_browser_process->local_state();
541 ssl_config_service_manager_.reset( 542 ssl_config_service_manager_.reset(
542 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 543 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
543 local_state, 544 local_state,
544 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); 545 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
545 546
546 #if BUILDFLAG(ENABLE_BACKGROUND) 547 #if BUILDFLAG(ENABLE_BACKGROUND)
547 // Initialize the BackgroundModeManager - this has to be done here before 548 // Initialize the BackgroundModeManager - this has to be done here before
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 1180
1180 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) 1181 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
1181 return GURL(chrome::kChromeUINewTabURL); 1182 return GURL(chrome::kChromeUINewTabURL);
1182 GURL home_page(url_formatter::FixupURL( 1183 GURL home_page(url_formatter::FixupURL(
1183 GetPrefs()->GetString(prefs::kHomePage), std::string())); 1184 GetPrefs()->GetString(prefs::kHomePage), std::string()));
1184 if (!home_page.is_valid()) 1185 if (!home_page.is_valid())
1185 return GURL(chrome::kChromeUINewTabURL); 1186 return GURL(chrome::kChromeUINewTabURL);
1186 return home_page; 1187 return home_page;
1187 } 1188 }
1188 1189
1189 void ProfileImpl::UpdateProfileSupervisedUserIdCache() { 1190 void ProfileImpl::UpdateSupervisedUserIdInStorage() {
1190 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1191 ProfileManager* profile_manager = g_browser_process->profile_manager();
1191 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1192 ProfileAttributesEntry* entry;
1192 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1193 bool has_entry = profile_manager->GetProfileAttributesStorage().
1193 if (index != std::string::npos) { 1194 GetProfileAttributesWithPath(GetPath(), &entry);
1194 std::string supervised_user_id = 1195 if (has_entry) {
1195 GetPrefs()->GetString(prefs::kSupervisedUserId); 1196 entry->SetSupervisedUserId(GetPrefs()->GetString(prefs::kSupervisedUserId));
1196 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id);
1197 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); 1197 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager);
1198 } 1198 }
1199 } 1199 }
1200 1200
1201 void ProfileImpl::UpdateProfileNameCache() { 1201 void ProfileImpl::UpdateNameInStorage() {
1202 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1202 ProfileAttributesEntry* entry;
1203 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1203 bool has_entry =
1204 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1204 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1205 if (index != std::string::npos) { 1205 GetProfileAttributesWithPath(GetPath(), &entry);
1206 std::string profile_name = 1206 if (has_entry) {
1207 GetPrefs()->GetString(prefs::kProfileName); 1207 entry->SetName(
1208 cache.SetNameOfProfileAtIndex(index, base::UTF8ToUTF16(profile_name)); 1208 base::UTF8ToUTF16(GetPrefs()->GetString(prefs::kProfileName)));
1209 bool default_name = 1209 entry->SetIsUsingDefaultName(
1210 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName); 1210 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName));
1211 cache.SetProfileIsUsingDefaultNameAtIndex(index, default_name);
1212 } 1211 }
1213 } 1212 }
1214 1213
1215 void ProfileImpl::UpdateProfileAvatarCache() { 1214 void ProfileImpl::UpdateAvatarInStorage() {
1216 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1215 ProfileAttributesEntry* entry;
1217 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1216 bool has_entry =
1218 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1217 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1219 if (index != std::string::npos) { 1218 GetProfileAttributesWithPath(GetPath(), &entry);
1220 size_t avatar_index = 1219 if (has_entry) {
1221 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); 1220 entry->SetAvatarIconIndex(
1222 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index); 1221 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex));
1223 bool default_avatar = 1222 entry->SetIsUsingDefaultAvatar(
1224 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar); 1223 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar));
1225 cache.SetProfileIsUsingDefaultAvatarAtIndex(index, default_avatar); 1224 entry->SetIsUsingGAIAPicture(
1226 bool gaia_avatar = 1225 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar));
1227 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar);
1228 cache.SetIsUsingGAIAPictureOfProfileAtIndex(index, gaia_avatar);
1229 } 1226 }
1230 } 1227 }
1231 1228
1232 void ProfileImpl::UpdateProfileIsEphemeralCache() { 1229 void ProfileImpl::UpdateIsEphemeralInStorage() {
1233 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1230 ProfileAttributesEntry* entry;
1234 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1231 bool has_entry =
1235 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1232 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1236 if (index != std::string::npos) { 1233 GetProfileAttributesWithPath(GetPath(), &entry);
1237 bool is_ephemeral = GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles); 1234 if (has_entry) {
1238 cache.SetProfileIsEphemeralAtIndex(index, is_ephemeral); 1235 entry->SetIsEphemeral(
1236 GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles));
1239 } 1237 }
1240 } 1238 }
1241 1239
1242 // Gets the cache parameters from the command line. If |is_media_context| is 1240 // Gets the cache parameters from the command line. If |is_media_context| is
1243 // set to true then settings for the media context type is what we need, 1241 // set to true then settings for the media context type is what we need,
1244 // |cache_path| will be set to the user provided path, or will not be touched if 1242 // |cache_path| will be set to the user provided path, or will not be touched if
1245 // there is not an argument. |max_size| will be the user provided value or zero 1243 // there is not an argument. |max_size| will be the user provided value or zero
1246 // by default. 1244 // by default.
1247 void ProfileImpl::GetCacheParameters(bool is_media_context, 1245 void ProfileImpl::GetCacheParameters(bool is_media_context,
1248 base::FilePath* cache_path, 1246 base::FilePath* cache_path,
(...skipping 22 matching lines...) Expand all
1271 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { 1269 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) {
1272 domain_reliability::DomainReliabilityService* service = 1270 domain_reliability::DomainReliabilityService* service =
1273 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> 1271 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1274 GetForBrowserContext(this); 1272 GetForBrowserContext(this);
1275 if (!service) 1273 if (!service)
1276 return std::unique_ptr<domain_reliability::DomainReliabilityMonitor>(); 1274 return std::unique_ptr<domain_reliability::DomainReliabilityMonitor>();
1277 1275
1278 return service->CreateMonitor( 1276 return service->CreateMonitor(
1279 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 1277 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
1280 } 1278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698