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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/task_scheduler/post_task.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
13 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 // IMPORTANT! | 21 // IMPORTANT! |
(...skipping 29 matching lines...) Expand all Loading... |
50 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { | 51 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { |
51 return base::Singleton< | 52 return base::Singleton< |
52 BrowserAccessibilityStateImpl, | 53 BrowserAccessibilityStateImpl, |
53 base::LeakySingletonTraits<BrowserAccessibilityStateImpl>>::get(); | 54 base::LeakySingletonTraits<BrowserAccessibilityStateImpl>>::get(); |
54 } | 55 } |
55 | 56 |
56 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() | 57 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() |
57 : BrowserAccessibilityState(), | 58 : BrowserAccessibilityState(), |
58 disable_hot_tracking_(false) { | 59 disable_hot_tracking_(false) { |
59 ResetAccessibilityModeValue(); | 60 ResetAccessibilityModeValue(); |
60 #if defined(OS_WIN) | |
61 // On Windows, UpdateHistograms calls some system functions with unknown | |
62 // runtime, so call it on the file thread to ensure there's no jank. | |
63 // Everything in that method must be safe to call on another thread. | |
64 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; | |
65 #else | |
66 // On all other platforms, UpdateHistograms should be called on the main | |
67 // thread. | |
68 BrowserThread::ID update_histogram_thread = BrowserThread::UI; | |
69 #endif | |
70 | 61 |
71 // We need to AddRef() the leaky singleton so that Bind doesn't | 62 // We need to AddRef() the leaky singleton so that Bind doesn't |
72 // delete it prematurely. | 63 // delete it prematurely. |
73 AddRef(); | 64 AddRef(); |
74 BrowserThread::PostDelayedTask( | 65 // The delay is necessary because assistive technology sometimes isn't |
75 update_histogram_thread, FROM_HERE, | 66 // detected until after the user interacts in some way, so a reasonable delay |
| 67 // gives us better numbers. |
| 68 base::PostDelayedTaskWithTraits( |
| 69 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
76 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this), | 70 base::Bind(&BrowserAccessibilityStateImpl::UpdateHistograms, this), |
77 base::TimeDelta::FromSeconds(ACCESSIBILITY_HISTOGRAM_DELAY_SECS)); | 71 base::TimeDelta::FromSeconds(ACCESSIBILITY_HISTOGRAM_DELAY_SECS)); |
78 } | 72 } |
79 | 73 |
80 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { | 74 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { |
81 } | 75 } |
82 | 76 |
83 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { | 77 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { |
84 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 78 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
85 switches::kDisableRendererAccessibility)) { | 79 switches::kDisableRendererAccessibility)) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 accessibility_mode_.mode() ^ (mode.mode() & accessibility_mode_.mode()); | 185 accessibility_mode_.mode() ^ (mode.mode() & accessibility_mode_.mode()); |
192 accessibility_mode_ = raw_flags; | 186 accessibility_mode_ = raw_flags; |
193 | 187 |
194 std::vector<WebContentsImpl*> web_contents_vector = | 188 std::vector<WebContentsImpl*> web_contents_vector = |
195 WebContentsImpl::GetAllWebContents(); | 189 WebContentsImpl::GetAllWebContents(); |
196 for (size_t i = 0; i < web_contents_vector.size(); ++i) | 190 for (size_t i = 0; i < web_contents_vector.size(); ++i) |
197 web_contents_vector[i]->SetAccessibilityMode(accessibility_mode()); | 191 web_contents_vector[i]->SetAccessibilityMode(accessibility_mode()); |
198 } | 192 } |
199 | 193 |
200 } // namespace content | 194 } // namespace content |
OLD | NEW |