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

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

Issue 23095006: If user profile doesn't contain language setting, default to his Google account settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix shared build. Created 7 years, 4 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 11 matching lines...) Expand all
22 #include "base/synchronization/waitable_event.h" 22 #include "base/synchronization/waitable_event.h"
23 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
24 #include "base/version.h" 24 #include "base/version.h"
25 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 25 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
26 #include "chrome/browser/background/background_contents_service_factory.h" 26 #include "chrome/browser/background/background_contents_service_factory.h"
27 #include "chrome/browser/background/background_mode_manager.h" 27 #include "chrome/browser/background/background_mode_manager.h"
28 #include "chrome/browser/bookmarks/bookmark_model.h" 28 #include "chrome/browser/bookmarks/bookmark_model.h"
29 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 29 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
30 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chrome_notification_types.h" 31 #include "chrome/browser/chrome_notification_types.h"
32 #include "chrome/browser/chromeos/login/language_switch_menu.h"
32 #include "chrome/browser/content_settings/cookie_settings.h" 33 #include "chrome/browser/content_settings/cookie_settings.h"
33 #include "chrome/browser/content_settings/host_content_settings_map.h" 34 #include "chrome/browser/content_settings/host_content_settings_map.h"
34 #include "chrome/browser/download/chrome_download_manager_delegate.h" 35 #include "chrome/browser/download/chrome_download_manager_delegate.h"
35 #include "chrome/browser/download/download_service.h" 36 #include "chrome/browser/download/download_service.h"
36 #include "chrome/browser/download/download_service_factory.h" 37 #include "chrome/browser/download/download_service_factory.h"
37 #include "chrome/browser/extensions/extension_pref_store.h" 38 #include "chrome/browser/extensions/extension_pref_store.h"
38 #include "chrome/browser/extensions/extension_pref_value_map.h" 39 #include "chrome/browser/extensions/extension_pref_value_map.h"
39 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" 40 #include "chrome/browser/extensions/extension_pref_value_map_factory.h"
40 #include "chrome/browser/extensions/extension_service.h" 41 #include "chrome/browser/extensions/extension_service.h"
41 #include "chrome/browser/extensions/extension_special_storage_policy.h" 42 #include "chrome/browser/extensions/extension_special_storage_policy.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Make sure that the ProfileImpl doesn't grow. We're currently trying to drive 136 // Make sure that the ProfileImpl doesn't grow. We're currently trying to drive
136 // the number of services that are included in ProfileImpl (instead of using 137 // the number of services that are included in ProfileImpl (instead of using
137 // BrowserContextKeyedServiceFactory) to zero. 138 // BrowserContextKeyedServiceFactory) to zero.
138 // 139 //
139 // If you don't know about this effort, please read: 140 // If you don't know about this effort, please read:
140 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/pro file-architecture 141 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/pro file-architecture
141 // 142 //
142 // REVIEWERS: Do not let anyone increment this. We need to drive the number of 143 // REVIEWERS: Do not let anyone increment this. We need to drive the number of
143 // raw accessed services down to zero. DO NOT LET PEOPLE REGRESS THIS UNLESS 144 // raw accessed services down to zero. DO NOT LET PEOPLE REGRESS THIS UNLESS
144 // THE PATCH ITSELF IS MAKING PROGRESS ON PKSF REFACTORING. 145 // THE PATCH ITSELF IS MAKING PROGRESS ON PKSF REFACTORING.
145 COMPILE_ASSERT(sizeof(ProfileImpl) <= 744u, profile_impl_size_unexpected); 146 COMPILE_ASSERT(sizeof(ProfileImpl) <= 744u, profile_impl_size_unexpected);
sail 2013/08/23 17:08:48 Your CL will probably break this assert. Could you
Alexander Alekseev 2013/09/06 19:52:08 Done.
146 #endif 147 #endif
147 148
148 #if defined(ENABLE_SESSION_SERVICE) 149 #if defined(ENABLE_SESSION_SERVICE)
149 // Delay, in milliseconds, before we explicitly create the SessionService. 150 // Delay, in milliseconds, before we explicitly create the SessionService.
150 static const int kCreateSessionServiceDelayMS = 500; 151 static const int kCreateSessionServiceDelayMS = 500;
151 #endif 152 #endif
152 153
153 // Text content of README file created in each profile directory. Both %s 154 // Text content of README file created in each profile directory. Both %s
154 // placeholders must contain the product name. This is not localizable and hence 155 // placeholders must contain the product name. This is not localizable and hence
155 // not in resources. 156 // not in resources.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 CreateMode create_mode, 355 CreateMode create_mode,
355 base::SequencedTaskRunner* sequenced_task_runner) 356 base::SequencedTaskRunner* sequenced_task_runner)
356 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, 357 : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged,
357 base::Unretained(this))), 358 base::Unretained(this))),
358 path_(path), 359 path_(path),
359 pref_registry_(new user_prefs::PrefRegistrySyncable), 360 pref_registry_(new user_prefs::PrefRegistrySyncable),
360 io_data_(this), 361 io_data_(this),
361 host_content_settings_map_(NULL), 362 host_content_settings_map_(NULL),
362 last_session_exit_type_(EXIT_NORMAL), 363 last_session_exit_type_(EXIT_NORMAL),
363 start_time_(Time::Now()), 364 start_time_(Time::Now()),
365 #if defined(OS_CHROMEOS)
366 is_created_(false),
367 #endif
364 delegate_(delegate), 368 delegate_(delegate),
365 predictor_(NULL) { 369 predictor_(NULL) {
366 TRACE_EVENT0("browser", "ProfileImpl::ctor") 370 TRACE_EVENT0("browser", "ProfileImpl::ctor")
367 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 371 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
368 "profile files to the root directory!"; 372 "profile files to the root directory!";
369 373
370 #if defined(ENABLE_SESSION_SERVICE) 374 #if defined(ENABLE_SESSION_SERVICE)
371 create_session_service_timer_.Start(FROM_HERE, 375 create_session_service_timer_.Start(FROM_HERE,
372 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 376 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
373 &ProfileImpl::EnsureSessionServiceCreated); 377 &ProfileImpl::EnsureSessionServiceCreated);
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 void ProfileImpl::StopCreateSessionServiceTimer() { 984 void ProfileImpl::StopCreateSessionServiceTimer() {
981 create_session_service_timer_.Stop(); 985 create_session_service_timer_.Stop();
982 } 986 }
983 987
984 void ProfileImpl::EnsureSessionServiceCreated() { 988 void ProfileImpl::EnsureSessionServiceCreated() {
985 SessionServiceFactory::GetForProfile(this); 989 SessionServiceFactory::GetForProfile(this);
986 } 990 }
987 #endif 991 #endif
988 992
989 #if defined(OS_CHROMEOS) 993 #if defined(OS_CHROMEOS)
994 void ProfileImpl::MarkCreated() {
995 is_created_ = true;
996 }
997
990 void ProfileImpl::ChangeAppLocale( 998 void ProfileImpl::ChangeAppLocale(
991 const std::string& new_locale, AppLocaleChangedVia via) { 999 const std::string& new_locale, AppLocaleChangedVia via) {
992 if (new_locale.empty()) { 1000 if (new_locale.empty()) {
993 NOTREACHED(); 1001 NOTREACHED();
994 return; 1002 return;
995 } 1003 }
996 PrefService* local_state = g_browser_process->local_state(); 1004 PrefService* local_state = g_browser_process->local_state();
997 DCHECK(local_state); 1005 DCHECK(local_state);
998 if (local_state->IsManagedPreference(prefs::kApplicationLocale)) 1006 if (local_state->IsManagedPreference(prefs::kApplicationLocale))
999 return; 1007 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 } else { 1043 } else {
1036 std::string cur_locale = g_browser_process->GetApplicationLocale(); 1044 std::string cur_locale = g_browser_process->GetApplicationLocale();
1037 std::string backup_locale = 1045 std::string backup_locale =
1038 GetPrefs()->GetString(prefs::kApplicationLocaleBackup); 1046 GetPrefs()->GetString(prefs::kApplicationLocaleBackup);
1039 // Profile synchronization takes time and is not completed at that 1047 // Profile synchronization takes time and is not completed at that
1040 // moment at first login. So we initialize locale preference in steps: 1048 // moment at first login. So we initialize locale preference in steps:
1041 // (1) first save it to temporary backup; 1049 // (1) first save it to temporary backup;
1042 // (2) on next login we assume that synchronization is already completed 1050 // (2) on next login we assume that synchronization is already completed
1043 // and we may finalize initialization. 1051 // and we may finalize initialization.
1044 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, cur_locale); 1052 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, cur_locale);
1045 if (!backup_locale.empty()) 1053 if (!new_locale.empty())
1054 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale);
1055 else if (!backup_locale.empty())
1046 GetPrefs()->SetString(prefs::kApplicationLocale, backup_locale); 1056 GetPrefs()->SetString(prefs::kApplicationLocale, backup_locale);
1047 do_update_pref = false; 1057 do_update_pref = false;
1048 } 1058 }
1049 break; 1059 break;
1050 } 1060 }
1051 case APP_LOCALE_CHANGED_VIA_UNKNOWN: 1061 case APP_LOCALE_CHANGED_VIA_UNKNOWN:
1052 default: { 1062 default: {
1053 NOTREACHED(); 1063 NOTREACHED();
1054 break; 1064 break;
1055 } 1065 }
1056 } 1066 }
1057 if (do_update_pref) 1067 if (do_update_pref)
1058 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale); 1068 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale);
1059 local_state->SetString(prefs::kApplicationLocale, new_locale); 1069 local_state->SetString(prefs::kApplicationLocale, new_locale);
1060 1070
1061 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) 1071 if (chromeos::UserManager::Get()->IsCurrentUserOwner())
1062 local_state->SetString(prefs::kOwnerLocale, new_locale); 1072 local_state->SetString(prefs::kOwnerLocale, new_locale);
1063 } 1073 }
1064 1074
1075 void ProfileImpl::SetGPlusProfileLocale(const std::string& gplus_locale) {
1076 gplus_locale_.reset(new std::string);
1077 // Ignore result
1078 l10n_util::CheckAndResolveLocale(gplus_locale, gplus_locale_.get());
jungshik at Google 2013/08/26 16:42:50 This does not take into account the preferred lang
Alexander Alekseev 2013/09/06 19:52:08 I like the idea, but I couldn't find "list of lang
jungshik at Google 2013/09/18 08:50:04 Thanks for digging that up. I've alerted an engine
1079 RespectLocalePreference();
1080 }
1081
1082 void ProfileImpl::RespectLocalePreference() {
1083 PrefService* prefs = GetPrefs();
1084 DCHECK(prefs != NULL);
1085 if (g_browser_process == NULL)
1086 return;
1087
1088 if (!is_created_)
1089 return;
1090
1091 if (gplus_locale_ == NULL)
1092 return;
1093
1094 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale);
1095 if (pref_locale.empty())
1096 pref_locale = prefs->GetString(prefs::kApplicationLocaleBackup);
1097 if (pref_locale.empty())
1098 pref_locale = *gplus_locale_;
1099 if (pref_locale.empty())
1100 pref_locale = g_browser_process->GetApplicationLocale();
1101 DCHECK(!pref_locale.empty());
1102 ChangeAppLocale(pref_locale, APP_LOCALE_CHANGED_VIA_LOGIN);
1103 // Here we don't enable keyboard layouts. Input methods are set up when
1104 // the user first logs in. Then the user may customize the input methods.
1105 // Hence changing input methods here, just because the user's UI language
1106 // is different from the login screen UI language, is not desirable. Note
1107 // that input method preferences are synced, so users can use their
1108 // farovite input methods as soon as the preferences are synced.
1109 chromeos::LanguageSwitchMenu::SwitchLanguage(pref_locale);
1110 }
1111
1065 void ProfileImpl::OnLogin() { 1112 void ProfileImpl::OnLogin() {
1066 if (locale_change_guard_ == NULL) 1113 if (locale_change_guard_ == NULL)
1067 locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this)); 1114 locale_change_guard_.reset(new chromeos::LocaleChangeGuard(this));
1068 locale_change_guard_->OnLogin(); 1115 locale_change_guard_->OnLogin();
1069 } 1116 }
1070 1117
1071 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() { 1118 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() {
1072 DCHECK(!chromeos_enterprise_extension_observer_); 1119 DCHECK(!chromeos_enterprise_extension_observer_);
1073 chromeos_enterprise_extension_observer_.reset( 1120 chromeos_enterprise_extension_observer_.reset(
1074 new chromeos::EnterpriseExtensionObserver(this)); 1121 new chromeos::EnterpriseExtensionObserver(this));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() { 1222 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() {
1176 #if defined(OS_CHROMEOS) 1223 #if defined(OS_CHROMEOS)
1177 if (chromeos::ProfileHelper::IsSigninProfile(this)) { 1224 if (chromeos::ProfileHelper::IsSigninProfile(this)) {
1178 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 1225 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
1179 g_browser_process->local_state()); 1226 g_browser_process->local_state());
1180 } 1227 }
1181 #endif // defined(OS_CHROMEOS) 1228 #endif // defined(OS_CHROMEOS)
1182 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( 1229 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
1183 GetPrefs(), g_browser_process->local_state()); 1230 GetPrefs(), g_browser_process->local_state());
1184 } 1231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698