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

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

Issue 6249009: Cleanup of r71320 commit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup 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 | « chrome/app/generated_resources.grd ('k') | chrome/browser/profiles/profile_impl.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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 15 matching lines...) Expand all
26 namespace chromeos { 26 namespace chromeos {
27 27
28 LocaleChangeGuard::LocaleChangeGuard() 28 LocaleChangeGuard::LocaleChangeGuard()
29 : profile_id_(Profile::InvalidProfileId), 29 : profile_id_(Profile::InvalidProfileId),
30 tab_contents_(NULL), 30 tab_contents_(NULL),
31 note_(NULL), 31 note_(NULL),
32 reverted_(false) { 32 reverted_(false) {
33 } 33 }
34 34
35 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { 35 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) {
36 if (note_ == NULL
37 || tab_contents_ == NULL
brettw 2011/01/17 16:40:30 In Chrome we'll normally put the || at the end of
Denis Lagno 2011/01/17 17:44:13 Done.
38 || from_locale_.empty()
39 || to_locale_.empty()) {
40 NOTREACHED();
41 return;
42 }
43 if (reverted_)
44 return;
45
46 PrefService* prefs = tab_contents_->profile()->GetPrefs();
47 if (prefs == NULL)
48 return;
49
36 reverted_ = true; 50 reverted_ = true;
37 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); 51 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert"));
38 tab_contents_->profile()->ChangeApplicationLocale(from_locale_, true); 52 tab_contents_->profile()->ChangeApplicationLocale(from_locale_, true);
39 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 53 prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_);
40 if (prefs) { 54 prefs->ClearPref(prefs::kApplicationLocaleAccepted);
41 prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_); 55 prefs->ScheduleSavePersistentPrefs();
42 prefs->ClearPref(prefs::kApplicationLocaleAccepted); 56
43 prefs->ScheduleSavePersistentPrefs();
44 }
45 Browser* browser = Browser::GetBrowserForController( 57 Browser* browser = Browser::GetBrowserForController(
46 &tab_contents_->controller(), NULL); 58 &tab_contents_->controller(), NULL);
47 if (browser) 59 if (browser)
48 browser->ExecuteCommand(IDC_EXIT); 60 browser->ExecuteCommand(IDC_EXIT);
49 } 61 }
50 62
51 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { 63 void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) {
52 // We want notification to be shown no more than once per session. 64 // We want notification to be shown no more than once per session.
53 if (note_ != NULL) 65 if (note_ != NULL)
54 return; 66 return;
67 DCHECK(note_ == NULL && tab_contents_ == NULL);
68 DCHECK(from_locale_.empty() && to_locale_.empty());
69
55 // We check profile Id because: 70 // We check profile Id because:
56 // (1) we want to exit fast in common case when nothing should be done. 71 // (1) we want to exit fast in common case when nothing should be done.
57 // (2) on ChromeOS this guard may be invoked for a dummy profile first time. 72 // (2) on ChromeOS this guard may be invoked for a dummy profile first time.
58 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId(); 73 ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId();
59 if (cur_profile_id == profile_id_) 74 if (cur_profile_id == profile_id_) {
75 // We have already checked this profile, exiting fast.
60 return; 76 return;
77 }
61 profile_id_ = cur_profile_id; 78 profile_id_ = cur_profile_id;
79
62 std::string cur_locale = g_browser_process->GetApplicationLocale(); 80 std::string cur_locale = g_browser_process->GetApplicationLocale();
63 if (cur_locale.empty()) 81 if (cur_locale.empty()) {
82 NOTREACHED();
64 return; 83 return;
84 }
85
65 PrefService* prefs = tab_contents->profile()->GetPrefs(); 86 PrefService* prefs = tab_contents->profile()->GetPrefs();
66 if (prefs == NULL) 87 if (prefs == NULL)
67 return; 88 return;
68 to_locale_ = prefs->GetString(prefs::kApplicationLocaleOverride); 89
69 if (!to_locale_.empty()) { 90 std::string to_locale = prefs->GetString(prefs::kApplicationLocaleOverride);
70 DCHECK(to_locale_ == cur_locale); 91 if (!to_locale.empty()) {
92 DCHECK(to_locale == cur_locale);
71 return; 93 return;
72 } 94 }
73 to_locale_ = prefs->GetString(prefs::kApplicationLocale); 95
74 if (to_locale_ != cur_locale) 96 to_locale = prefs->GetString(prefs::kApplicationLocale);
97 if (to_locale != cur_locale) {
98 // This conditional branch can occur in case kApplicationLocale
99 // preference was modified by synchronization.
75 return; 100 return;
76 from_locale_ = prefs->GetString(prefs::kApplicationLocaleBackup); 101 }
77 if (from_locale_.empty() || from_locale_ == to_locale_) 102
78 return; 103 DCHECK(note_ == NULL && tab_contents_ == NULL);
brettw 2011/01/17 16:40:30 You already did these two DCHECKs at the top of th
Denis Lagno 2011/01/17 17:44:13 Done.
79 note_.reset(new chromeos::SystemNotification( 104 DCHECK(from_locale_.empty() && to_locale_.empty());
80 tab_contents->profile(), 105 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup);
81 new Delegate(this), 106 if (!from_locale.empty() && from_locale != to_locale) {
brettw 2011/01/17 16:40:30 I actually liked the old way of returning early in
Denis Lagno 2011/01/17 17:44:13 Done.
82 IDR_DEFAULT_FAVICON, 107 // Locale change detected, showing notification.
83 l10n_util::GetStringUTF16( 108 from_locale_ = from_locale;
84 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE))); 109 to_locale_ = to_locale;
85 tab_contents_ = tab_contents; 110 tab_contents_ = tab_contents;
86 note_->Show( 111 note_.reset(new chromeos::SystemNotification(
87 l10n_util::GetStringFUTF16( 112 tab_contents->profile(),
88 IDS_LOCALE_CHANGE_MESSAGE, 113 new Delegate(this),
89 l10n_util::GetDisplayNameForLocale(from_locale_, to_locale_, true), 114 IDR_DEFAULT_FAVICON,
90 l10n_util::GetDisplayNameForLocale(to_locale_, to_locale_, true)), 115 l10n_util::GetStringUTF16(
91 l10n_util::GetStringUTF16(IDS_LOCALE_CHANGE_REVERT_MESSAGE), 116 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE)));
92 NewCallback(this, &LocaleChangeGuard::RevertLocaleChange), 117 note_->Show(
93 true, // urgent 118 l10n_util::GetStringFUTF16(
94 false); // non-sticky 119 IDS_LOCALE_CHANGE_MESSAGE,
120 l10n_util::GetDisplayNameForLocale(from_locale_, to_locale_, true),
121 l10n_util::GetDisplayNameForLocale(to_locale_, to_locale_, true)),
122 l10n_util::GetStringUTF16(IDS_LOCALE_CHANGE_REVERT_MESSAGE),
123 NewCallback(this, &LocaleChangeGuard::RevertLocaleChange),
124 true, // urgent
125 false); // non-sticky
126 }
95 } 127 }
96 128
97 void LocaleChangeGuard::AcceptLocaleChange() { 129 void LocaleChangeGuard::AcceptLocaleChange() {
130 if (note_ == NULL
131 || tab_contents_ == NULL
brettw 2011/01/17 16:40:30 Ditto with || at the end.
Denis Lagno 2011/01/17 17:44:13 Done.
132 || from_locale_.empty()
133 || to_locale_.empty()) {
134 NOTREACHED();
135 return;
136 }
137
98 // Check whether locale has been reverted or changed. 138 // Check whether locale has been reverted or changed.
99 // If not: mark current locale as accepted. 139 // If not: mark current locale as accepted.
100 if (tab_contents_ == NULL)
101 return;
102 if (reverted_) 140 if (reverted_)
103 return; 141 return;
104 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 142 PrefService* prefs = tab_contents_->profile()->GetPrefs();
105 if (prefs == NULL) 143 if (prefs == NULL)
106 return; 144 return;
107 std::string override_locale = 145 std::string override_locale =
108 prefs->GetString(prefs::kApplicationLocaleOverride); 146 prefs->GetString(prefs::kApplicationLocaleOverride);
109 if (!override_locale.empty()) 147 if (!override_locale.empty())
110 return; 148 return;
111 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) 149 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_)
(...skipping 13 matching lines...) Expand all
125 if (by_user) 163 if (by_user)
126 master_->AcceptLocaleChange(); 164 master_->AcceptLocaleChange();
127 } 165 }
128 166
129 std::string LocaleChangeGuard::Delegate::id() const { 167 std::string LocaleChangeGuard::Delegate::id() const {
130 // Arbitrary unique Id. 168 // Arbitrary unique Id.
131 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; 169 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5";
132 } 170 }
133 171
134 } // namespace chromeos 172 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698