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

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

Issue 6677049: Comb up ownership things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: c Created 9 years, 9 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
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/login/user_manager.h"
10 #include "chrome/browser/metrics/user_metrics.h" 11 #include "chrome/browser/metrics/user_metrics.h"
11 #include "chrome/browser/notifications/notification_delegate.h" 12 #include "chrome/browser/notifications/notification_delegate.h"
12 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "content/browser/tab_contents/tab_contents.h" 17 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/common/notification_service.h" 18 #include "content/common/notification_service.h"
18 #include "content/common/notification_source.h" 19 #include "content/common/notification_source.h"
19 #include "grit/app_resources.h" 20 #include "grit/app_resources.h"
(...skipping 17 matching lines...) Expand all
37 DISALLOW_COPY_AND_ASSIGN(Delegate); 38 DISALLOW_COPY_AND_ASSIGN(Delegate);
38 }; 39 };
39 40
40 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) 41 LocaleChangeGuard::LocaleChangeGuard(Profile* profile)
41 : profile_(profile), 42 : profile_(profile),
42 note_(NULL), 43 note_(NULL),
43 reverted_(false) { 44 reverted_(false) {
44 DCHECK(profile_); 45 DCHECK(profile_);
45 registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, 46 registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME,
46 NotificationService::AllSources()); 47 NotificationService::AllSources());
48 registrar_.Add(this, NotificationType::OWNERSHIP_CHECKED,
49 NotificationService::AllSources());
47 } 50 }
48 51
49 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { 52 void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) {
50 if (note_ == NULL || 53 if (note_ == NULL ||
51 profile_ == NULL || 54 profile_ == NULL ||
52 from_locale_.empty() || 55 from_locale_.empty() ||
53 to_locale_.empty()) { 56 to_locale_.empty()) {
54 NOTREACHED(); 57 NOTREACHED();
55 return; 58 return;
56 } 59 }
57 if (reverted_) 60 if (reverted_)
58 return; 61 return;
59
60 PrefService* prefs = profile_->GetPrefs();
61 if (prefs == NULL)
62 return;
63
64 reverted_ = true; 62 reverted_ = true;
65 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); 63 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert"));
66 profile_->ChangeAppLocale( 64 profile_->ChangeAppLocale(
67 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); 65 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT);
68 66
69 Browser* browser = Browser::GetTabbedBrowser(profile_, false); 67 Browser* browser = Browser::GetTabbedBrowser(profile_, false);
70 if (browser) 68 if (browser)
71 browser->ExecuteCommand(IDC_EXIT); 69 browser->ExecuteCommand(IDC_EXIT);
72 } 70 }
73 71
74 void LocaleChangeGuard::Observe(NotificationType type, 72 void LocaleChangeGuard::Observe(NotificationType type,
75 const NotificationSource& source, 73 const NotificationSource& source,
76 const NotificationDetails& details) { 74 const NotificationDetails& details) {
77 if (type != NotificationType::LOAD_COMPLETED_MAIN_FRAME) {
78 NOTREACHED();
79 return;
80 }
81 if (profile_ == NULL) { 75 if (profile_ == NULL) {
82 NOTREACHED(); 76 NOTREACHED();
83 return; 77 return;
84 } 78 }
79 switch (type.value) {
80 case NotificationType::LOAD_COMPLETED_MAIN_FRAME:
81 // We need to perform locale change check only once, so unsubscribe.
82 registrar_.Remove(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME,
83 NotificationService::AllSources());
84 Check();
85 break;
86 case NotificationType::OWNERSHIP_CHECKED:
87 if (UserManager::Get()->current_user_is_owner()) {
88 PrefService* local_state = g_browser_process->local_state();
89 if (local_state) {
90 PrefService* prefs = profile_->GetPrefs();
91 if (prefs == NULL) {
92 NOTREACHED();
93 return;
94 }
95 std::string owner_locale =
96 prefs->GetString(prefs::kApplicationLocale);
97 if (!owner_locale.empty()) {
98 local_state->SetString(prefs::kOwnerLocale, owner_locale);
99 local_state->ScheduleSavePersistentPrefs();
100 }
101 }
102 }
103 break;
104 default:
105 NOTREACHED();
106 break;
107 }
108 }
85 109
86 // We need to perform locale change check only once: so we want to 110 void LocaleChangeGuard::Check() {
87 // unsubscribe from notifications in any case.
88 registrar_.RemoveAll();
89
90 if (note_ != NULL || !from_locale_.empty() || !to_locale_.empty()) { 111 if (note_ != NULL || !from_locale_.empty() || !to_locale_.empty()) {
91 // Somehow we are notified more than once. Once is enough. 112 // Somehow we are invoked more than once. Once is enough.
92 return; 113 return;
93 } 114 }
94 115
95 std::string cur_locale = g_browser_process->GetApplicationLocale(); 116 std::string cur_locale = g_browser_process->GetApplicationLocale();
96 if (cur_locale.empty()) { 117 if (cur_locale.empty()) {
97 NOTREACHED(); 118 NOTREACHED();
98 return; 119 return;
99 } 120 }
100 121
101 PrefService* prefs = profile_->GetPrefs(); 122 PrefService* prefs = profile_->GetPrefs();
102 if (prefs == NULL) 123 if (prefs == NULL) {
124 NOTREACHED();
103 return; 125 return;
126 }
104 127
105 std::string to_locale = prefs->GetString(prefs::kApplicationLocale); 128 std::string to_locale = prefs->GetString(prefs::kApplicationLocale);
106 if (to_locale != cur_locale) { 129 if (to_locale != cur_locale) {
107 // This conditional branch can occur in cases like: 130 // This conditional branch can occur in cases like:
108 // (1) kApplicationLocale preference was modified by synchronization; 131 // (1) kApplicationLocale preference was modified by synchronization;
109 // (2) kApplicationLocale is managed by policy. 132 // (2) kApplicationLocale is managed by policy.
110 return; 133 return;
111 } 134 }
112 135
113 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); 136 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup);
(...skipping 30 matching lines...) Expand all
144 to_locale_.empty()) { 167 to_locale_.empty()) {
145 NOTREACHED(); 168 NOTREACHED();
146 return; 169 return;
147 } 170 }
148 171
149 // Check whether locale has been reverted or changed. 172 // Check whether locale has been reverted or changed.
150 // If not: mark current locale as accepted. 173 // If not: mark current locale as accepted.
151 if (reverted_) 174 if (reverted_)
152 return; 175 return;
153 PrefService* prefs = profile_->GetPrefs(); 176 PrefService* prefs = profile_->GetPrefs();
154 if (prefs == NULL) 177 if (prefs == NULL) {
178 NOTREACHED();
155 return; 179 return;
180 }
156 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) 181 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_)
157 return; 182 return;
158 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept")); 183 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept"));
159 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); 184 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_);
160 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); 185 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_);
161 prefs->ScheduleSavePersistentPrefs(); 186 prefs->ScheduleSavePersistentPrefs();
162 } 187 }
163 188
164 void LocaleChangeGuard::Delegate::Close(bool by_user) { 189 void LocaleChangeGuard::Delegate::Close(bool by_user) {
165 if (by_user) 190 if (by_user)
166 master_->AcceptLocaleChange(); 191 master_->AcceptLocaleChange();
167 } 192 }
168 193
169 std::string LocaleChangeGuard::Delegate::id() const { 194 std::string LocaleChangeGuard::Delegate::id() const {
170 // Arbitrary unique Id. 195 // Arbitrary unique Id.
171 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; 196 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5";
172 } 197 }
173 198
174 } // namespace chromeos 199 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/locale_change_guard.h ('k') | chrome/browser/chromeos/login/ownership_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698