OLD | NEW |
1 // Copyright (c) 2010 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/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void LoginUtilsImpl::FetchTokens( | 322 void LoginUtilsImpl::FetchTokens( |
323 Profile* profile, | 323 Profile* profile, |
324 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 324 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
325 TokenService* token_service = profile->GetTokenService(); | 325 TokenService* token_service = profile->GetTokenService(); |
326 token_service->UpdateCredentials(credentials); | 326 token_service->UpdateCredentials(credentials); |
327 if (token_service->AreCredentialsValid()) { | 327 if (token_service->AreCredentialsValid()) { |
328 token_service->StartFetchingTokens(); | 328 token_service->StartFetchingTokens(); |
329 } | 329 } |
330 } | 330 } |
331 | 331 |
332 void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) { | 332 void LoginUtilsImpl::RespectLocalePreference(PrefService* prefs) { |
333 std::string pref_locale = pref->GetString(prefs::kApplicationLocale); | 333 DCHECK(prefs != NULL); |
334 if (pref_locale.empty()) { | 334 std::string pref_locale_override = |
335 // Profile synchronization takes time and is not completed at that moment | 335 prefs->GetString(prefs::kApplicationLocaleOverride); |
336 // at first login. So we initialize locale preference in steps: | 336 if (!pref_locale_override.empty()) { |
337 // (1) first save it to temporary backup; | 337 LanguageSwitchMenu::SwitchLanguage(pref_locale_override); |
338 // (2) on next login we assume that synchronization is already completed | 338 return; |
339 // and we may finalize initialization. | 339 } |
340 std::string pref_locale_backup = | 340 |
341 pref->GetString(prefs::kApplicationLocaleBackup); | 341 if (g_browser_process == NULL) |
342 if (pref_locale_backup.empty()) { | 342 return; |
343 pref->SetString(prefs::kApplicationLocaleBackup, | 343 std::string cur_locale = g_browser_process->GetApplicationLocale(); |
344 g_browser_process->GetApplicationLocale()); | 344 |
345 return; | 345 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); |
| 346 if (!pref_locale.empty()) { |
| 347 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == pref_locale) { |
| 348 // If locale is accepted then we do not want to show LocaleChange |
| 349 // notification. This notification is triggered by different values of |
| 350 // kApplicationLocaleBackup and kApplicationLocale preferences, |
| 351 // so make them identical. |
| 352 prefs->SetString(prefs::kApplicationLocaleBackup, pref_locale); |
346 } else { | 353 } else { |
347 pref_locale.swap(pref_locale_backup); | 354 std::string pref_locale_backup = |
348 pref->SetString(prefs::kApplicationLocale, pref_locale); | 355 prefs->GetString(prefs::kApplicationLocaleBackup); |
| 356 if (pref_locale_backup != cur_locale) { |
| 357 if (pref_locale_backup == pref_locale || pref_locale_backup.empty()) { |
| 358 prefs->SetString(prefs::kApplicationLocaleBackup, cur_locale); |
| 359 } |
| 360 } |
349 } | 361 } |
| 362 LanguageSwitchMenu::SwitchLanguage(pref_locale); |
| 363 return; |
350 } | 364 } |
351 LanguageSwitchMenu::SwitchLanguage(pref_locale); | 365 // Profile synchronization takes time and is not completed at that moment |
| 366 // at first login. So we initialize locale preference in steps: |
| 367 // (1) first save it to temporary backup; |
| 368 // (2) on next login we assume that synchronization is already completed |
| 369 // and we may finalize initialization. |
| 370 std::string pref_locale_backup = |
| 371 prefs->GetString(prefs::kApplicationLocaleBackup); |
| 372 prefs->SetString(prefs::kApplicationLocaleBackup, cur_locale); |
| 373 prefs->ScheduleSavePersistentPrefs(); |
| 374 if (!pref_locale_backup.empty()) { |
| 375 prefs->SetString(prefs::kApplicationLocale, pref_locale_backup); |
| 376 prefs->ScheduleSavePersistentPrefs(); |
| 377 LanguageSwitchMenu::SwitchLanguage(pref_locale_backup); |
| 378 } |
352 } | 379 } |
353 | 380 |
354 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { | 381 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { |
355 VLOG(1) << "Completing off the record login"; | 382 VLOG(1) << "Completing off the record login"; |
356 | 383 |
357 UserManager::Get()->OffTheRecordUserLoggedIn(); | 384 UserManager::Get()->OffTheRecordUserLoggedIn(); |
358 | 385 |
359 if (CrosLibrary::Get()->EnsureLoaded()) { | 386 if (CrosLibrary::Get()->EnsureLoaded()) { |
360 // For guest session we ask session manager to restart Chrome with --bwsi | 387 // For guest session we ask session manager to restart Chrome with --bwsi |
361 // flag. We keep only some of the arguments of this process. | 388 // flag. We keep only some of the arguments of this process. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 BrowserInit browser_init; | 553 BrowserInit browser_init; |
527 int return_code; | 554 int return_code; |
528 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 555 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
529 profile, | 556 profile, |
530 FilePath(), | 557 FilePath(), |
531 true, | 558 true, |
532 &return_code); | 559 &return_code); |
533 } | 560 } |
534 | 561 |
535 } // namespace chromeos | 562 } // namespace chromeos |
OLD | NEW |