| 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/chromeos/locale_change_guard.h" | 5 #include "chrome/browser/chromeos/locale_change_guard.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 chromeos::LocaleChangeGuard* master_; | 36 chromeos::LocaleChangeGuard* master_; |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(Delegate); | 38 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) | 41 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) |
| 42 : profile_(profile), | 42 : profile_(profile), |
| 43 note_(NULL), | 43 note_(NULL), |
| 44 reverted_(false) { | 44 reverted_(false) { |
| 45 DCHECK(profile_); | 45 DCHECK(profile_); |
| 46 registrar_.Add(this, NotificationType::OWNERSHIP_CHECKED, | 46 registrar_.Add(this, chrome::OWNERSHIP_CHECKED, |
| 47 NotificationService::AllSources()); | 47 NotificationService::AllSources()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 LocaleChangeGuard::~LocaleChangeGuard() {} | 50 LocaleChangeGuard::~LocaleChangeGuard() {} |
| 51 | 51 |
| 52 void LocaleChangeGuard::OnLogin() { | 52 void LocaleChangeGuard::OnLogin() { |
| 53 registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, | 53 registrar_.Add(this, chrome::LOAD_COMPLETED_MAIN_FRAME, |
| 54 NotificationService::AllSources()); | 54 NotificationService::AllSources()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { | 57 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { |
| 58 if (note_ == NULL || | 58 if (note_ == NULL || |
| 59 profile_ == NULL || | 59 profile_ == NULL || |
| 60 from_locale_.empty() || | 60 from_locale_.empty() || |
| 61 to_locale_.empty()) { | 61 to_locale_.empty()) { |
| 62 NOTREACHED(); | 62 NOTREACHED(); |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 if (reverted_) | 65 if (reverted_) |
| 66 return; | 66 return; |
| 67 reverted_ = true; | 67 reverted_ = true; |
| 68 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); | 68 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); |
| 69 profile_->ChangeAppLocale( | 69 profile_->ChangeAppLocale( |
| 70 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); | 70 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); |
| 71 | 71 |
| 72 Browser* browser = Browser::GetTabbedBrowser(profile_, false); | 72 Browser* browser = Browser::GetTabbedBrowser(profile_, false); |
| 73 if (browser) | 73 if (browser) |
| 74 browser->ExecuteCommand(IDC_EXIT); | 74 browser->ExecuteCommand(IDC_EXIT); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void LocaleChangeGuard::Observe(NotificationType type, | 77 void LocaleChangeGuard::Observe(int type, |
| 78 const NotificationSource& source, | 78 const NotificationSource& source, |
| 79 const NotificationDetails& details) { | 79 const NotificationDetails& details) { |
| 80 if (profile_ == NULL) { | 80 if (profile_ == NULL) { |
| 81 NOTREACHED(); | 81 NOTREACHED(); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 switch (type.value) { | 84 switch (type) { |
| 85 case NotificationType::LOAD_COMPLETED_MAIN_FRAME: { | 85 case chrome::LOAD_COMPLETED_MAIN_FRAME: { |
| 86 // We need to perform locale change check only once, so unsubscribe. | 86 // We need to perform locale change check only once, so unsubscribe. |
| 87 registrar_.Remove(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, | 87 registrar_.Remove(this, chrome::LOAD_COMPLETED_MAIN_FRAME, |
| 88 NotificationService::AllSources()); | 88 NotificationService::AllSources()); |
| 89 Check(); | 89 Check(); |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 case NotificationType::OWNERSHIP_CHECKED: { | 92 case chrome::OWNERSHIP_CHECKED: { |
| 93 if (UserManager::Get()->current_user_is_owner()) { | 93 if (UserManager::Get()->current_user_is_owner()) { |
| 94 PrefService* local_state = g_browser_process->local_state(); | 94 PrefService* local_state = g_browser_process->local_state(); |
| 95 if (local_state) { | 95 if (local_state) { |
| 96 PrefService* prefs = profile_->GetPrefs(); | 96 PrefService* prefs = profile_->GetPrefs(); |
| 97 if (prefs == NULL) { | 97 if (prefs == NULL) { |
| 98 NOTREACHED(); | 98 NOTREACHED(); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 std::string owner_locale = | 101 std::string owner_locale = |
| 102 prefs->GetString(prefs::kApplicationLocale); | 102 prefs->GetString(prefs::kApplicationLocale); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (by_user) | 220 if (by_user) |
| 221 master_->AcceptLocaleChange(); | 221 master_->AcceptLocaleChange(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 std::string LocaleChangeGuard::Delegate::id() const { | 224 std::string LocaleChangeGuard::Delegate::id() const { |
| 225 // Arbitrary unique Id. | 225 // Arbitrary unique Id. |
| 226 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; | 226 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace chromeos | 229 } // namespace chromeos |
| OLD | NEW |