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

Side by Side Diff: chrome/browser/chromeos/locale_change_guard.cc

Issue 10391177: Add TrayLocale for locale change notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase w/ icons in tot Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/locale_change_guard.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
9 #include "ash/system/tray/system_tray.h"
7 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 15 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/notifications/notification_delegate.h" 16 #include "chrome/browser/notifications/notification_delegate.h"
13 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 content::NotificationService::AllSources()); 57 content::NotificationService::AllSources());
54 } 58 }
55 59
56 LocaleChangeGuard::~LocaleChangeGuard() {} 60 LocaleChangeGuard::~LocaleChangeGuard() {}
57 61
58 void LocaleChangeGuard::OnLogin() { 62 void LocaleChangeGuard::OnLogin() {
59 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 63 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
60 content::NotificationService::AllBrowserContextsAndSources()); 64 content::NotificationService::AllBrowserContextsAndSources());
61 } 65 }
62 66
63 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { 67 void LocaleChangeGuard::RevertLocaleChange() {
64 if (note_ == NULL || 68 if (note_ == NULL ||
65 profile_ == NULL || 69 profile_ == NULL ||
66 from_locale_.empty() || 70 from_locale_.empty() ||
67 to_locale_.empty()) { 71 to_locale_.empty()) {
68 NOTREACHED(); 72 NOTREACHED();
69 return; 73 return;
70 } 74 }
71 if (reverted_) 75 if (reverted_)
72 return; 76 return;
73 reverted_ = true; 77 reverted_ = true;
74 content::RecordAction(UserMetricsAction("LanguageChange_Revert")); 78 content::RecordAction(UserMetricsAction("LanguageChange_Revert"));
75 profile_->ChangeAppLocale( 79 profile_->ChangeAppLocale(
76 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); 80 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT);
77 81
78 Browser* browser = browser::FindTabbedBrowser(profile_, false); 82 Browser* browser = browser::FindTabbedBrowser(profile_, false);
79 if (browser) 83 if (browser)
80 browser->ExecuteCommand(IDC_EXIT); 84 browser->ExecuteCommand(IDC_EXIT);
81 } 85 }
82 86
87 void LocaleChangeGuard::RevertLocaleChangeCallback(const ListValue* list) {
88 RevertLocaleChange();
89 }
90
83 void LocaleChangeGuard::Observe(int type, 91 void LocaleChangeGuard::Observe(int type,
84 const content::NotificationSource& source, 92 const content::NotificationSource& source,
85 const content::NotificationDetails& details) { 93 const content::NotificationDetails& details) {
86 if (profile_ == NULL) { 94 if (profile_ == NULL) {
87 NOTREACHED(); 95 NOTREACHED();
88 return; 96 return;
89 } 97 }
90 switch (type) { 98 switch (type) {
91 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { 99 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: {
92 if (profile_ == 100 if (profile_ ==
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale) 163 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale)
156 return; // Already accepted. 164 return; // Already accepted.
157 165
158 // Locale change detected, showing notification. 166 // Locale change detected, showing notification.
159 if (from_locale_ != from_locale || to_locale_ != to_locale) { 167 if (from_locale_ != from_locale || to_locale_ != to_locale) {
160 // Falling back to showing message in current locale. 168 // Falling back to showing message in current locale.
161 LOG(ERROR) << 169 LOG(ERROR) <<
162 "Showing locale change notification in current (not previous) language"; 170 "Showing locale change notification in current (not previous) language";
163 PrepareChangingLocale(from_locale, to_locale); 171 PrepareChangingLocale(from_locale, to_locale);
164 } 172 }
173
174 if (CommandLine::ForCurrentProcess()->HasSwitch(ash::switches::kAshNotify)) {
175 ash::Shell::GetInstance()->tray()->locale_observer()->OnLocaleChanged(
176 this, cur_locale, from_locale_, to_locale_);
177 return;
178 }
179
165 note_.reset(new chromeos::SystemNotification( 180 note_.reset(new chromeos::SystemNotification(
166 profile_, 181 profile_,
167 new Delegate(this), 182 new Delegate(this),
168 IDR_NOTIFICATION_LOCALE_CHANGE, 183 IDR_NOTIFICATION_LOCALE_CHANGE,
169 title_text_)); 184 title_text_));
170 note_->Show( 185 note_->Show(
171 message_text_, revert_link_text_, 186 message_text_, revert_link_text_,
172 base::Bind(&LocaleChangeGuard::RevertLocaleChange, 187 base::Bind(&LocaleChangeGuard::RevertLocaleChangeCallback,
173 AsWeakPtr()), 188 AsWeakPtr()),
174 true, // urgent 189 true, // urgent
175 false); // non-sticky 190 false); // non-sticky
176 } 191 }
177 192
178 void LocaleChangeGuard::AcceptLocaleChange() { 193 void LocaleChangeGuard::AcceptLocaleChange() {
179 if (note_ == NULL || 194 if (note_ == NULL ||
180 profile_ == NULL || 195 profile_ == NULL ||
181 from_locale_.empty() || 196 from_locale_.empty() ||
182 to_locale_.empty()) { 197 to_locale_.empty()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (by_user) 242 if (by_user)
228 master_->AcceptLocaleChange(); 243 master_->AcceptLocaleChange();
229 } 244 }
230 245
231 std::string LocaleChangeGuard::Delegate::id() const { 246 std::string LocaleChangeGuard::Delegate::id() const {
232 // Arbitrary unique Id. 247 // Arbitrary unique Id.
233 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; 248 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5";
234 } 249 }
235 250
236 } // namespace chromeos 251 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/locale_change_guard.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698