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

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: Created 4 years, 9 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 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "chrome/browser/plugins/plugin_prefs.h" 51 #include "chrome/browser/plugins/plugin_prefs.h"
52 #include "chrome/browser/policy/profile_policy_connector.h" 52 #include "chrome/browser/policy/profile_policy_connector.h"
53 #include "chrome/browser/policy/profile_policy_connector_factory.h" 53 #include "chrome/browser/policy/profile_policy_connector_factory.h"
54 #include "chrome/browser/prefs/browser_prefs.h" 54 #include "chrome/browser/prefs/browser_prefs.h"
55 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 55 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
56 #include "chrome/browser/prefs/pref_service_syncable_util.h" 56 #include "chrome/browser/prefs/pref_service_syncable_util.h"
57 #include "chrome/browser/prerender/prerender_manager_factory.h" 57 #include "chrome/browser/prerender/prerender_manager_factory.h"
58 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" 58 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
59 #include "chrome/browser/profiles/chrome_version_service.h" 59 #include "chrome/browser/profiles/chrome_version_service.h"
60 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" 60 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
61 #include "chrome/browser/profiles/profile_attributes_entry.h"
62 #include "chrome/browser/profiles/profile_attributes_storage.h"
61 #include "chrome/browser/profiles/profile_destroyer.h" 63 #include "chrome/browser/profiles/profile_destroyer.h"
62 #include "chrome/browser/profiles/profile_info_cache.h"
63 #include "chrome/browser/profiles/profile_manager.h" 64 #include "chrome/browser/profiles/profile_manager.h"
64 #include "chrome/browser/profiles/profile_metrics.h" 65 #include "chrome/browser/profiles/profile_metrics.h"
65 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" 66 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
66 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" 67 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
67 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 68 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
68 #include "chrome/browser/sessions/session_service_factory.h" 69 #include "chrome/browser/sessions/session_service_factory.h"
69 #include "chrome/browser/signin/signin_manager_factory.h" 70 #include "chrome/browser/signin/signin_manager_factory.h"
70 #include "chrome/browser/signin/signin_ui_util.h" 71 #include "chrome/browser/signin/signin_ui_util.h"
71 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 72 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
72 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" 73 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 486 }
486 487
487 void ProfileImpl::DoFinalInit() { 488 void ProfileImpl::DoFinalInit() {
488 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit") 489 TRACE_EVENT0("browser", "ProfileImpl::DoFinalInit")
489 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit"); 490 SCOPED_UMA_HISTOGRAM_TIMER("Profile.ProfileImplDoFinalInit");
490 491
491 PrefService* prefs = GetPrefs(); 492 PrefService* prefs = GetPrefs();
492 pref_change_registrar_.Init(prefs); 493 pref_change_registrar_.Init(prefs);
493 pref_change_registrar_.Add( 494 pref_change_registrar_.Add(
494 prefs::kSupervisedUserId, 495 prefs::kSupervisedUserId,
495 base::Bind(&ProfileImpl::UpdateProfileSupervisedUserIdCache, 496 base::Bind(&ProfileImpl::UpdateSupervisedUserIdInStorage,
496 base::Unretained(this))); 497 base::Unretained(this)));
497 498
498 // Changes in the profile avatar. 499 // Changes in the profile avatar.
499 pref_change_registrar_.Add( 500 pref_change_registrar_.Add(
500 prefs::kProfileAvatarIndex, 501 prefs::kProfileAvatarIndex,
501 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 502 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
502 base::Unretained(this))); 503 base::Unretained(this)));
503 pref_change_registrar_.Add( 504 pref_change_registrar_.Add(
504 prefs::kProfileUsingDefaultAvatar, 505 prefs::kProfileUsingDefaultAvatar,
505 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 506 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
506 base::Unretained(this))); 507 base::Unretained(this)));
507 pref_change_registrar_.Add( 508 pref_change_registrar_.Add(
508 prefs::kProfileUsingGAIAAvatar, 509 prefs::kProfileUsingGAIAAvatar,
509 base::Bind(&ProfileImpl::UpdateProfileAvatarCache, 510 base::Bind(&ProfileImpl::UpdateAvatarInStorage,
510 base::Unretained(this))); 511 base::Unretained(this)));
511 512
512 // Changes in the profile name. 513 // Changes in the profile name.
513 pref_change_registrar_.Add( 514 pref_change_registrar_.Add(
514 prefs::kProfileUsingDefaultName, 515 prefs::kProfileUsingDefaultName,
515 base::Bind(&ProfileImpl::UpdateProfileNameCache, 516 base::Bind(&ProfileImpl::UpdateNameInStorage,
516 base::Unretained(this))); 517 base::Unretained(this)));
517 pref_change_registrar_.Add( 518 pref_change_registrar_.Add(
518 prefs::kProfileName, 519 prefs::kProfileName,
519 base::Bind(&ProfileImpl::UpdateProfileNameCache, 520 base::Bind(&ProfileImpl::UpdateNameInStorage,
520 base::Unretained(this))); 521 base::Unretained(this)));
521 522
522 pref_change_registrar_.Add( 523 pref_change_registrar_.Add(
523 prefs::kForceEphemeralProfiles, 524 prefs::kForceEphemeralProfiles,
524 base::Bind(&ProfileImpl::UpdateProfileIsEphemeralCache, 525 base::Bind(&ProfileImpl::UpdateIsEphemeralInStorage,
525 base::Unretained(this))); 526 base::Unretained(this)));
526 527
527 // It would be nice to use PathService for fetching this directory, but 528 // It would be nice to use PathService for fetching this directory, but
528 // the cache directory depends on the profile directory, which isn't available 529 // the cache directory depends on the profile directory, which isn't available
529 // to PathService. 530 // to PathService.
530 chrome::GetUserCacheDirectory(path_, &base_cache_path_); 531 chrome::GetUserCacheDirectory(path_, &base_cache_path_);
531 // Always create the cache directory asynchronously. 532 // Always create the cache directory asynchronously.
532 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = 533 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner =
533 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_, 534 JsonPrefStore::GetTaskRunnerForFile(base_cache_path_,
534 BrowserThread::GetBlockingPool()); 535 BrowserThread::GetBlockingPool());
535 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false); 536 CreateProfileDirectory(sequenced_task_runner.get(), base_cache_path_, false);
536 537
537 // Initialize components that depend on the current value. 538 // Initialize components that depend on the current value.
538 UpdateProfileSupervisedUserIdCache(); 539 UpdateSupervisedUserIdInStorage();
539 UpdateProfileIsEphemeralCache(); 540 UpdateIsEphemeralInStorage();
540 GAIAInfoUpdateServiceFactory::GetForProfile(this); 541 GAIAInfoUpdateServiceFactory::GetForProfile(this);
541 542
542 PrefService* local_state = g_browser_process->local_state(); 543 PrefService* local_state = g_browser_process->local_state();
543 ssl_config_service_manager_.reset( 544 ssl_config_service_manager_.reset(
544 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 545 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
545 local_state, 546 local_state,
546 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); 547 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
547 548
548 #if BUILDFLAG(ENABLE_BACKGROUND) 549 #if BUILDFLAG(ENABLE_BACKGROUND)
549 // Initialize the BackgroundModeManager - this has to be done here before 550 // Initialize the BackgroundModeManager - this has to be done here before
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 1190
1190 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) 1191 if (GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
1191 return GURL(chrome::kChromeUINewTabURL); 1192 return GURL(chrome::kChromeUINewTabURL);
1192 GURL home_page(url_formatter::FixupURL( 1193 GURL home_page(url_formatter::FixupURL(
1193 GetPrefs()->GetString(prefs::kHomePage), std::string())); 1194 GetPrefs()->GetString(prefs::kHomePage), std::string()));
1194 if (!home_page.is_valid()) 1195 if (!home_page.is_valid())
1195 return GURL(chrome::kChromeUINewTabURL); 1196 return GURL(chrome::kChromeUINewTabURL);
1196 return home_page; 1197 return home_page;
1197 } 1198 }
1198 1199
1199 void ProfileImpl::UpdateProfileSupervisedUserIdCache() { 1200 void ProfileImpl::UpdateSupervisedUserIdInStorage() {
1200 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1201 ProfileManager* profile_manager = g_browser_process->profile_manager();
1201 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1202 ProfileAttributesEntry* entry;
1202 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1203 bool has_entry = profile_manager->GetProfileAttributesStorage().
1203 if (index != std::string::npos) { 1204 GetProfileAttributesWithPath(GetPath(), &entry);
1204 std::string supervised_user_id = 1205 if (has_entry) {
1205 GetPrefs()->GetString(prefs::kSupervisedUserId); 1206 entry->SetSupervisedUserId(GetPrefs()->GetString(prefs::kSupervisedUserId));
1206 cache.SetSupervisedUserIdOfProfileAtIndex(index, supervised_user_id);
1207 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager); 1207 ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager);
1208 } 1208 }
1209 } 1209 }
1210 1210
1211 void ProfileImpl::UpdateProfileNameCache() { 1211 void ProfileImpl::UpdateNameInStorage() {
1212 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1212 ProfileAttributesEntry* entry;
1213 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1213 bool has_entry =
1214 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1214 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1215 if (index != std::string::npos) { 1215 GetProfileAttributesWithPath(GetPath(), &entry);
1216 std::string profile_name = 1216 if (has_entry) {
1217 GetPrefs()->GetString(prefs::kProfileName); 1217 entry->SetName(
1218 cache.SetNameOfProfileAtIndex(index, base::UTF8ToUTF16(profile_name)); 1218 base::UTF8ToUTF16(GetPrefs()->GetString(prefs::kProfileName)));
1219 bool default_name = 1219 entry->SetIsUsingDefaultName(
1220 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName); 1220 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName));
1221 cache.SetProfileIsUsingDefaultNameAtIndex(index, default_name);
1222 } 1221 }
1223 } 1222 }
1224 1223
1225 void ProfileImpl::UpdateProfileAvatarCache() { 1224 void ProfileImpl::UpdateAvatarInStorage() {
1226 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1225 ProfileAttributesEntry* entry;
1227 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1226 bool has_entry =
1228 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1227 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1229 if (index != std::string::npos) { 1228 GetProfileAttributesWithPath(GetPath(), &entry);
1230 size_t avatar_index = 1229 if (has_entry) {
1231 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); 1230 entry->SetAvatarIconIndex(
1232 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index); 1231 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex));
1233 bool default_avatar = 1232 entry->SetIsUsingDefaultAvatar(
1234 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar); 1233 GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultAvatar));
1235 cache.SetProfileIsUsingDefaultAvatarAtIndex(index, default_avatar); 1234 entry->SetIsUsingGAIAPicture(
1236 bool gaia_avatar = 1235 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar));
1237 GetPrefs()->GetBoolean(prefs::kProfileUsingGAIAAvatar);
1238 cache.SetIsUsingGAIAPictureOfProfileAtIndex(index, gaia_avatar);
1239 } 1236 }
1240 } 1237 }
1241 1238
1242 void ProfileImpl::UpdateProfileIsEphemeralCache() { 1239 void ProfileImpl::UpdateIsEphemeralInStorage() {
1243 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1240 ProfileAttributesEntry* entry;
1244 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1241 bool has_entry =
1245 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1242 g_browser_process->profile_manager()->GetProfileAttributesStorage().
1246 if (index != std::string::npos) { 1243 GetProfileAttributesWithPath(GetPath(), &entry);
1247 bool is_ephemeral = GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles); 1244 if (has_entry) {
1248 cache.SetProfileIsEphemeralAtIndex(index, is_ephemeral); 1245 entry->SetIsEphemeral(
1246 GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles));
1249 } 1247 }
1250 } 1248 }
1251 1249
1252 // Gets the cache parameters from the command line. If |is_media_context| is 1250 // Gets the cache parameters from the command line. If |is_media_context| is
1253 // set to true then settings for the media context type is what we need, 1251 // set to true then settings for the media context type is what we need,
1254 // |cache_path| will be set to the user provided path, or will not be touched if 1252 // |cache_path| will be set to the user provided path, or will not be touched if
1255 // there is not an argument. |max_size| will be the user provided value or zero 1253 // there is not an argument. |max_size| will be the user provided value or zero
1256 // by default. 1254 // by default.
1257 void ProfileImpl::GetCacheParameters(bool is_media_context, 1255 void ProfileImpl::GetCacheParameters(bool is_media_context,
1258 base::FilePath* cache_path, 1256 base::FilePath* cache_path,
(...skipping 22 matching lines...) Expand all
1281 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) { 1279 ProfileImpl::CreateDomainReliabilityMonitor(PrefService* local_state) {
1282 domain_reliability::DomainReliabilityService* service = 1280 domain_reliability::DomainReliabilityService* service =
1283 domain_reliability::DomainReliabilityServiceFactory::GetInstance()-> 1281 domain_reliability::DomainReliabilityServiceFactory::GetInstance()->
1284 GetForBrowserContext(this); 1282 GetForBrowserContext(this);
1285 if (!service) 1283 if (!service)
1286 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>(); 1284 return scoped_ptr<domain_reliability::DomainReliabilityMonitor>();
1287 1285
1288 return service->CreateMonitor( 1286 return service->CreateMonitor(
1289 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 1287 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
1290 } 1288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698