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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 } | 1359 } |
1360 } | 1360 } |
1361 */ | 1361 */ |
1362 return instant_promo_counter_.get(); | 1362 return instant_promo_counter_.get(); |
1363 #else | 1363 #else |
1364 return NULL; | 1364 return NULL; |
1365 #endif | 1365 #endif |
1366 } | 1366 } |
1367 | 1367 |
1368 #if defined(OS_CHROMEOS) | 1368 #if defined(OS_CHROMEOS) |
1369 void ProfileImpl::ChangeApplicationLocale( | 1369 void ProfileImpl::ChangeAppLocale( |
1370 const std::string& locale, bool keep_local) { | 1370 const std::string& new_locale, AppLocaleChangedVia via) { |
1371 if (locale.empty()) { | 1371 if (new_locale.empty()) { |
1372 NOTREACHED(); | 1372 NOTREACHED(); |
1373 return; | 1373 return; |
1374 } | 1374 } |
1375 if (keep_local) { | 1375 std::string pref_locale = GetPrefs()->GetString(prefs::kApplicationLocale); |
1376 GetPrefs()->SetString(prefs::kApplicationLocaleOverride, locale); | 1376 bool do_update_pref = true; |
1377 } else { | 1377 switch (via) { |
1378 GetPrefs()->SetString(prefs::kApplicationLocale, locale); | 1378 case APP_LOCALE_CHANGED_VIA_SETTINGS: |
1379 GetPrefs()->ClearPref(prefs::kApplicationLocaleOverride); | 1379 case APP_LOCALE_CHANGED_VIA_REVERT: { |
| 1380 // We keep kApplicationLocaleBackup value as a reference. In case value |
| 1381 // of kApplicationLocale preference would change due to sync from other |
| 1382 // device then kApplicationLocaleBackup value will trigger and allow us to |
| 1383 // show notification about automatic locale change in LocaleChangeGuard. |
| 1384 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, new_locale); |
| 1385 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted); |
| 1386 // We maintain kApplicationLocale property in both a global storage |
| 1387 // and user's profile. Global property determines locale of login screen, |
| 1388 // while user's profile determines his personal locale preference. |
| 1389 // In case of APP_LOCALE_CHANGED_VIA_LOGIN we won't touch local state |
| 1390 // because login screen code is active and takes care of it. |
| 1391 g_browser_process->local_state()->SetString( |
| 1392 prefs::kApplicationLocale, new_locale); |
| 1393 break; |
| 1394 } |
| 1395 case APP_LOCALE_CHANGED_VIA_LOGIN: { |
| 1396 if (!pref_locale.empty()) { |
| 1397 DCHECK(pref_locale == new_locale); |
| 1398 std::string accepted_locale = |
| 1399 GetPrefs()->GetString(prefs::kApplicationLocaleAccepted); |
| 1400 if (accepted_locale == new_locale) { |
| 1401 // If locale is accepted then we do not want to show LocaleChange |
| 1402 // notification. This notification is triggered by different values |
| 1403 // of kApplicationLocaleBackup and kApplicationLocale preferences, |
| 1404 // so make them identical. |
| 1405 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, new_locale); |
| 1406 } else { |
| 1407 // Back up locale of login screen. |
| 1408 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, |
| 1409 g_browser_process->GetApplicationLocale()); |
| 1410 } |
| 1411 } else { |
| 1412 std::string cur_locale = g_browser_process->GetApplicationLocale(); |
| 1413 std::string backup_locale = |
| 1414 GetPrefs()->GetString(prefs::kApplicationLocaleBackup); |
| 1415 // Profile synchronization takes time and is not completed at that |
| 1416 // moment at first login. So we initialize locale preference in steps: |
| 1417 // (1) first save it to temporary backup; |
| 1418 // (2) on next login we assume that synchronization is already completed |
| 1419 // and we may finalize initialization. |
| 1420 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, cur_locale); |
| 1421 if (!backup_locale.empty()) |
| 1422 GetPrefs()->SetString(prefs::kApplicationLocale, backup_locale); |
| 1423 do_update_pref = false; |
| 1424 } |
| 1425 break; |
| 1426 } |
| 1427 case APP_LOCALE_CHANGED_VIA_UNKNOWN: |
| 1428 default: { |
| 1429 NOTREACHED(); |
| 1430 break; |
| 1431 } |
1380 } | 1432 } |
1381 GetPrefs()->SetString(prefs::kApplicationLocaleBackup, locale); | 1433 if (do_update_pref) |
1382 GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted); | 1434 GetPrefs()->SetString(prefs::kApplicationLocale, new_locale); |
1383 // We maintain kApplicationLocale property in both a global storage | |
1384 // and user's profile. Global property determines locale of login screen, | |
1385 // while user's profile determines his personal locale preference. | |
1386 g_browser_process->local_state()->SetString( | |
1387 prefs::kApplicationLocale, locale); | |
1388 | 1435 |
1389 GetPrefs()->SavePersistentPrefs(); | 1436 GetPrefs()->ScheduleSavePersistentPrefs(); |
1390 g_browser_process->local_state()->SavePersistentPrefs(); | 1437 g_browser_process->local_state()->ScheduleSavePersistentPrefs(); |
1391 } | 1438 } |
1392 | 1439 |
1393 chromeos::ProxyConfigServiceImpl* | 1440 chromeos::ProxyConfigServiceImpl* |
1394 ProfileImpl::GetChromeOSProxyConfigServiceImpl() { | 1441 ProfileImpl::GetChromeOSProxyConfigServiceImpl() { |
1395 if (!chromeos_proxy_config_service_impl_) { | 1442 if (!chromeos_proxy_config_service_impl_) { |
1396 chromeos_proxy_config_service_impl_ = | 1443 chromeos_proxy_config_service_impl_ = |
1397 new chromeos::ProxyConfigServiceImpl(); | 1444 new chromeos::ProxyConfigServiceImpl(); |
1398 } | 1445 } |
1399 return chromeos_proxy_config_service_impl_; | 1446 return chromeos_proxy_config_service_impl_; |
1400 } | 1447 } |
(...skipping 13 matching lines...) Expand all Loading... |
1414 } | 1461 } |
1415 | 1462 |
1416 PrerenderManager* ProfileImpl::GetPrerenderManager() { | 1463 PrerenderManager* ProfileImpl::GetPrerenderManager() { |
1417 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1464 CommandLine* cl = CommandLine::ForCurrentProcess(); |
1418 if (!cl->HasSwitch(switches::kEnablePagePrerender)) | 1465 if (!cl->HasSwitch(switches::kEnablePagePrerender)) |
1419 return NULL; | 1466 return NULL; |
1420 if (!prerender_manager_) | 1467 if (!prerender_manager_) |
1421 prerender_manager_ = new PrerenderManager(this); | 1468 prerender_manager_ = new PrerenderManager(this); |
1422 return prerender_manager_; | 1469 return prerender_manager_; |
1423 } | 1470 } |
OLD | NEW |