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

Side by Side Diff: chrome/browser/chromeos/accessibility/magnification_manager.cc

Issue 102483006: Getting rid of GetDefaultProfile & fixing multi user issues with accessibility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test Created 7 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/accessibility/magnification_manager.h" 5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "ash/magnifier/magnification_controller.h" 9 #include "ash/magnifier/magnification_controller.h"
10 #include "ash/magnifier/partial_magnification_controller.h" 10 #include "ash/magnifier/partial_magnification_controller.h"
11 #include "ash/session_state_delegate.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/shell_delegate.h" 13 #include "ash/shell_delegate.h"
13 #include "ash/system/tray/system_tray_notifier.h" 14 #include "ash/system/tray/system_tray_notifier.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
16 #include "base/prefs/pref_member.h" 17 #include "base/prefs/pref_member.h"
17 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
20 #include "chrome/browser/chromeos/login/user_manager.h" 21 #include "chrome/browser/chromeos/login/user_manager.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_observer.h" 27 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h" 28 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 31
31 namespace chromeos { 32 namespace chromeos {
32 33
33 namespace { 34 namespace {
34 static MagnificationManager* g_magnification_manager = NULL; 35 static MagnificationManager* g_magnification_manager = NULL;
35 } 36 }
36 37
37 class MagnificationManagerImpl : public MagnificationManager, 38 class MagnificationManagerImpl : public MagnificationManager,
38 public content::NotificationObserver { 39 public content::NotificationObserver,
40 public ash::SessionStateObserver {
39 public: 41 public:
40 MagnificationManagerImpl() 42 MagnificationManagerImpl()
41 : first_time_update_(true), 43 : first_time_update_(true),
42 profile_(NULL), 44 profile_(NULL),
43 magnifier_enabled_pref_handler_(prefs::kScreenMagnifierEnabled), 45 magnifier_enabled_pref_handler_(prefs::kScreenMagnifierEnabled),
44 magnifier_type_pref_handler_(prefs::kScreenMagnifierType), 46 magnifier_type_pref_handler_(prefs::kScreenMagnifierType),
45 magnifier_scale_pref_handler_(prefs::kScreenMagnifierScale), 47 magnifier_scale_pref_handler_(prefs::kScreenMagnifierScale),
46 type_(ash::kDefaultMagnifierType), 48 type_(ash::kDefaultMagnifierType),
47 enabled_(false) { 49 enabled_(false) {
48 registrar_.Add(this, 50 registrar_.Add(this,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (!profile_) 100 if (!profile_)
99 return std::numeric_limits<double>::min(); 101 return std::numeric_limits<double>::min();
100 102
101 return profile_->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); 103 return profile_->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale);
102 } 104 }
103 105
104 virtual void SetProfileForTest(Profile* profile) OVERRIDE { 106 virtual void SetProfileForTest(Profile* profile) OVERRIDE {
105 SetProfile(profile); 107 SetProfile(profile);
106 } 108 }
107 109
110 // SessionStateObserver overrides:
111 virtual void ActiveUserChanged(const std::string& user_id) OVERRIDE {
112 SetProfile(ProfileManager::GetActiveUserProfile());
113 }
114
108 private: 115 private:
109 void SetProfile(Profile* profile) { 116 void SetProfile(Profile* profile) {
110 pref_change_registrar_.reset(); 117 pref_change_registrar_.reset();
111 118
112 if (profile) { 119 if (profile) {
113 // TODO(yoshiki): Move following code to PrefHandler. 120 // TODO(yoshiki): Move following code to PrefHandler.
114 pref_change_registrar_.reset(new PrefChangeRegistrar); 121 pref_change_registrar_.reset(new PrefChangeRegistrar);
115 pref_change_registrar_->Init(profile->GetPrefs()); 122 pref_change_registrar_->Init(profile->GetPrefs());
116 pref_change_registrar_->Add( 123 pref_change_registrar_->Add(
117 prefs::kScreenMagnifierEnabled, 124 prefs::kScreenMagnifierEnabled,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { 209 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: {
203 // Update |profile_| when entering the login screen. 210 // Update |profile_| when entering the login screen.
204 Profile* profile = ProfileManager::GetDefaultProfile(); 211 Profile* profile = ProfileManager::GetDefaultProfile();
205 if (ProfileHelper::IsSigninProfile(profile)) 212 if (ProfileHelper::IsSigninProfile(profile))
206 SetProfile(profile); 213 SetProfile(profile);
207 break; 214 break;
208 } 215 }
209 case chrome::NOTIFICATION_SESSION_STARTED: 216 case chrome::NOTIFICATION_SESSION_STARTED:
210 // Update |profile_| when entering a session. 217 // Update |profile_| when entering a session.
211 SetProfile(ProfileManager::GetDefaultProfile()); 218 SetProfile(ProfileManager::GetDefaultProfile());
219
220 // Add a session state observer to be able to monitor session changes.
221 if (!session_state_observer_.get() && ash::Shell::HasInstance())
222 session_state_observer_.reset(
223 new ash::ScopedSessionStateObserver(this));
212 break; 224 break;
213 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 225 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
214 // Update |profile_| when exiting a session or shutting down. 226 // Update |profile_| when exiting a session or shutting down.
215 Profile* profile = content::Source<Profile>(source).ptr(); 227 Profile* profile = content::Source<Profile>(source).ptr();
216 if (profile_ == profile) 228 if (profile_ == profile)
217 SetProfile(NULL); 229 SetProfile(NULL);
218 break; 230 break;
219 } 231 }
220 } 232 }
221 } 233 }
222 234
223 bool first_time_update_; 235 bool first_time_update_;
224 Profile* profile_; 236 Profile* profile_;
225 237
226 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; 238 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_;
227 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; 239 AccessibilityManager::PrefHandler magnifier_type_pref_handler_;
228 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; 240 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_;
229 241
230 ash::MagnifierType type_; 242 ash::MagnifierType type_;
231 bool enabled_; 243 bool enabled_;
244
232 content::NotificationRegistrar registrar_; 245 content::NotificationRegistrar registrar_;
233 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; 246 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
247 scoped_ptr<ash::ScopedSessionStateObserver> session_state_observer_;
234 248
235 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); 249 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl);
236 }; 250 };
237 251
238 // static 252 // static
239 void MagnificationManager::Initialize() { 253 void MagnificationManager::Initialize() {
240 CHECK(g_magnification_manager == NULL); 254 CHECK(g_magnification_manager == NULL);
241 g_magnification_manager = new MagnificationManagerImpl(); 255 g_magnification_manager = new MagnificationManagerImpl();
242 } 256 }
243 257
244 // static 258 // static
245 void MagnificationManager::Shutdown() { 259 void MagnificationManager::Shutdown() {
246 CHECK(g_magnification_manager); 260 CHECK(g_magnification_manager);
247 delete g_magnification_manager; 261 delete g_magnification_manager;
248 g_magnification_manager = NULL; 262 g_magnification_manager = NULL;
249 } 263 }
250 264
251 // static 265 // static
252 MagnificationManager* MagnificationManager::Get() { 266 MagnificationManager* MagnificationManager::Get() {
253 return g_magnification_manager; 267 return g_magnification_manager;
254 } 268 }
255 269
256 } // namespace chromeos 270 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698