Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), |
| 50 session_state_observer_installed_(false) { | |
| 48 registrar_.Add(this, | 51 registrar_.Add(this, |
| 49 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 52 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 50 content::NotificationService::AllSources()); | 53 content::NotificationService::AllSources()); |
| 51 registrar_.Add(this, | 54 registrar_.Add(this, |
| 52 chrome::NOTIFICATION_SESSION_STARTED, | 55 chrome::NOTIFICATION_SESSION_STARTED, |
| 53 content::NotificationService::AllSources()); | 56 content::NotificationService::AllSources()); |
| 54 registrar_.Add(this, | 57 registrar_.Add(this, |
| 55 chrome::NOTIFICATION_PROFILE_DESTROYED, | 58 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 56 content::NotificationService::AllSources()); | 59 content::NotificationService::AllSources()); |
| 57 } | 60 } |
| 58 | 61 |
| 59 virtual ~MagnificationManagerImpl() { | 62 virtual ~MagnificationManagerImpl() { |
| 60 CHECK(this == g_magnification_manager); | 63 CHECK(this == g_magnification_manager); |
| 64 if (session_state_observer_installed_) | |
|
dmazzoni
2013/12/13 16:15:07
Nit: {}
Mr4D (OOO till 08-26)
2013/12/13 17:21:13
Done.
| |
| 65 ash::Shell::GetInstance()->session_state_delegate()-> | |
| 66 RemoveSessionStateObserver(this); | |
| 61 } | 67 } |
| 62 | 68 |
| 63 // MagnificationManager implimentation: | 69 // MagnificationManager implimentation: |
| 64 virtual bool IsMagnifierEnabled() const OVERRIDE { | 70 virtual bool IsMagnifierEnabled() const OVERRIDE { |
| 65 return enabled_; | 71 return enabled_; |
| 66 } | 72 } |
| 67 | 73 |
| 68 virtual ash::MagnifierType GetMagnifierType() const OVERRIDE { | 74 virtual ash::MagnifierType GetMagnifierType() const OVERRIDE { |
| 69 return type_; | 75 return type_; |
| 70 } | 76 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 98 if (!profile_) | 104 if (!profile_) |
| 99 return std::numeric_limits<double>::min(); | 105 return std::numeric_limits<double>::min(); |
| 100 | 106 |
| 101 return profile_->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); | 107 return profile_->GetPrefs()->GetDouble(prefs::kScreenMagnifierScale); |
| 102 } | 108 } |
| 103 | 109 |
| 104 virtual void SetProfileForTest(Profile* profile) OVERRIDE { | 110 virtual void SetProfileForTest(Profile* profile) OVERRIDE { |
| 105 SetProfile(profile); | 111 SetProfile(profile); |
| 106 } | 112 } |
| 107 | 113 |
| 114 // SessionStateObserver overrides: | |
| 115 virtual void ActiveUserChanged(const std::string& user_id) OVERRIDE { | |
| 116 SetProfile(ProfileManager::GetActiveUserProfile()); | |
| 117 } | |
| 118 | |
| 108 private: | 119 private: |
| 109 void SetProfile(Profile* profile) { | 120 void SetProfile(Profile* profile) { |
| 110 pref_change_registrar_.reset(); | 121 pref_change_registrar_.reset(); |
| 111 | 122 |
| 112 if (profile) { | 123 if (profile) { |
| 113 // TODO(yoshiki): Move following code to PrefHandler. | 124 // TODO(yoshiki): Move following code to PrefHandler. |
| 114 pref_change_registrar_.reset(new PrefChangeRegistrar); | 125 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 115 pref_change_registrar_->Init(profile->GetPrefs()); | 126 pref_change_registrar_->Init(profile->GetPrefs()); |
| 116 pref_change_registrar_->Add( | 127 pref_change_registrar_->Add( |
| 117 prefs::kScreenMagnifierEnabled, | 128 prefs::kScreenMagnifierEnabled, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 213 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
| 203 // Update |profile_| when entering the login screen. | 214 // Update |profile_| when entering the login screen. |
| 204 Profile* profile = ProfileManager::GetDefaultProfile(); | 215 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 205 if (ProfileHelper::IsSigninProfile(profile)) | 216 if (ProfileHelper::IsSigninProfile(profile)) |
| 206 SetProfile(profile); | 217 SetProfile(profile); |
| 207 break; | 218 break; |
| 208 } | 219 } |
| 209 case chrome::NOTIFICATION_SESSION_STARTED: | 220 case chrome::NOTIFICATION_SESSION_STARTED: |
| 210 // Update |profile_| when entering a session. | 221 // Update |profile_| when entering a session. |
| 211 SetProfile(ProfileManager::GetDefaultProfile()); | 222 SetProfile(ProfileManager::GetDefaultProfile()); |
| 223 | |
| 224 // Add a session state observer to be able to monitor session changes. | |
| 225 if (!session_state_observer_installed_ && ash::Shell::HasInstance()) { | |
| 226 session_state_observer_installed_ = true; | |
| 227 ash::Shell::GetInstance()->session_state_delegate()-> | |
| 228 AddSessionStateObserver(this); | |
| 229 } | |
| 212 break; | 230 break; |
| 213 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 231 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 214 // Update |profile_| when exiting a session or shutting down. | 232 // Update |profile_| when exiting a session or shutting down. |
| 215 Profile* profile = content::Source<Profile>(source).ptr(); | 233 Profile* profile = content::Source<Profile>(source).ptr(); |
| 216 if (profile_ == profile) | 234 if (profile_ == profile) |
| 217 SetProfile(NULL); | 235 SetProfile(NULL); |
| 218 break; | 236 break; |
| 219 } | 237 } |
| 220 } | 238 } |
| 221 } | 239 } |
| 222 | 240 |
| 223 bool first_time_update_; | 241 bool first_time_update_; |
| 224 Profile* profile_; | 242 Profile* profile_; |
| 225 | 243 |
| 226 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; | 244 AccessibilityManager::PrefHandler magnifier_enabled_pref_handler_; |
| 227 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 245 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
| 228 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 246 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
| 229 | 247 |
| 230 ash::MagnifierType type_; | 248 ash::MagnifierType type_; |
| 231 bool enabled_; | 249 bool enabled_; |
| 250 | |
| 251 // True when the session state observer was installed. | |
| 252 bool session_state_observer_installed_; | |
| 253 | |
| 232 content::NotificationRegistrar registrar_; | 254 content::NotificationRegistrar registrar_; |
| 233 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 255 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 234 | 256 |
| 235 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 257 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
| 236 }; | 258 }; |
| 237 | 259 |
| 238 // static | 260 // static |
| 239 void MagnificationManager::Initialize() { | 261 void MagnificationManager::Initialize() { |
| 240 CHECK(g_magnification_manager == NULL); | 262 CHECK(g_magnification_manager == NULL); |
| 241 g_magnification_manager = new MagnificationManagerImpl(); | 263 g_magnification_manager = new MagnificationManagerImpl(); |
| 242 } | 264 } |
| 243 | 265 |
| 244 // static | 266 // static |
| 245 void MagnificationManager::Shutdown() { | 267 void MagnificationManager::Shutdown() { |
| 246 CHECK(g_magnification_manager); | 268 CHECK(g_magnification_manager); |
| 247 delete g_magnification_manager; | 269 delete g_magnification_manager; |
| 248 g_magnification_manager = NULL; | 270 g_magnification_manager = NULL; |
| 249 } | 271 } |
| 250 | 272 |
| 251 // static | 273 // static |
| 252 MagnificationManager* MagnificationManager::Get() { | 274 MagnificationManager* MagnificationManager::Get() { |
| 253 return g_magnification_manager; | 275 return g_magnification_manager; |
| 254 } | 276 } |
| 255 | 277 |
| 256 } // namespace chromeos | 278 } // namespace chromeos |
| OLD | NEW |