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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 | 196 |
197 // static | 197 // static |
198 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 198 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
199 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, | 199 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, |
200 false, | 200 false, |
201 PrefService::UNSYNCABLE_PREF); | 201 PrefService::UNSYNCABLE_PREF); |
202 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 202 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
203 false, | 203 false, |
204 PrefService::SYNCABLE_PREF); | 204 PrefService::SYNCABLE_PREF); |
| 205 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, |
| 206 -1, |
| 207 PrefService::SYNCABLE_PREF); |
| 208 prefs->RegisterStringPref(prefs::kProfileName, |
| 209 "", |
| 210 PrefService::SYNCABLE_PREF); |
205 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | 211 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) |
206 prefs->RegisterIntegerPref(prefs::kLocalProfileId, | 212 prefs->RegisterIntegerPref(prefs::kLocalProfileId, |
207 kInvalidLocalProfileId, | 213 kInvalidLocalProfileId, |
208 PrefService::UNSYNCABLE_PREF); | 214 PrefService::UNSYNCABLE_PREF); |
209 // Notice that the preprocessor conditions above are exactly those that will | 215 // Notice that the preprocessor conditions above are exactly those that will |
210 // result in using PasswordStoreX in CreatePasswordStore() below. | 216 // result in using PasswordStoreX in CreatePasswordStore() below. |
211 PasswordStoreX::RegisterUserPrefs(prefs); | 217 PasswordStoreX::RegisterUserPrefs(prefs); |
212 #endif | 218 #endif |
213 } | 219 } |
214 | 220 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 void ProfileImpl::DoFinalInit() { | 273 void ProfileImpl::DoFinalInit() { |
268 PrefService* prefs = GetPrefs(); | 274 PrefService* prefs = GetPrefs(); |
269 pref_change_registrar_.Init(prefs); | 275 pref_change_registrar_.Init(prefs); |
270 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); | 276 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this); |
271 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); | 277 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); |
272 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); | 278 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); |
273 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); | 279 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); |
274 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 280 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
275 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); | 281 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); |
276 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); | 282 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); |
| 283 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); |
| 284 pref_change_registrar_.Add(prefs::kProfileName, this); |
277 | 285 |
278 // It would be nice to use PathService for fetching this directory, but | 286 // It would be nice to use PathService for fetching this directory, but |
279 // the cache directory depends on the profile directory, which isn't available | 287 // the cache directory depends on the profile directory, which isn't available |
280 // to PathService. | 288 // to PathService. |
281 chrome::GetUserCacheDirectory(path_, &base_cache_path_); | 289 chrome::GetUserCacheDirectory(path_, &base_cache_path_); |
282 if (!delegate_) { | 290 if (!delegate_) { |
283 if (!file_util::CreateDirectory(base_cache_path_)) | 291 if (!file_util::CreateDirectory(base_cache_path_)) |
284 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); | 292 LOG(FATAL) << "Failed to create " << base_cache_path_.value(); |
285 } else { | 293 } else { |
286 // Async profile loading is used, so call this on the FILE thread instead. | 294 // Async profile loading is used, so call this on the FILE thread instead. |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 if (webkit_context_) { | 1288 if (webkit_context_) { |
1281 webkit_context_->set_clear_local_state_on_exit( | 1289 webkit_context_->set_clear_local_state_on_exit( |
1282 clear_local_state_on_exit_); | 1290 clear_local_state_on_exit_); |
1283 } | 1291 } |
1284 if (db_tracker_) { | 1292 if (db_tracker_) { |
1285 db_tracker_->SetClearLocalStateOnExit( | 1293 db_tracker_->SetClearLocalStateOnExit( |
1286 clear_local_state_on_exit_); | 1294 clear_local_state_on_exit_); |
1287 } | 1295 } |
1288 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | 1296 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
1289 UpdateProfileUserNameCache(); | 1297 UpdateProfileUserNameCache(); |
| 1298 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { |
| 1299 UpdateProfileAvatarCache(); |
| 1300 } else if (*pref_name_in == prefs::kProfileName) { |
| 1301 UpdateProfileNameCache(); |
1290 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | 1302 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
1291 GetHostZoomMap()->set_default_zoom_level( | 1303 GetHostZoomMap()->set_default_zoom_level( |
1292 prefs->GetDouble(prefs::kDefaultZoomLevel)); | 1304 prefs->GetDouble(prefs::kDefaultZoomLevel)); |
1293 } | 1305 } |
1294 break; | 1306 break; |
1295 } | 1307 } |
1296 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 1308 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
1297 GetProfileSyncService(); // Causes lazy-load if sync is enabled. | 1309 GetProfileSyncService(); // Causes lazy-load if sync is enabled. |
1298 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 1310 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
1299 content::Source<Profile>(this)); | 1311 content::Source<Profile>(this)); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1585 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1574 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1586 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
1575 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); | 1587 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
1576 if (index != std::string::npos) { | 1588 if (index != std::string::npos) { |
1577 std::string user_name = | 1589 std::string user_name = |
1578 GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 1590 GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
1579 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); | 1591 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); |
1580 } | 1592 } |
1581 } | 1593 } |
1582 | 1594 |
| 1595 void ProfileImpl::UpdateProfileNameCache() { |
| 1596 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1597 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 1598 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
| 1599 if (index != std::string::npos) { |
| 1600 std::string profile_name = |
| 1601 GetPrefs()->GetString(prefs::kProfileName); |
| 1602 cache.SetNameOfProfileAtIndex(index, UTF8ToUTF16(profile_name)); |
| 1603 } |
| 1604 } |
| 1605 |
| 1606 void ProfileImpl::UpdateProfileAvatarCache() { |
| 1607 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1608 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 1609 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); |
| 1610 if (index != std::string::npos) { |
| 1611 size_t avatar_index = |
| 1612 GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 1613 cache.SetAvatarIconOfProfileAtIndex(index, avatar_index); |
| 1614 } |
| 1615 } |
| 1616 |
1583 // Gets the cache parameters from the command line. If |is_media_context| is | 1617 // Gets the cache parameters from the command line. If |is_media_context| is |
1584 // set to true then settings for the media context type is what we need, | 1618 // set to true then settings for the media context type is what we need, |
1585 // |cache_path| will be set to the user provided path, or will not be touched if | 1619 // |cache_path| will be set to the user provided path, or will not be touched if |
1586 // there is not an argument. |max_size| will be the user provided value or zero | 1620 // there is not an argument. |max_size| will be the user provided value or zero |
1587 // by default. | 1621 // by default. |
1588 void ProfileImpl::GetCacheParameters(bool is_media_context, | 1622 void ProfileImpl::GetCacheParameters(bool is_media_context, |
1589 FilePath* cache_path, | 1623 FilePath* cache_path, |
1590 int* max_size) { | 1624 int* max_size) { |
1591 DCHECK(cache_path); | 1625 DCHECK(cache_path); |
1592 DCHECK(max_size); | 1626 DCHECK(max_size); |
1593 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1627 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
1594 if (!path.empty()) | 1628 if (!path.empty()) |
1595 *cache_path = path; | 1629 *cache_path = path; |
1596 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1630 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1597 prefs_->GetInteger(prefs::kDiskCacheSize); | 1631 prefs_->GetInteger(prefs::kDiskCacheSize); |
1598 } | 1632 } |
OLD | NEW |