| 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 "content/browser/accessibility/browser_accessibility_state_impl.h" | 5 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/timer.h" | 9 #include "base/timer.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 accessibility_mode_ = AccessibilityModeEditableTextOnly; | 43 accessibility_mode_ = AccessibilityModeEditableTextOnly; |
| 44 } | 44 } |
| 45 #endif // defined(OS_WIN) | 45 #endif // defined(OS_WIN) |
| 46 | 46 |
| 47 if (CommandLine::ForCurrentProcess()->HasSwitch( | 47 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 48 switches::kForceRendererAccessibility)) { | 48 switches::kForceRendererAccessibility)) { |
| 49 accessibility_mode_ = AccessibilityModeComplete; | 49 accessibility_mode_ = AccessibilityModeComplete; |
| 50 } | 50 } |
| 51 | 51 |
| 52 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 53 // On Windows, UpdateHistogram calls some system functions with unknown | 53 // On Windows, UpdateHistograms calls some system functions with unknown |
| 54 // runtime, so call it on the file thread to ensure there's no jank. | 54 // runtime, so call it on the file thread to ensure there's no jank. |
| 55 // Everything in that method must be safe to call on another thread. | 55 // Everything in that method must be safe to call on another thread. |
| 56 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; | 56 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; |
| 57 #else | 57 #else |
| 58 // On all other platforms, UpdateHistogram should be called on the main | 58 // On all other platforms, UpdateHistograms should be called on the main |
| 59 // thread. | 59 // thread. |
| 60 BrowserThread::ID update_histogram_thread = BrowserThread::UI; | 60 BrowserThread::ID update_histogram_thread = BrowserThread::UI; |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 // We need to AddRef() the leaky singleton so that Bind doesn't | 63 // We need to AddRef() the leaky singleton so that Bind doesn't |
| 64 // delete it prematurely. | 64 // delete it prematurely. |
| 65 AddRef(); | 65 AddRef(); |
| 66 BrowserThread::PostDelayedTask( | 66 BrowserThread::PostDelayedTask( |
| 67 update_histogram_thread, FROM_HERE, | 67 update_histogram_thread, FROM_HERE, |
| 68 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistogram, this), | 68 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this), |
| 69 base::TimeDelta::FromSeconds(kAccessibilityHistogramDelaySecs)); | 69 base::TimeDelta::FromSeconds(kAccessibilityHistogramDelaySecs)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { | 72 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { | 75 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { |
| 76 if (CommandLine::ForCurrentProcess()->HasSwitch( | 76 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 77 switches::kDisableRendererAccessibility)) { | 77 switches::kDisableRendererAccessibility)) { |
| 78 return; | 78 return; |
| 79 } | 79 } |
| 80 SetAccessibilityMode(AccessibilityModeComplete); | 80 SetAccessibilityMode(AccessibilityModeComplete); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void BrowserAccessibilityStateImpl::OnAccessibilityEnabledManually() { | 83 void BrowserAccessibilityStateImpl::OnAccessibilityEnabledManually() { |
| 84 // We may want to do something different with this later. | 84 // We may want to do something different with this later. |
| 85 SetAccessibilityMode(AccessibilityModeComplete); | 85 SetAccessibilityMode(AccessibilityModeComplete); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { | 88 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { |
| 89 return (accessibility_mode_ == AccessibilityModeComplete); | 89 return (accessibility_mode_ == AccessibilityModeComplete); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void BrowserAccessibilityStateImpl::AddHistogramCallback( | 92 void BrowserAccessibilityStateImpl::AddHistogramCallback( |
| 93 base::Closure callback) { | 93 base::Closure callback) { |
| 94 histogram_callbacks_.push_back(callback); | 94 histogram_callbacks_.push_back(callback); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void BrowserAccessibilityStateImpl::UpdateHistogram() { | 97 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { |
| 98 UpdateHistograms(); |
| 99 } |
| 100 |
| 101 void BrowserAccessibilityStateImpl::UpdateHistograms() { |
| 98 UpdatePlatformSpecificHistograms(); | 102 UpdatePlatformSpecificHistograms(); |
| 99 | 103 |
| 100 for (size_t i = 0; i < histogram_callbacks_.size(); ++i) | 104 for (size_t i = 0; i < histogram_callbacks_.size(); ++i) |
| 101 histogram_callbacks_[i].Run(); | 105 histogram_callbacks_[i].Run(); |
| 102 | 106 |
| 103 UMA_HISTOGRAM_BOOLEAN("Accessibility.State", IsAccessibleBrowser()); | 107 UMA_HISTOGRAM_BOOLEAN("Accessibility.State", IsAccessibleBrowser()); |
| 104 UMA_HISTOGRAM_BOOLEAN("Accessibility.InvertedColors", | 108 UMA_HISTOGRAM_BOOLEAN("Accessibility.InvertedColors", |
| 105 gfx::IsInvertedColorScheme()); | 109 gfx::IsInvertedColorScheme()); |
| 106 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", | 110 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", |
| 107 CommandLine::ForCurrentProcess()->HasSwitch( | 111 CommandLine::ForCurrentProcess()->HasSwitch( |
| 108 switches::kForceRendererAccessibility)); | 112 switches::kForceRendererAccessibility)); |
| 109 } | 113 } |
| 110 | 114 |
| 111 #if !defined(OS_WIN) | 115 #if !defined(OS_WIN) |
| 112 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { | 116 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { |
| 113 } | 117 } |
| 114 #endif | 118 #endif |
| 115 | 119 |
| 116 AccessibilityMode BrowserAccessibilityStateImpl::GetAccessibilityMode() { | 120 AccessibilityMode BrowserAccessibilityStateImpl::GetAccessibilityMode() { |
| 117 return accessibility_mode_; | 121 return accessibility_mode_; |
| 118 } | 122 } |
| 119 | 123 |
| 120 void BrowserAccessibilityStateImpl::SetAccessibilityMode( | 124 void BrowserAccessibilityStateImpl::SetAccessibilityMode( |
| 121 AccessibilityMode mode) { | 125 AccessibilityMode mode) { |
| 122 accessibility_mode_ = mode; | 126 accessibility_mode_ = mode; |
| 123 } | 127 } |
| 124 | 128 |
| 125 } // namespace content | 129 } // namespace content |
| OLD | NEW |