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

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: d 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)
altimofeev 2011/03/16 11:35:54 You can add NOTREACHED() here, since GetPrefs() sh
Denis Lagno 2011/03/16 11:55:14 Done.
92 return;
93 std::string owner_locale =
94 prefs->GetString(prefs::kApplicationLocale);
95 if (!owner_locale.empty()) {
96 local_state->SetString(prefs::kOwnerLocale, owner_locale);
97 local_state->ScheduleSavePersistentPrefs();
98 }
99 }
100 }
101 break;
102 default:
103 NOTREACHED();
104 break;
105 }
106 }
85 107
86 // We need to perform locale change check only once: so we want to 108 void LocaleChangeGuard::Check() {
87 // unsubscribe from notifications in any case.
88 registrar_.RemoveAll();
89
90 if (note_ != NULL || !from_locale_.empty() || !to_locale_.empty()) { 109 if (note_ != NULL || !from_locale_.empty() || !to_locale_.empty()) {
91 // Somehow we are notified more than once. Once is enough. 110 // Somehow we are invoked more than once. Once is enough.
92 return; 111 return;
93 } 112 }
94 113
95 std::string cur_locale = g_browser_process->GetApplicationLocale(); 114 std::string cur_locale = g_browser_process->GetApplicationLocale();
96 if (cur_locale.empty()) { 115 if (cur_locale.empty()) {
97 NOTREACHED(); 116 NOTREACHED();
98 return; 117 return;
99 } 118 }
100 119
101 PrefService* prefs = profile_->GetPrefs(); 120 PrefService* prefs = profile_->GetPrefs();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (by_user) 184 if (by_user)
166 master_->AcceptLocaleChange(); 185 master_->AcceptLocaleChange();
167 } 186 }
168 187
169 std::string LocaleChangeGuard::Delegate::id() const { 188 std::string LocaleChangeGuard::Delegate::id() const {
170 // Arbitrary unique Id. 189 // Arbitrary unique Id.
171 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; 190 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5";
172 } 191 }
173 192
174 } // namespace chromeos 193 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698