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

Side by Side Diff: chrome/browser/chromeos/accessibility/accessibility_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: Addressed 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/accessibility_manager.h" 5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
6 6
7 #include "ash/autoclick/autoclick_controller.h" 7 #include "ash/autoclick/autoclick_controller.h"
8 #include "ash/high_contrast/high_contrast_controller.h" 8 #include "ash/high_contrast/high_contrast_controller.h"
9 #include "ash/session_state_delegate.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_notifier.h" 11 #include "ash/system/tray/system_tray_notifier.h"
11 #include "ash/wm/event_rewriter_event_filter.h" 12 #include "ash/wm/event_rewriter_event_filter.h"
12 #include "ash/wm/sticky_keys.h" 13 #include "ash/wm/sticky_keys.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
15 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.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 "base/time/time.h" 19 #include "base/time/time.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 autoclick_delay_pref_handler_(prefs::kAutoclickDelayMs), 286 autoclick_delay_pref_handler_(prefs::kAutoclickDelayMs),
286 large_cursor_enabled_(false), 287 large_cursor_enabled_(false),
287 sticky_keys_enabled_(false), 288 sticky_keys_enabled_(false),
288 spoken_feedback_enabled_(false), 289 spoken_feedback_enabled_(false),
289 high_contrast_enabled_(false), 290 high_contrast_enabled_(false),
290 autoclick_enabled_(false), 291 autoclick_enabled_(false),
291 autoclick_delay_ms_(ash::AutoclickController::kDefaultAutoclickDelayMs), 292 autoclick_delay_ms_(ash::AutoclickController::kDefaultAutoclickDelayMs),
292 spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE), 293 spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE),
293 weak_ptr_factory_(this), 294 weak_ptr_factory_(this),
294 should_speak_chrome_vox_announcements_on_user_screen_(true), 295 should_speak_chrome_vox_announcements_on_user_screen_(true),
296 session_state_observer_installed_(false),
295 system_sounds_enabled_(false) { 297 system_sounds_enabled_(false) {
296 notification_registrar_.Add(this, 298 notification_registrar_.Add(this,
297 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 299 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
298 content::NotificationService::AllSources()); 300 content::NotificationService::AllSources());
299 notification_registrar_.Add(this, 301 notification_registrar_.Add(this,
300 chrome::NOTIFICATION_SESSION_STARTED, 302 chrome::NOTIFICATION_SESSION_STARTED,
301 content::NotificationService::AllSources()); 303 content::NotificationService::AllSources());
302 notification_registrar_.Add(this, 304 notification_registrar_.Add(this,
303 chrome::NOTIFICATION_PROFILE_DESTROYED, 305 chrome::NOTIFICATION_PROFILE_DESTROYED,
304 content::NotificationService::AllSources()); 306 content::NotificationService::AllSources());
305 notification_registrar_.Add(this, 307 notification_registrar_.Add(this,
306 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 308 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
307 content::NotificationService::AllSources()); 309 content::NotificationService::AllSources());
308 notification_registrar_.Add(this, 310 notification_registrar_.Add(this,
309 chrome::NOTIFICATION_EXTENSION_REMOVED, 311 chrome::NOTIFICATION_EXTENSION_REMOVED,
310 content::NotificationService::AllSources()); 312 content::NotificationService::AllSources());
311 notification_registrar_.Add(this, 313 notification_registrar_.Add(this,
312 chrome::NOTIFICATION_EXTENSION_UNLOADED, 314 chrome::NOTIFICATION_EXTENSION_UNLOADED,
313 content::NotificationService::AllSources()); 315 content::NotificationService::AllSources());
316
314 GetBrailleController()->AddObserver(this); 317 GetBrailleController()->AddObserver(this);
315 318
316 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 319 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
317 media::SoundsManager* manager = media::SoundsManager::Get(); 320 media::SoundsManager* manager = media::SoundsManager::Get();
318 manager->Initialize(SOUND_SHUTDOWN, 321 manager->Initialize(SOUND_SHUTDOWN,
319 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV)); 322 bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV));
320 manager->Initialize( 323 manager->Initialize(
321 SOUND_SPOKEN_FEEDBACK_ENABLED, 324 SOUND_SPOKEN_FEEDBACK_ENABLED,
322 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV)); 325 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV));
323 manager->Initialize( 326 manager->Initialize(
324 SOUND_SPOKEN_FEEDBACK_DISABLED, 327 SOUND_SPOKEN_FEEDBACK_DISABLED,
325 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV)); 328 bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV));
326 } 329 }
327 330
328 AccessibilityManager::~AccessibilityManager() { 331 AccessibilityManager::~AccessibilityManager() {
329 CHECK(this == g_accessibility_manager); 332 CHECK(this == g_accessibility_manager);
330 333
331 // Component extensions don't always notify us when they're unloaded. Ensure 334 // Component extensions don't always notify us when they're unloaded. Ensure
332 // we clean up ChromeVox observers here. 335 // we clean up ChromeVox observers here.
333 if (profile_) { 336 if (profile_) {
334 extensions::ExtensionSystem::Get(profile_)-> 337 extensions::ExtensionSystem::Get(profile_)->
335 event_router()->UnregisterObserver(this); 338 event_router()->UnregisterObserver(this);
336 } 339 }
340
341 if (session_state_observer_installed_)
342 ash::Shell::GetInstance()->session_state_delegate()->
343 RemoveSessionStateObserver(this);
dmazzoni 2013/12/13 16:15:07 I think we should have a ScopedSessionStateObserve
Mr4D (OOO till 08-26) 2013/12/13 17:21:13 Done.
344 }
345
346 bool AccessibilityManager::ShouldShowAccessibilityMenu() {
347 // If any of the loaded profiles has an accessibility feature turned on, we
dmazzoni 2013/12/13 16:15:07 If they have an accessibility feature turned on, *
Mr4D (OOO till 08-26) 2013/12/13 17:21:13 Done.
348 // should return true to show the menu.
349 std::vector<Profile*> profiles =
350 g_browser_process->profile_manager()->GetLoadedProfiles();
351 for (std::vector<Profile*>::iterator it = profiles.begin();
352 it != profiles.end();
353 ++it) {
354 PrefService* pref_service = (*it)->GetPrefs();
355 if (pref_service->GetBoolean(prefs::kStickyKeysEnabled) ||
356 pref_service->GetBoolean(prefs::kLargeCursorEnabled) ||
357 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled) ||
358 pref_service->GetBoolean(prefs::kHighContrastEnabled) ||
359 pref_service->GetBoolean(prefs::kAutoclickEnabled) ||
360 pref_service->GetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu) ||
361 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled))
362 return true;
363 }
364 return false;
337 } 365 }
338 366
339 void AccessibilityManager::EnableLargeCursor(bool enabled) { 367 void AccessibilityManager::EnableLargeCursor(bool enabled) {
340 if (!profile_) 368 if (!profile_)
341 return; 369 return;
342 370
343 PrefService* pref_service = profile_->GetPrefs(); 371 PrefService* pref_service = profile_->GetPrefs();
344 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled); 372 pref_service->SetBoolean(prefs::kLargeCursorEnabled, enabled);
345 pref_service->CommitPendingWrite(); 373 pref_service->CommitPendingWrite();
346 } 374 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 745
718 profile_ = profile; 746 profile_ = profile;
719 UpdateLargeCursorFromPref(); 747 UpdateLargeCursorFromPref();
720 UpdateStickyKeysFromPref(); 748 UpdateStickyKeysFromPref();
721 UpdateSpokenFeedbackFromPref(); 749 UpdateSpokenFeedbackFromPref();
722 UpdateHighContrastFromPref(); 750 UpdateHighContrastFromPref();
723 UpdateAutoclickFromPref(); 751 UpdateAutoclickFromPref();
724 UpdateAutoclickDelayFromPref(); 752 UpdateAutoclickDelayFromPref();
725 } 753 }
726 754
755 void AccessibilityManager::ActiveUserChanged(const std::string& user_id) {
756 SetProfile(ProfileManager::GetActiveUserProfile());
dmazzoni 2013/12/13 16:15:07 Does this need to take login / lock screen into ac
Mr4D (OOO till 08-26) 2013/12/13 17:21:13 This only gets called when a user switches activel
757 }
758
727 void AccessibilityManager::SetProfileForTest(Profile* profile) { 759 void AccessibilityManager::SetProfileForTest(Profile* profile) {
728 SetProfile(profile); 760 SetProfile(profile);
729 } 761 }
730 762
731 void AccessibilityManager::SetBrailleControllerForTest( 763 void AccessibilityManager::SetBrailleControllerForTest(
732 BrailleController* controller) { 764 BrailleController* controller) {
733 g_braille_controller_for_test = controller; 765 g_braille_controller_for_test = controller;
734 } 766 }
735 767
736 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) { 768 void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 } 817 }
786 } 818 }
787 819
788 void AccessibilityManager::Observe( 820 void AccessibilityManager::Observe(
789 int type, 821 int type,
790 const content::NotificationSource& source, 822 const content::NotificationSource& source,
791 const content::NotificationDetails& details) { 823 const content::NotificationDetails& details) {
792 switch (type) { 824 switch (type) {
793 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { 825 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: {
794 // Update |profile_| when entering the login screen. 826 // Update |profile_| when entering the login screen.
795 Profile* profile = ProfileManager::GetDefaultProfile(); 827 Profile* profile = ProfileManager::GetActiveUserProfile();
796 if (ProfileHelper::IsSigninProfile(profile)) 828 if (ProfileHelper::IsSigninProfile(profile))
797 SetProfile(profile); 829 SetProfile(profile);
798 break; 830 break;
799 } 831 }
800 case chrome::NOTIFICATION_SESSION_STARTED: 832 case chrome::NOTIFICATION_SESSION_STARTED:
801 // Update |profile_| when entering a session. 833 // Update |profile_| when entering a session.
802 SetProfile(ProfileManager::GetDefaultProfile()); 834 SetProfile(ProfileManager::GetActiveUserProfile());
803 835
804 // Ensure ChromeVox makes announcements at the start of new sessions. 836 // Ensure ChromeVox makes announcements at the start of new sessions.
805 should_speak_chrome_vox_announcements_on_user_screen_ = true; 837 should_speak_chrome_vox_announcements_on_user_screen_ = true;
838
839 // Add a session state observer to be able to monitor session changes.
840 if (!session_state_observer_installed_ && ash::Shell::HasInstance()) {
841 session_state_observer_installed_ = true;
842 ash::Shell::GetInstance()->session_state_delegate()->
843 AddSessionStateObserver(this);
844 }
806 break; 845 break;
807 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 846 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
808 // Update |profile_| when exiting a session or shutting down. 847 // Update |profile_| when exiting a session or shutting down.
809 Profile* profile = content::Source<Profile>(source).ptr(); 848 Profile* profile = content::Source<Profile>(source).ptr();
810 if (profile_ == profile) 849 if (profile_ == profile)
811 SetProfile(NULL); 850 SetProfile(NULL);
812 break; 851 break;
813 } 852 }
814 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { 853 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
815 bool is_screen_locked = *content::Details<bool>(details).ptr(); 854 bool is_screen_locked = *content::Details<bool>(details).ptr();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 event_router()->UnregisterObserver(this); 946 event_router()->UnregisterObserver(this);
908 } 947 }
909 } 948 }
910 949
911 void AccessibilityManager::PlaySound(int sound_key) const { 950 void AccessibilityManager::PlaySound(int sound_key) const {
912 if (system_sounds_enabled_) 951 if (system_sounds_enabled_)
913 media::SoundsManager::Get()->Play(sound_key); 952 media::SoundsManager::Get()->Play(sound_key);
914 } 953 }
915 954
916 } // namespace chromeos 955 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698