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

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

Issue 2420753002: ash: Use mojo LocaleNotificationController interface. (Closed)
Patch Set: Uniquify callbacks Created 4 years, 2 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
« 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/common/system/tray/system_tray_notifier.h"
10 #include "ash/common/wm_shell.h"
11 #include "base/bind.h" 9 #include "base/bind.h"
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 15 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chrome/browser/lifetime/application_lifetime.h" 16 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/ash/ash_util.h"
20 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "chrome/grit/generated_resources.h"
24 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
25 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
27 #include "content/public/browser/user_metrics.h" 25 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/service_manager_connection.h"
28 #include "services/service_manager/public/cpp/connector.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 30
31 using base::UserMetricsAction; 31 using base::UserMetricsAction;
32 using content::WebContents; 32 using content::WebContents;
33 33
34 namespace chromeos { 34 namespace chromeos {
35 35
36 namespace { 36 namespace {
37 37
38 // This is the list of languages that do not require user notification when 38 // This is the list of languages that do not require user notification when
(...skipping 17 matching lines...) Expand all
56 56
57 LocaleChangeGuard::~LocaleChangeGuard() {} 57 LocaleChangeGuard::~LocaleChangeGuard() {}
58 58
59 void LocaleChangeGuard::OnLogin() { 59 void LocaleChangeGuard::OnLogin() {
60 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, 60 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
61 content::NotificationService::AllSources()); 61 content::NotificationService::AllSources());
62 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 62 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
63 content::NotificationService::AllBrowserContextsAndSources()); 63 content::NotificationService::AllBrowserContextsAndSources());
64 } 64 }
65 65
66 void LocaleChangeGuard::ConnectToLocaleNotificationController() {
67 content::ServiceManagerConnection* connection =
68 content::ServiceManagerConnection::GetForProcess();
69 service_manager::Connector* connector =
70 connection ? connection->GetConnector() : nullptr;
71 // Unit tests may not have a connector.
72 if (!connector)
73 return;
74
75 if (chrome::IsRunningInMash()) {
76 connector->ConnectToInterface("service:ash", &notification_controller_);
77 } else {
78 connector->ConnectToInterface("service:content_browser",
79 &notification_controller_);
80 }
81 }
82
66 void LocaleChangeGuard::RevertLocaleChange() { 83 void LocaleChangeGuard::RevertLocaleChange() {
67 if (profile_ == NULL || 84 if (profile_ == NULL ||
68 from_locale_.empty() || 85 from_locale_.empty() ||
69 to_locale_.empty()) { 86 to_locale_.empty()) {
70 NOTREACHED(); 87 NOTREACHED();
71 return; 88 return;
72 } 89 }
73 if (reverted_) 90 if (reverted_)
74 return; 91 return;
75 reverted_ = true; 92 reverted_ = true;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return; 186 return;
170 187
171 // Showing notification. 188 // Showing notification.
172 if (from_locale_ != from_locale || to_locale_ != to_locale) { 189 if (from_locale_ != from_locale || to_locale_ != to_locale) {
173 // Falling back to showing message in current locale. 190 // Falling back to showing message in current locale.
174 LOG(ERROR) << 191 LOG(ERROR) <<
175 "Showing locale change notification in current (not previous) language"; 192 "Showing locale change notification in current (not previous) language";
176 PrepareChangingLocale(from_locale, to_locale); 193 PrepareChangingLocale(from_locale, to_locale);
177 } 194 }
178 195
179 ash::WmShell::Get()->system_tray_notifier()->NotifyLocaleChanged( 196 if (!notification_controller_)
180 this, cur_locale, from_locale_, to_locale_); 197 ConnectToLocaleNotificationController();
198
199 notification_controller_->OnLocaleChanged(
200 cur_locale, from_locale_, to_locale_,
201 base::Bind(&LocaleChangeGuard::OnResult, AsWeakPtr()));
202 }
203
204 void LocaleChangeGuard::OnResult(ash::mojom::LocaleNotificationResult result) {
205 switch (result) {
206 case ash::mojom::LocaleNotificationResult::ACCEPT:
207 AcceptLocaleChange();
208 break;
209 case ash::mojom::LocaleNotificationResult::REVERT:
210 RevertLocaleChange();
211 break;
212 }
181 } 213 }
182 214
183 void LocaleChangeGuard::AcceptLocaleChange() { 215 void LocaleChangeGuard::AcceptLocaleChange() {
184 if (profile_ == NULL || 216 if (profile_ == NULL ||
185 from_locale_.empty() || 217 from_locale_.empty() ||
186 to_locale_.empty()) { 218 to_locale_.empty()) {
187 NOTREACHED(); 219 NOTREACHED();
188 return; 220 return;
189 } 221 }
190 222
(...skipping 13 matching lines...) Expand all
204 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); 236 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_);
205 } 237 }
206 238
207 void LocaleChangeGuard::PrepareChangingLocale( 239 void LocaleChangeGuard::PrepareChangingLocale(
208 const std::string& from_locale, const std::string& to_locale) { 240 const std::string& from_locale, const std::string& to_locale) {
209 std::string cur_locale = g_browser_process->GetApplicationLocale(); 241 std::string cur_locale = g_browser_process->GetApplicationLocale();
210 if (!from_locale.empty()) 242 if (!from_locale.empty())
211 from_locale_ = from_locale; 243 from_locale_ = from_locale;
212 if (!to_locale.empty()) 244 if (!to_locale.empty())
213 to_locale_ = to_locale; 245 to_locale_ = to_locale;
214
215 if (!from_locale_.empty() && !to_locale_.empty()) {
216 base::string16 from = l10n_util::GetDisplayNameForLocale(
217 from_locale_, cur_locale, true);
218 base::string16 to = l10n_util::GetDisplayNameForLocale(
219 to_locale_, cur_locale, true);
220
221 title_text_ = l10n_util::GetStringUTF16(
222 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE);
223 message_text_ = l10n_util::GetStringFUTF16(
224 IDS_LOCALE_CHANGE_MESSAGE, from, to);
225 revert_link_text_ = l10n_util::GetStringFUTF16(
226 IDS_LOCALE_CHANGE_REVERT_MESSAGE, from);
227 }
228 } 246 }
229 247
230 // static 248 // static
231 bool LocaleChangeGuard::ShouldShowLocaleChangeNotification( 249 bool LocaleChangeGuard::ShouldShowLocaleChangeNotification(
232 const std::string& from_locale, 250 const std::string& from_locale,
233 const std::string& to_locale) { 251 const std::string& to_locale) {
234 const std::string from_lang = l10n_util::GetLanguage(from_locale); 252 const std::string from_lang = l10n_util::GetLanguage(from_locale);
235 const std::string to_lang = l10n_util::GetLanguage(to_locale); 253 const std::string to_lang = l10n_util::GetLanguage(to_locale);
236 254
237 if (from_locale == to_locale) 255 if (from_locale == to_locale)
(...skipping 14 matching lines...) Expand all
252 LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting() { 270 LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting() {
253 return kSkipShowNotificationLanguages; 271 return kSkipShowNotificationLanguages;
254 } 272 }
255 273
256 // static 274 // static
257 size_t LocaleChangeGuard::GetSkipShowNotificationLanguagesSizeForTesting() { 275 size_t LocaleChangeGuard::GetSkipShowNotificationLanguagesSizeForTesting() {
258 return arraysize(kSkipShowNotificationLanguages); 276 return arraysize(kSkipShowNotificationLanguages);
259 } 277 }
260 278
261 } // namespace chromeos 279 } // 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