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

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

Issue 6248017: Do not use local override for language settings: always sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bs removed Created 9 years, 11 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 | « no previous file | chrome/browser/chromeos/login/login_utils.cc » ('j') | 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) 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/notifications/system_notification.h" 10 #include "chrome/browser/chromeos/notifications/system_notification.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 if (reverted_) 60 if (reverted_)
61 return; 61 return;
62 62
63 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 63 PrefService* prefs = tab_contents_->profile()->GetPrefs();
64 if (prefs == NULL) 64 if (prefs == NULL)
65 return; 65 return;
66 66
67 reverted_ = true; 67 reverted_ = true;
68 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); 68 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert"));
69 tab_contents_->profile()->ChangeApplicationLocale(from_locale_, true); 69 tab_contents_->profile()->ChangeAppLocale(
70 prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_); 70 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT);
71 prefs->ClearPref(prefs::kApplicationLocaleAccepted);
72 prefs->ScheduleSavePersistentPrefs();
73 71
74 Browser* browser = Browser::GetBrowserForController( 72 Browser* browser = Browser::GetBrowserForController(
75 &tab_contents_->controller(), NULL); 73 &tab_contents_->controller(), NULL);
76 if (browser) 74 if (browser)
77 browser->ExecuteCommand(IDC_EXIT); 75 browser->ExecuteCommand(IDC_EXIT);
78 } 76 }
79 77
80 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { 78 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) {
81 // We want notification to be shown no more than once per session. 79 // We want notification to be shown no more than once per session.
82 if (note_ != NULL) 80 if (note_ != NULL)
83 return; 81 return;
84 DCHECK(note_ == NULL && tab_contents_ == NULL); 82 DCHECK(note_ == NULL && tab_contents_ == NULL);
85 DCHECK(from_locale_.empty() && to_locale_.empty()); 83 DCHECK(from_locale_.empty() && to_locale_.empty());
86 84
87 // We check profile Id because: 85 // We check profile Id because:
88 // (1) we want to exit fast in common case when nothing should be done. 86 // (1) we want to exit fast in common case when nothing should be done.
89 // (2) on ChromeOS this guard may be invoked for a dummy profile first time. 87 // (2) on ChromeOS this guard may be invoked for a dummy profile first time.
90 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId(); 88 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId();
91 if (cur_profile_id == profile_id_) { 89 if (cur_profile_id == profile_id_)
92 // We have already checked this profile, exiting fast. 90 return; // We have already checked this profile, exiting fast.
93 return;
94 }
95 profile_id_ = cur_profile_id; 91 profile_id_ = cur_profile_id;
96 92
97 std::string cur_locale = g_browser_process->GetApplicationLocale(); 93 std::string cur_locale = g_browser_process->GetApplicationLocale();
98 if (cur_locale.empty()) { 94 if (cur_locale.empty()) {
99 NOTREACHED(); 95 NOTREACHED();
100 return; 96 return;
101 } 97 }
102 98
103 PrefService* prefs = tab_contents->profile()->GetPrefs(); 99 PrefService* prefs = tab_contents->profile()->GetPrefs();
104 if (prefs == NULL) 100 if (prefs == NULL)
105 return; 101 return;
106 102
107 std::string to_locale = prefs->GetString(prefs::kApplicationLocaleOverride); 103 std::string to_locale = prefs->GetString(prefs::kApplicationLocale);
108 if (!to_locale.empty()) {
109 DCHECK(to_locale == cur_locale);
110 return;
111 }
112
113 to_locale = prefs->GetString(prefs::kApplicationLocale);
114 if (to_locale != cur_locale) { 104 if (to_locale != cur_locale) {
115 // This conditional branch can occur in case kApplicationLocale 105 // This conditional branch can occur in case kApplicationLocale
116 // preference was modified by synchronization. 106 // preference was modified by synchronization.
117 return; 107 return;
118 } 108 }
119 109
120 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); 110 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup);
121 if (from_locale.empty() || from_locale == to_locale) { 111 if (from_locale.empty() || from_locale == to_locale)
122 // No locale change was detected, just exit. 112 return; // No locale change was detected, just exit.
123 return; 113
124 } 114 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale)
115 return; // Already accepted.
125 116
126 // Locale change detected, showing notification. 117 // Locale change detected, showing notification.
127 from_locale_ = from_locale; 118 from_locale_ = from_locale;
128 to_locale_ = to_locale; 119 to_locale_ = to_locale;
129 tab_contents_ = tab_contents; 120 tab_contents_ = tab_contents;
130 note_.reset(new chromeos::SystemNotification( 121 note_.reset(new chromeos::SystemNotification(
131 tab_contents->profile(), 122 tab_contents->profile(),
132 new Delegate(this), 123 new Delegate(this),
133 IDR_DEFAULT_FAVICON, 124 IDR_DEFAULT_FAVICON,
134 l10n_util::GetStringUTF16( 125 l10n_util::GetStringUTF16(
(...skipping 18 matching lines...) Expand all
153 return; 144 return;
154 } 145 }
155 146
156 // Check whether locale has been reverted or changed. 147 // Check whether locale has been reverted or changed.
157 // If not: mark current locale as accepted. 148 // If not: mark current locale as accepted.
158 if (reverted_) 149 if (reverted_)
159 return; 150 return;
160 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 151 PrefService* prefs = tab_contents_->profile()->GetPrefs();
161 if (prefs == NULL) 152 if (prefs == NULL)
162 return; 153 return;
163 std::string override_locale =
164 prefs->GetString(prefs::kApplicationLocaleOverride);
165 if (!override_locale.empty())
166 return;
167 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) 154 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_)
168 return; 155 return;
169 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept")); 156 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept"));
170 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); 157 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_);
171 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); 158 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_);
172 prefs->ScheduleSavePersistentPrefs(); 159 prefs->ScheduleSavePersistentPrefs();
173 } 160 }
174 161
175 // static 162 // static
176 void LocaleChangeGuard::Check(TabContents* tab_contents) { 163 void LocaleChangeGuard::Check(TabContents* tab_contents) {
177 g_locale_change_guard.Get().CheckLocaleChange(tab_contents); 164 g_locale_change_guard.Get().CheckLocaleChange(tab_contents);
178 } 165 }
179 166
180 void LocaleChangeGuard::Delegate::Close(bool by_user) { 167 void LocaleChangeGuard::Delegate::Close(bool by_user) {
181 if (by_user) 168 if (by_user)
182 master_->AcceptLocaleChange(); 169 master_->AcceptLocaleChange();
183 } 170 }
184 171
185 std::string LocaleChangeGuard::Delegate::id() const { 172 std::string LocaleChangeGuard::Delegate::id() const {
186 // Arbitrary unique Id. 173 // Arbitrary unique Id.
187 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; 174 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5";
188 } 175 }
189 176
190 } // namespace chromeos 177 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/login_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698