| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 209 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
| 210 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, | 210 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, |
| 211 false, | 211 false, |
| 212 PrefService::UNSYNCABLE_PREF); | 212 PrefService::UNSYNCABLE_PREF); |
| 213 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 213 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
| 214 false, | 214 false, |
| 215 PrefService::SYNCABLE_PREF); | 215 PrefService::SYNCABLE_PREF); |
| 216 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, |
| 217 -1, |
| 218 PrefService::SYNCABLE_PREF); |
| 219 prefs->RegisterStringPref(prefs::kProfileName, |
| 220 "", |
| 221 PrefService::SYNCABLE_PREF); |
| 216 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | 222 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) |
| 217 prefs->RegisterIntegerPref(prefs::kLocalProfileId, | 223 prefs->RegisterIntegerPref(prefs::kLocalProfileId, |
| 218 kInvalidLocalProfileId, | 224 kInvalidLocalProfileId, |
| 219 PrefService::UNSYNCABLE_PREF); | 225 PrefService::UNSYNCABLE_PREF); |
| 220 // Notice that the preprocessor conditions above are exactly those that will | 226 // Notice that the preprocessor conditions above are exactly those that will |
| 221 // result in using PasswordStoreX in CreatePasswordStore() below. | 227 // result in using PasswordStoreX in CreatePasswordStore() below. |
| 222 PasswordStoreX::RegisterUserPrefs(prefs); | 228 PasswordStoreX::RegisterUserPrefs(prefs); |
| 223 #endif | 229 #endif |
| 224 } | 230 } |
| 225 | 231 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 void ProfileImpl::DoFinalInit() { | 287 void ProfileImpl::DoFinalInit() { |
| 282 PrefService* prefs = GetPrefs(); | 288 PrefService* prefs = GetPrefs(); |
| 283 pref_change_registrar_.Init(prefs); | 289 pref_change_registrar_.Init(prefs); |
| 284 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); | 290 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); |
| 285 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); | 291 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); |
| 286 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); | 292 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); |
| 287 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); | 293 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); |
| 288 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 294 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
| 289 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); | 295 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); |
| 290 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); | 296 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); |
| 297 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); |
| 298 pref_change_registrar_.Add(prefs::kProfileName, this); |
| 291 | 299 |
| 292 // It would be nice to use PathService for fetching this directory, but | 300 // It would be nice to use PathService for fetching this directory, but |
| 293 // the cache directory depends on the profile directory, which isn't available | 301 // the cache directory depends on the profile directory, which isn't available |
| 294 // to PathService. | 302 // to PathService. |
| 295 chrome::GetUserCacheDirectory(path_, &base_cache_path_); | 303 chrome::GetUserCacheDirectory(path_, &base_cache_path_); |
| 296 if (!delegate_) { | 304 if (!delegate_) { |
| 297 if (!file_util::CreateDirectory(base_cache_path_)) | 305 if (!file_util::CreateDirectory(base_cache_path_)) |
| 298 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); | 306 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); |
| 299 } else { | 307 } else { |
| 300 // Async profile loading is used, so call this on the FILE thread instead. | 308 // Async profile loading is used, so call this on the FILE thread instead. |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 if (webkit_context_) { | 1322 if (webkit_context_) { |
| 1315 webkit_context_->set_clear_local_state_on_exit( | 1323 webkit_context_->set_clear_local_state_on_exit( |
| 1316 clear_local_state_on_exit_); | 1324 clear_local_state_on_exit_); |
| 1317 } | 1325 } |
| 1318 if (db_tracker_) { | 1326 if (db_tracker_) { |
| 1319 db_tracker_->SetClearLocalStateOnExit( | 1327 db_tracker_->SetClearLocalStateOnExit( |
| 1320 clear_local_state_on_exit_); | 1328 clear_local_state_on_exit_); |
| 1321 } | 1329 } |
| 1322 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | 1330 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
| 1323 UpdateProfileUserNameCache(); | 1331 UpdateProfileUserNameCache(); |
| 1332 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { |
| 1333 UpdateProfileAvatarCache(); |
| 1334 } else if (*pref_name_in == prefs::kProfileName) { |
| 1335 UpdateProfileNameCache(); |
| 1324 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | 1336 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
| 1325 GetHostZoomMap()->set_default_zoom_level( | 1337 GetHostZoomMap()->set_default_zoom_level( |
| 1326 prefs->GetDouble(prefs::kDefaultZoomLevel)); | 1338 prefs->GetDouble(prefs::kDefaultZoomLevel)); |
| 1327 } | 1339 } |
| 1328 break; | 1340 break; |
| 1329 } | 1341 } |
| 1330 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 1342 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
| 1331 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1343 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
| 1332 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 1344 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
| 1333 content::Source<Profile>(this)); | 1345 content::Source<Profile>(this)); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1634 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1623 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1635 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 1624 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1636 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
| 1625 if (index != std::string::npos) { | 1637 if (index != std::string::npos) { |
| 1626 std::string user_name = | 1638 std::string user_name = |
| 1627 GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 1639 GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 1628 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); | 1640 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); |
| 1629 } | 1641 } |
| 1630 } | 1642 } |
| 1631 | 1643 |
| 1644 void ProfileImpl::UpdateProfileNameCache() { |
| 1645 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1646 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 1647 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
| 1648 if (index != std::string::npos) { |
| 1649 std::string profile_name = |
| 1650 GetPrefs()->GetString(prefs::kProfileName); |
| 1651 cache.SetNameOfProfileAtIndex(index, UTF8ToUTF16(profile_name)); |
| 1652 } |
| 1653 } |
| 1654 |
| 1655 void ProfileImpl::UpdateProfileAvatarCache() { |
| 1656 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1657 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 1658 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
| 1659 if (index != std::string::npos) { |
| 1660 size_t avatar_index = |
| 1661 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 1662 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index); |
| 1663 } |
| 1664 } |
| 1665 |
| 1632 // Gets the cache parameters from the command line. If |is_media_context| is | 1666 // Gets the cache parameters from the command line. If |is_media_context| is |
| 1633 // set to true then settings for the media context type is what we need, | 1667 // set to true then settings for the media context type is what we need, |
| 1634 // |cache_path| will be set to the user provided path, or will not be touched if | 1668 // |cache_path| will be set to the user provided path, or will not be touched if |
| 1635 // there is not an argument. |max_size| will be the user provided value or zero | 1669 // there is not an argument. |max_size| will be the user provided value or zero |
| 1636 // by default. | 1670 // by default. |
| 1637 void ProfileImpl::GetCacheParameters(bool is_media_context, | 1671 void ProfileImpl::GetCacheParameters(bool is_media_context, |
| 1638 FilePath* cache_path, | 1672 FilePath* cache_path, |
| 1639 int* max_size) { | 1673 int* max_size) { |
| 1640 DCHECK(cache_path); | 1674 DCHECK(cache_path); |
| 1641 DCHECK(max_size); | 1675 DCHECK(max_size); |
| 1642 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1676 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
| 1643 if (!path.empty()) | 1677 if (!path.empty()) |
| 1644 *cache_path = path; | 1678 *cache_path = path; |
| 1645 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1679 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1646 prefs_->GetInteger(prefs::kDiskCacheSize); | 1680 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1647 } | 1681 } |
| OLD | NEW |