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/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 Loading... | |
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()->ChangeApplicationLocale(from_locale_); |
Nikita (slow)
2011/01/25 14:35:31
In this case should we clear LocaleBackup setting?
Denis Lagno
2011/01/25 15:46:43
ChangeApplicationLocale will set both kApplication
| |
70 prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_); | |
71 prefs->ClearPref(prefs::kApplicationLocaleAccepted); | |
72 prefs->ScheduleSavePersistentPrefs(); | |
73 | 70 |
74 Browser* browser = Browser::GetBrowserForController( | 71 Browser* browser = Browser::GetBrowserForController( |
75 &tab_contents_->controller(), NULL); | 72 &tab_contents_->controller(), NULL); |
76 if (browser) | 73 if (browser) |
77 browser->ExecuteCommand(IDC_EXIT); | 74 browser->ExecuteCommand(IDC_EXIT); |
78 } | 75 } |
79 | 76 |
80 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { | 77 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { |
81 // We want notification to be shown no more than once per session. | 78 // We want notification to be shown no more than once per session. |
82 if (note_ != NULL) | 79 if (note_ != NULL) |
83 return; | 80 return; |
84 DCHECK(note_ == NULL && tab_contents_ == NULL); | 81 DCHECK(note_ == NULL && tab_contents_ == NULL); |
85 DCHECK(from_locale_.empty() && to_locale_.empty()); | 82 DCHECK(from_locale_.empty() && to_locale_.empty()); |
86 | 83 |
87 // We check profile Id because: | 84 // We check profile Id because: |
88 // (1) we want to exit fast in common case when nothing should be done. | 85 // (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. | 86 // (2) on ChromeOS this guard may be invoked for a dummy profile first time. |
90 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId(); | 87 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId(); |
91 if (cur_profile_id == profile_id_) { | 88 if (cur_profile_id == profile_id_) |
92 // We have already checked this profile, exiting fast. | 89 return; // We have already checked this profile, exiting fast. |
93 return; | |
94 } | |
95 profile_id_ = cur_profile_id; | 90 profile_id_ = cur_profile_id; |
96 | 91 |
97 std::string cur_locale = g_browser_process->GetApplicationLocale(); | 92 std::string cur_locale = g_browser_process->GetApplicationLocale(); |
98 if (cur_locale.empty()) { | 93 if (cur_locale.empty()) { |
99 NOTREACHED(); | 94 NOTREACHED(); |
100 return; | 95 return; |
101 } | 96 } |
102 | 97 |
103 PrefService* prefs = tab_contents->profile()->GetPrefs(); | 98 PrefService* prefs = tab_contents->profile()->GetPrefs(); |
104 if (prefs == NULL) | 99 if (prefs == NULL) |
105 return; | 100 return; |
106 | 101 |
107 std::string to_locale = prefs->GetString(prefs::kApplicationLocaleOverride); | 102 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) { | 103 if (to_locale != cur_locale) { |
115 // This conditional branch can occur in case kApplicationLocale | 104 // This conditional branch can occur in case kApplicationLocale |
116 // preference was modified by synchronization. | 105 // preference was modified by synchronization. |
117 return; | 106 return; |
118 } | 107 } |
119 | 108 |
120 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); | 109 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); |
121 if (from_locale.empty() || from_locale == to_locale) { | 110 if (from_locale.empty() || from_locale == to_locale) |
122 // No locale change was detected, just exit. | 111 return; // No locale change was detected, just exit. |
123 return; | 112 |
124 } | 113 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale) |
Nikita (slow)
2011/01/25 14:35:31
Could you describe case which we're optimizing her
Denis Lagno
2011/01/25 15:46:43
it is not optimization, it is double check.
This c
| |
114 return; // Already accepted. | |
125 | 115 |
126 // Locale change detected, showing notification. | 116 // Locale change detected, showing notification. |
127 from_locale_ = from_locale; | 117 from_locale_ = from_locale; |
128 to_locale_ = to_locale; | 118 to_locale_ = to_locale; |
129 tab_contents_ = tab_contents; | 119 tab_contents_ = tab_contents; |
130 note_.reset(new chromeos::SystemNotification( | 120 note_.reset(new chromeos::SystemNotification( |
131 tab_contents->profile(), | 121 tab_contents->profile(), |
132 new Delegate(this), | 122 new Delegate(this), |
133 IDR_DEFAULT_FAVICON, | 123 IDR_DEFAULT_FAVICON, |
134 l10n_util::GetStringUTF16( | 124 l10n_util::GetStringUTF16( |
(...skipping 18 matching lines...) Expand all Loading... | |
153 return; | 143 return; |
154 } | 144 } |
155 | 145 |
156 // Check whether locale has been reverted or changed. | 146 // Check whether locale has been reverted or changed. |
157 // If not: mark current locale as accepted. | 147 // If not: mark current locale as accepted. |
158 if (reverted_) | 148 if (reverted_) |
159 return; | 149 return; |
160 PrefService* prefs = tab_contents_->profile()->GetPrefs(); | 150 PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
161 if (prefs == NULL) | 151 if (prefs == NULL) |
162 return; | 152 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_) | 153 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) |
168 return; | 154 return; |
169 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept")); | 155 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept")); |
170 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); | 156 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); |
171 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); | 157 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); |
172 prefs->ScheduleSavePersistentPrefs(); | 158 prefs->ScheduleSavePersistentPrefs(); |
173 } | 159 } |
174 | 160 |
175 // static | 161 // static |
176 void LocaleChangeGuard::Check(TabContents* tab_contents) { | 162 void LocaleChangeGuard::Check(TabContents* tab_contents) { |
177 g_locale_change_guard.Get().CheckLocaleChange(tab_contents); | 163 g_locale_change_guard.Get().CheckLocaleChange(tab_contents); |
178 } | 164 } |
179 | 165 |
180 void LocaleChangeGuard::Delegate::Close(bool by_user) { | 166 void LocaleChangeGuard::Delegate::Close(bool by_user) { |
181 if (by_user) | 167 if (by_user) |
182 master_->AcceptLocaleChange(); | 168 master_->AcceptLocaleChange(); |
183 } | 169 } |
184 | 170 |
185 std::string LocaleChangeGuard::Delegate::id() const { | 171 std::string LocaleChangeGuard::Delegate::id() const { |
186 // Arbitrary unique Id. | 172 // Arbitrary unique Id. |
187 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; | 173 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; |
188 } | 174 } |
189 | 175 |
190 } // namespace chromeos | 176 } // namespace chromeos |
OLD | NEW |