| 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 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/common/accessibility_types.h" | 10 #include "ash/common/accessibility_types.h" |
| 11 #include "ash/common/session/session_state_observer.h" | |
| 12 #include "ash/magnifier/magnification_controller.h" | 11 #include "ash/magnifier/magnification_controller.h" |
| 13 #include "ash/magnifier/partial_magnification_controller.h" | 12 #include "ash/magnifier/partial_magnification_controller.h" |
| 14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 17 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 23 #include "components/prefs/pref_member.h" | 22 #include "components/prefs/pref_member.h" |
| 24 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/browser/focused_node_details.h" | 25 #include "content/public/browser/focused_node_details.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 31 | 31 |
| 32 class AccountId; | |
| 33 | |
| 34 namespace chromeos { | 32 namespace chromeos { |
| 35 | 33 |
| 36 namespace { | 34 namespace { |
| 37 static MagnificationManager* g_magnification_manager = NULL; | 35 static MagnificationManager* g_magnification_manager = NULL; |
| 38 } | 36 } |
| 39 | 37 |
| 40 class MagnificationManagerImpl : public MagnificationManager, | 38 class MagnificationManagerImpl |
| 41 public content::NotificationObserver, | 39 : public MagnificationManager, |
| 42 public ash::SessionStateObserver { | 40 public content::NotificationObserver, |
| 41 public user_manager::UserManager::UserSessionStateObserver { |
| 43 public: | 42 public: |
| 44 MagnificationManagerImpl() | 43 MagnificationManagerImpl() |
| 45 : profile_(NULL), | 44 : profile_(NULL), |
| 46 magnifier_enabled_pref_handler_( | 45 magnifier_enabled_pref_handler_( |
| 47 prefs::kAccessibilityScreenMagnifierEnabled), | 46 prefs::kAccessibilityScreenMagnifierEnabled), |
| 48 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), | 47 magnifier_type_pref_handler_(prefs::kAccessibilityScreenMagnifierType), |
| 49 magnifier_scale_pref_handler_( | 48 magnifier_scale_pref_handler_( |
| 50 prefs::kAccessibilityScreenMagnifierScale), | 49 prefs::kAccessibilityScreenMagnifierScale), |
| 51 type_(ash::kDefaultMagnifierType), | 50 type_(ash::kDefaultMagnifierType), |
| 52 enabled_(false), | 51 enabled_(false), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 double GetSavedScreenMagnifierScale() const override { | 100 double GetSavedScreenMagnifierScale() const override { |
| 102 if (!profile_) | 101 if (!profile_) |
| 103 return std::numeric_limits<double>::min(); | 102 return std::numeric_limits<double>::min(); |
| 104 | 103 |
| 105 return profile_->GetPrefs()->GetDouble( | 104 return profile_->GetPrefs()->GetDouble( |
| 106 prefs::kAccessibilityScreenMagnifierScale); | 105 prefs::kAccessibilityScreenMagnifierScale); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void SetProfileForTest(Profile* profile) override { SetProfile(profile); } | 108 void SetProfileForTest(Profile* profile) override { SetProfile(profile); } |
| 110 | 109 |
| 111 // SessionStateObserver overrides: | 110 // user_manager::UserManager::UserSessionStateObserver overrides: |
| 112 void ActiveUserChanged(const AccountId& account_id) override { | 111 void ActiveUserChanged(const user_manager::User* active_user) override { |
| 113 SetProfile(ProfileManager::GetActiveUserProfile()); | 112 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 114 } | 113 } |
| 115 | 114 |
| 116 private: | 115 private: |
| 117 void SetProfile(Profile* profile) { | 116 void SetProfile(Profile* profile) { |
| 118 pref_change_registrar_.reset(); | 117 pref_change_registrar_.reset(); |
| 119 | 118 |
| 120 if (profile) { | 119 if (profile) { |
| 121 // TODO(yoshiki): Move following code to PrefHandler. | 120 // TODO(yoshiki): Move following code to PrefHandler. |
| 122 pref_change_registrar_.reset(new PrefChangeRegistrar); | 121 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 Profile* profile = ProfileManager::GetActiveUserProfile(); | 250 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 252 if (ProfileHelper::IsSigninProfile(profile)) | 251 if (ProfileHelper::IsSigninProfile(profile)) |
| 253 SetProfile(profile); | 252 SetProfile(profile); |
| 254 break; | 253 break; |
| 255 } | 254 } |
| 256 case chrome::NOTIFICATION_SESSION_STARTED: | 255 case chrome::NOTIFICATION_SESSION_STARTED: |
| 257 // Update |profile_| when entering a session. | 256 // Update |profile_| when entering a session. |
| 258 SetProfile(ProfileManager::GetActiveUserProfile()); | 257 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 259 | 258 |
| 260 // Add a session state observer to be able to monitor session changes. | 259 // Add a session state observer to be able to monitor session changes. |
| 261 if (!session_state_observer_.get() && ash::Shell::HasInstance()) | 260 if (!session_state_observer_.get()) |
| 262 session_state_observer_.reset( | 261 session_state_observer_.reset( |
| 263 new ash::ScopedSessionStateObserver(this)); | 262 new user_manager::ScopedUserSessionStateObserver(this)); |
| 264 break; | 263 break; |
| 265 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 264 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 266 // Update |profile_| when exiting a session or shutting down. | 265 // Update |profile_| when exiting a session or shutting down. |
| 267 Profile* profile = content::Source<Profile>(source).ptr(); | 266 Profile* profile = content::Source<Profile>(source).ptr(); |
| 268 if (profile_ == profile) | 267 if (profile_ == profile) |
| 269 SetProfile(NULL); | 268 SetProfile(NULL); |
| 270 break; | 269 break; |
| 271 } | 270 } |
| 272 case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { | 271 case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { |
| 273 content::FocusedNodeDetails* node_details = | 272 content::FocusedNodeDetails* node_details = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 287 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 286 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
| 288 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 287 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
| 289 | 288 |
| 290 ash::MagnifierType type_; | 289 ash::MagnifierType type_; |
| 291 bool enabled_; | 290 bool enabled_; |
| 292 bool keep_focus_centered_; | 291 bool keep_focus_centered_; |
| 293 bool observing_focus_change_in_page_; | 292 bool observing_focus_change_in_page_; |
| 294 | 293 |
| 295 content::NotificationRegistrar registrar_; | 294 content::NotificationRegistrar registrar_; |
| 296 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 295 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 297 std::unique_ptr<ash::ScopedSessionStateObserver> session_state_observer_; | 296 std::unique_ptr<user_manager::ScopedUserSessionStateObserver> |
| 297 session_state_observer_; |
| 298 | 298 |
| 299 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 299 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 // static | 302 // static |
| 303 void MagnificationManager::Initialize() { | 303 void MagnificationManager::Initialize() { |
| 304 CHECK(g_magnification_manager == NULL); | 304 CHECK(g_magnification_manager == NULL); |
| 305 g_magnification_manager = new MagnificationManagerImpl(); | 305 g_magnification_manager = new MagnificationManagerImpl(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 // static | 308 // static |
| 309 void MagnificationManager::Shutdown() { | 309 void MagnificationManager::Shutdown() { |
| 310 CHECK(g_magnification_manager); | 310 CHECK(g_magnification_manager); |
| 311 delete g_magnification_manager; | 311 delete g_magnification_manager; |
| 312 g_magnification_manager = NULL; | 312 g_magnification_manager = NULL; |
| 313 } | 313 } |
| 314 | 314 |
| 315 // static | 315 // static |
| 316 MagnificationManager* MagnificationManager::Get() { | 316 MagnificationManager* MagnificationManager::Get() { |
| 317 return g_magnification_manager; | 317 return g_magnification_manager; |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace chromeos | 320 } // namespace chromeos |
| OLD | NEW |