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 #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), |
| 53 keep_focus_centered_(false), | 52 keep_focus_centered_(false), |
| 54 observing_focus_change_in_page_(false) { | 53 observing_focus_change_in_page_(false) { |
| 55 registrar_.Add(this, | 54 registrar_.Add(this, |
| 56 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 55 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 57 content::NotificationService::AllSources()); | 56 content::NotificationService::AllSources()); |
| 58 registrar_.Add(this, | 57 registrar_.Add(this, |
| 59 chrome::NOTIFICATION_SESSION_STARTED, | 58 chrome::NOTIFICATION_SESSION_STARTED, |
| 60 content::NotificationService::AllSources()); | 59 content::NotificationService::AllSources()); |
| 61 registrar_.Add(this, | 60 registrar_.Add(this, |
| 62 chrome::NOTIFICATION_PROFILE_DESTROYED, | 61 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 63 content::NotificationService::AllSources()); | 62 content::NotificationService::AllSources()); |
| 64 } | 63 } |
| 65 | 64 |
| 66 ~MagnificationManagerImpl() override { | 65 ~MagnificationManagerImpl() override { |
| 67 CHECK(this == g_magnification_manager); | 66 CHECK(this == g_magnification_manager); |
| 67 | |
| 68 session_state_observer_.reset(); | |
|
James Cook
2017/02/27 21:20:28
ditto
xiyuan
2017/02/27 22:16:22
Removed, same as the one in AccessibilityManager
| |
| 68 } | 69 } |
| 69 | 70 |
| 70 // MagnificationManager implimentation: | 71 // MagnificationManager implimentation: |
| 71 bool IsMagnifierEnabled() const override { return enabled_; } | 72 bool IsMagnifierEnabled() const override { return enabled_; } |
| 72 | 73 |
| 73 ash::MagnifierType GetMagnifierType() const override { return type_; } | 74 ash::MagnifierType GetMagnifierType() const override { return type_; } |
| 74 | 75 |
| 75 void SetMagnifierEnabled(bool enabled) override { | 76 void SetMagnifierEnabled(bool enabled) override { |
| 76 if (!profile_) | 77 if (!profile_) |
| 77 return; | 78 return; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 101 double GetSavedScreenMagnifierScale() const override { | 102 double GetSavedScreenMagnifierScale() const override { |
| 102 if (!profile_) | 103 if (!profile_) |
| 103 return std::numeric_limits<double>::min(); | 104 return std::numeric_limits<double>::min(); |
| 104 | 105 |
| 105 return profile_->GetPrefs()->GetDouble( | 106 return profile_->GetPrefs()->GetDouble( |
| 106 prefs::kAccessibilityScreenMagnifierScale); | 107 prefs::kAccessibilityScreenMagnifierScale); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void SetProfileForTest(Profile* profile) override { SetProfile(profile); } | 110 void SetProfileForTest(Profile* profile) override { SetProfile(profile); } |
| 110 | 111 |
| 111 // SessionStateObserver overrides: | 112 // user_manager::UserManager::UserSessionStateObserver overrides: |
| 112 void ActiveUserChanged(const AccountId& account_id) override { | 113 void ActiveUserChanged(const user_manager::User* active_user) override { |
| 113 SetProfile(ProfileManager::GetActiveUserProfile()); | 114 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 private: | 117 private: |
| 117 void SetProfile(Profile* profile) { | 118 void SetProfile(Profile* profile) { |
| 118 pref_change_registrar_.reset(); | 119 pref_change_registrar_.reset(); |
| 119 | 120 |
| 120 if (profile) { | 121 if (profile) { |
| 121 // TODO(yoshiki): Move following code to PrefHandler. | 122 // TODO(yoshiki): Move following code to PrefHandler. |
| 122 pref_change_registrar_.reset(new PrefChangeRegistrar); | 123 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 Profile* profile = ProfileManager::GetActiveUserProfile(); | 252 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 252 if (ProfileHelper::IsSigninProfile(profile)) | 253 if (ProfileHelper::IsSigninProfile(profile)) |
| 253 SetProfile(profile); | 254 SetProfile(profile); |
| 254 break; | 255 break; |
| 255 } | 256 } |
| 256 case chrome::NOTIFICATION_SESSION_STARTED: | 257 case chrome::NOTIFICATION_SESSION_STARTED: |
| 257 // Update |profile_| when entering a session. | 258 // Update |profile_| when entering a session. |
| 258 SetProfile(ProfileManager::GetActiveUserProfile()); | 259 SetProfile(ProfileManager::GetActiveUserProfile()); |
| 259 | 260 |
| 260 // Add a session state observer to be able to monitor session changes. | 261 // Add a session state observer to be able to monitor session changes. |
| 261 if (!session_state_observer_.get() && ash::Shell::HasInstance()) | 262 if (!session_state_observer_.get()) |
| 262 session_state_observer_.reset( | 263 session_state_observer_.reset( |
| 263 new ash::ScopedSessionStateObserver(this)); | 264 new user_manager::ScopedUserSessionStateObserver(this)); |
| 264 break; | 265 break; |
| 265 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 266 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 266 // Update |profile_| when exiting a session or shutting down. | 267 // Update |profile_| when exiting a session or shutting down. |
| 267 Profile* profile = content::Source<Profile>(source).ptr(); | 268 Profile* profile = content::Source<Profile>(source).ptr(); |
| 268 if (profile_ == profile) | 269 if (profile_ == profile) |
| 269 SetProfile(NULL); | 270 SetProfile(NULL); |
| 270 break; | 271 break; |
| 271 } | 272 } |
| 272 case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { | 273 case content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE: { |
| 273 content::FocusedNodeDetails* node_details = | 274 content::FocusedNodeDetails* node_details = |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 287 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; | 288 AccessibilityManager::PrefHandler magnifier_type_pref_handler_; |
| 288 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; | 289 AccessibilityManager::PrefHandler magnifier_scale_pref_handler_; |
| 289 | 290 |
| 290 ash::MagnifierType type_; | 291 ash::MagnifierType type_; |
| 291 bool enabled_; | 292 bool enabled_; |
| 292 bool keep_focus_centered_; | 293 bool keep_focus_centered_; |
| 293 bool observing_focus_change_in_page_; | 294 bool observing_focus_change_in_page_; |
| 294 | 295 |
| 295 content::NotificationRegistrar registrar_; | 296 content::NotificationRegistrar registrar_; |
| 296 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 297 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
| 297 std::unique_ptr<ash::ScopedSessionStateObserver> session_state_observer_; | 298 std::unique_ptr<user_manager::ScopedUserSessionStateObserver> |
| 299 session_state_observer_; | |
| 298 | 300 |
| 299 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); | 301 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl); |
| 300 }; | 302 }; |
| 301 | 303 |
| 302 // static | 304 // static |
| 303 void MagnificationManager::Initialize() { | 305 void MagnificationManager::Initialize() { |
| 304 CHECK(g_magnification_manager == NULL); | 306 CHECK(g_magnification_manager == NULL); |
| 305 g_magnification_manager = new MagnificationManagerImpl(); | 307 g_magnification_manager = new MagnificationManagerImpl(); |
| 306 } | 308 } |
| 307 | 309 |
| 308 // static | 310 // static |
| 309 void MagnificationManager::Shutdown() { | 311 void MagnificationManager::Shutdown() { |
| 310 CHECK(g_magnification_manager); | 312 CHECK(g_magnification_manager); |
| 311 delete g_magnification_manager; | 313 delete g_magnification_manager; |
| 312 g_magnification_manager = NULL; | 314 g_magnification_manager = NULL; |
| 313 } | 315 } |
| 314 | 316 |
| 315 // static | 317 // static |
| 316 MagnificationManager* MagnificationManager::Get() { | 318 MagnificationManager* MagnificationManager::Get() { |
| 317 return g_magnification_manager; | 319 return g_magnification_manager; |
| 318 } | 320 } |
| 319 | 321 |
| 320 } // namespace chromeos | 322 } // namespace chromeos |
| OLD | NEW |