OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cmath> | 5 #include <cmath> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/browser/gamepad/gamepad_provider.h" | 16 #include "content/browser/gamepad/gamepad_provider.h" |
17 #include "content/browser/gamepad/data_fetcher.h" | 17 #include "content/browser/gamepad/data_fetcher.h" |
18 #include "content/common/gamepad_messages.h" | 18 #include "content/common/gamepad_messages.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include "content/browser/gamepad/data_fetcher_win.h" | 21 #include "content/browser/gamepad/data_fetcher_win.h" |
22 #endif | 22 #endif |
23 | 23 |
24 namespace gamepad { | 24 namespace gamepad { |
25 | 25 |
26 Provider* Provider::instance_ = NULL; | |
27 | |
28 using namespace content; | 26 using namespace content; |
29 | 27 |
30 // Define the default data fetcher that Provider will use if none is supplied. | 28 // Define the default data fetcher that Provider will use if none is supplied. |
31 // (PlatformDataFetcher). | 29 // (PlatformDataFetcher). |
32 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
33 | 31 |
34 typedef DataFetcherWindows PlatformDataFetcher; | 32 typedef DataFetcherWindows PlatformDataFetcher; |
35 | 33 |
36 #else | 34 #else |
37 | 35 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 | 90 |
93 MessageLoop* polling_loop = polling_thread_->message_loop(); | 91 MessageLoop* polling_loop = polling_thread_->message_loop(); |
94 polling_loop->PostTask( | 92 polling_loop->PostTask( |
95 FROM_HERE, | 93 FROM_HERE, |
96 base::Bind(&Provider::DoInitializePollingThread, this)); | 94 base::Bind(&Provider::DoInitializePollingThread, this)); |
97 } | 95 } |
98 | 96 |
99 void Provider::Stop() { | 97 void Provider::Stop() { |
100 DCHECK(MessageLoop::current()->message_loop_proxy() == creator_loop_); | 98 DCHECK(MessageLoop::current()->message_loop_proxy() == creator_loop_); |
101 | 99 |
100 // TODO(scottmg): Don't join the thread. See crbug.com/72286. | |
101 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
jam
2011/11/24 23:16:02
hmm, no way to avoid this in this cl? these usage
| |
102 | |
102 polling_thread_.reset(); | 103 polling_thread_.reset(); |
103 data_fetcher_.reset(); | 104 data_fetcher_.reset(); |
104 } | 105 } |
105 | 106 |
106 void Provider::DoInitializePollingThread() { | 107 void Provider::DoInitializePollingThread() { |
107 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 108 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
108 | 109 |
109 if (!provided_fetcher_.get()) | 110 if (!provided_fetcher_.get()) |
110 provided_fetcher_.reset(new PlatformDataFetcher); | 111 provided_fetcher_.reset(new PlatformDataFetcher); |
111 | 112 |
(...skipping 24 matching lines...) Expand all Loading... | |
136 kDesiredSamplingIntervalMs); | 137 kDesiredSamplingIntervalMs); |
137 } | 138 } |
138 | 139 |
139 GamepadHardwareBuffer* Provider::SharedMemoryAsHardwareBuffer() { | 140 GamepadHardwareBuffer* Provider::SharedMemoryAsHardwareBuffer() { |
140 void* mem = gamepad_shared_memory_.memory(); | 141 void* mem = gamepad_shared_memory_.memory(); |
141 DCHECK(mem); | 142 DCHECK(mem); |
142 return static_cast<GamepadHardwareBuffer*>(mem); | 143 return static_cast<GamepadHardwareBuffer*>(mem); |
143 } | 144 } |
144 | 145 |
145 } // namespace gamepad | 146 } // namespace gamepad |
OLD | NEW |