| OLD | NEW |
| 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/chromeos/locale_change_guard.h" | 5 #include "chrome/browser/chromeos/locale_change_guard.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 9 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/command_line.h" | |
| 12 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 13 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 16 #include "chrome/browser/notifications/notification_delegate.h" | 14 #include "chrome/browser/notifications/notification_delegate.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 50 virtual ~Delegate() {} | 48 virtual ~Delegate() {} |
| 51 | 49 |
| 52 private: | 50 private: |
| 53 chromeos::LocaleChangeGuard* master_; | 51 chromeos::LocaleChangeGuard* master_; |
| 54 | 52 |
| 55 DISALLOW_COPY_AND_ASSIGN(Delegate); | 53 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) | 56 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) |
| 59 : profile_(profile), | 57 : profile_(profile), |
| 60 note_(NULL), | |
| 61 reverted_(false) { | 58 reverted_(false) { |
| 62 DCHECK(profile_); | 59 DCHECK(profile_); |
| 63 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 60 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, |
| 64 content::NotificationService::AllSources()); | 61 content::NotificationService::AllSources()); |
| 65 } | 62 } |
| 66 | 63 |
| 67 LocaleChangeGuard::~LocaleChangeGuard() {} | 64 LocaleChangeGuard::~LocaleChangeGuard() {} |
| 68 | 65 |
| 69 void LocaleChangeGuard::OnLogin() { | 66 void LocaleChangeGuard::OnLogin() { |
| 70 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 67 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 break; | 127 break; |
| 131 } | 128 } |
| 132 default: { | 129 default: { |
| 133 NOTREACHED(); | 130 NOTREACHED(); |
| 134 break; | 131 break; |
| 135 } | 132 } |
| 136 } | 133 } |
| 137 } | 134 } |
| 138 | 135 |
| 139 void LocaleChangeGuard::Check() { | 136 void LocaleChangeGuard::Check() { |
| 140 if (note_ != NULL) { | |
| 141 // Somehow we are invoked more than once. Once is enough. | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 std::string cur_locale = g_browser_process->GetApplicationLocale(); | 137 std::string cur_locale = g_browser_process->GetApplicationLocale(); |
| 146 if (cur_locale.empty()) { | 138 if (cur_locale.empty()) { |
| 147 NOTREACHED(); | 139 NOTREACHED(); |
| 148 return; | 140 return; |
| 149 } | 141 } |
| 150 | 142 |
| 151 PrefService* prefs = profile_->GetPrefs(); | 143 PrefService* prefs = profile_->GetPrefs(); |
| 152 if (prefs == NULL) { | 144 if (prefs == NULL) { |
| 153 NOTREACHED(); | 145 NOTREACHED(); |
| 154 return; | 146 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 170 return; // Already accepted. | 162 return; // Already accepted. |
| 171 | 163 |
| 172 // Locale change detected, showing notification. | 164 // Locale change detected, showing notification. |
| 173 if (from_locale_ != from_locale || to_locale_ != to_locale) { | 165 if (from_locale_ != from_locale || to_locale_ != to_locale) { |
| 174 // Falling back to showing message in current locale. | 166 // Falling back to showing message in current locale. |
| 175 LOG(ERROR) << | 167 LOG(ERROR) << |
| 176 "Showing locale change notification in current (not previous) language"; | 168 "Showing locale change notification in current (not previous) language"; |
| 177 PrepareChangingLocale(from_locale, to_locale); | 169 PrepareChangingLocale(from_locale, to_locale); |
| 178 } | 170 } |
| 179 | 171 |
| 180 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 172 ash::Shell::GetInstance()->system_tray()->locale_observer()-> |
| 181 ash::switches::kAshNotifyDisabled)) { | 173 OnLocaleChanged(this, cur_locale, from_locale_, to_locale_); |
| 182 ash::Shell::GetInstance()->system_tray()->locale_observer()-> | |
| 183 OnLocaleChanged(this, cur_locale, from_locale_, to_locale_); | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 note_.reset(new chromeos::SystemNotification( | |
| 188 profile_, | |
| 189 new Delegate(this), | |
| 190 IDR_NOTIFICATION_LOCALE_CHANGE, | |
| 191 title_text_)); | |
| 192 note_->Show( | |
| 193 message_text_, revert_link_text_, | |
| 194 base::Bind(&LocaleChangeGuard::RevertLocaleChangeCallback, | |
| 195 AsWeakPtr()), | |
| 196 true, // urgent | |
| 197 false); // non-sticky | |
| 198 } | 174 } |
| 199 | 175 |
| 200 void LocaleChangeGuard::AcceptLocaleChange() { | 176 void LocaleChangeGuard::AcceptLocaleChange() { |
| 201 if (profile_ == NULL || | 177 if (profile_ == NULL || |
| 202 from_locale_.empty() || | 178 from_locale_.empty() || |
| 203 to_locale_.empty()) { | 179 to_locale_.empty()) { |
| 204 NOTREACHED(); | 180 NOTREACHED(); |
| 205 return; | 181 return; |
| 206 } | 182 } |
| 207 | 183 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (by_user) | 224 if (by_user) |
| 249 master_->AcceptLocaleChange(); | 225 master_->AcceptLocaleChange(); |
| 250 } | 226 } |
| 251 | 227 |
| 252 std::string LocaleChangeGuard::Delegate::id() const { | 228 std::string LocaleChangeGuard::Delegate::id() const { |
| 253 // Arbitrary unique Id. | 229 // Arbitrary unique Id. |
| 254 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; | 230 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; |
| 255 } | 231 } |
| 256 | 232 |
| 257 } // namespace chromeos | 233 } // namespace chromeos |
| OLD | NEW |