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

Side by Side Diff: content/browser/gamepad/raw_input_data_fetcher_win.cc

Issue 1113913003: Allow Raw Input gamepads to persist across page refreshes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shield_mapping
Patch Set: Created 5 years, 7 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gamepad/raw_input_data_fetcher_win.h" 5 #include "content/browser/gamepad/raw_input_data_fetcher_win.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "content/common/gamepad_hardware_buffer.h" 8 #include "content/common/gamepad_hardware_buffer.h"
9 #include "content/common/gamepad_messages.h" 9 #include "content/common/gamepad_messages.h"
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 } // namespace 35 } // namespace
36 36
37 RawInputDataFetcher::RawInputDataFetcher() 37 RawInputDataFetcher::RawInputDataFetcher()
38 : hid_dll_(base::FilePath(FILE_PATH_LITERAL("hid.dll"))) 38 : hid_dll_(base::FilePath(FILE_PATH_LITERAL("hid.dll")))
39 , rawinput_available_(GetHidDllFunctions()) 39 , rawinput_available_(GetHidDllFunctions())
40 , filter_xinput_(true) 40 , filter_xinput_(true)
41 , events_monitored_(false) {} 41 , events_monitored_(false) {}
42 42
43 RawInputDataFetcher::~RawInputDataFetcher() { 43 RawInputDataFetcher::~RawInputDataFetcher() {
44 ClearControllers();
44 DCHECK(!window_); 45 DCHECK(!window_);
45 DCHECK(!events_monitored_); 46 DCHECK(!events_monitored_);
46 } 47 }
47 48
48 void RawInputDataFetcher::WillDestroyCurrentMessageLoop() { 49 void RawInputDataFetcher::WillDestroyCurrentMessageLoop() {
49 StopMonitor(); 50 StopMonitor();
50 } 51 }
51 52
52 RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) { 53 RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) {
53 int usage_count = arraysize(DeviceUsages); 54 int usage_count = arraysize(DeviceUsages);
54 scoped_ptr<RAWINPUTDEVICE[]> devices(new RAWINPUTDEVICE[usage_count]); 55 scoped_ptr<RAWINPUTDEVICE[]> devices(new RAWINPUTDEVICE[usage_count]);
55 for (int i = 0; i < usage_count; ++i) { 56 for (int i = 0; i < usage_count; ++i) {
56 devices[i].dwFlags = flags; 57 devices[i].dwFlags = flags;
57 devices[i].usUsagePage = 1; 58 devices[i].usUsagePage = 1;
58 devices[i].usUsage = DeviceUsages[i]; 59 devices[i].usUsage = DeviceUsages[i];
59 devices[i].hwndTarget = window_->hwnd(); 60 devices[i].hwndTarget = (flags & RIDEV_REMOVE) ? 0 : window_->hwnd();
60 } 61 }
61 return devices.release(); 62 return devices.release();
62 } 63 }
63 64
64 void RawInputDataFetcher::StartMonitor() { 65 void RawInputDataFetcher::StartMonitor() {
65 if (!rawinput_available_ || events_monitored_) 66 if (!rawinput_available_ || events_monitored_)
66 return; 67 return;
67 68
68 if (!window_) { 69 if (!window_) {
69 window_.reset(new base::win::MessageWindow()); 70 window_.reset(new base::win::MessageWindow());
(...skipping 30 matching lines...) Expand all
100 DCHECK(window_); 101 DCHECK(window_);
101 scoped_ptr<RAWINPUTDEVICE[]> devices(GetRawInputDevices(RIDEV_REMOVE)); 102 scoped_ptr<RAWINPUTDEVICE[]> devices(GetRawInputDevices(RIDEV_REMOVE));
102 103
103 if (!RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages), 104 if (!RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages),
104 sizeof(RAWINPUTDEVICE))) { 105 sizeof(RAWINPUTDEVICE))) {
105 PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE"; 106 PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE";
106 } 107 }
107 108
108 events_monitored_ = false; 109 events_monitored_ = false;
109 window_.reset(); 110 window_.reset();
110 ClearControllers();
111 111
112 // Stop observing message loop destruction if no event is being monitored. 112 // Stop observing message loop destruction if no event is being monitored.
113 base::MessageLoop::current()->RemoveDestructionObserver(this); 113 base::MessageLoop::current()->RemoveDestructionObserver(this);
114 } 114 }
115 115
116 void RawInputDataFetcher::ClearControllers() { 116 void RawInputDataFetcher::ClearControllers() {
117 while (!controllers_.empty()) { 117 while (!controllers_.empty()) {
118 RawGamepadInfo* gamepad_info = controllers_.begin()->second; 118 RawGamepadInfo* gamepad_info = controllers_.begin()->second;
119 controllers_.erase(gamepad_info->handle); 119 controllers_.erase(gamepad_info->handle);
120 delete gamepad_info; 120 delete gamepad_info;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return false; 504 return false;
505 hidd_get_product_string_ = reinterpret_cast<HidDGetStringFunc>( 505 hidd_get_product_string_ = reinterpret_cast<HidDGetStringFunc>(
506 hid_dll_.GetFunctionPointer("HidD_GetProductString")); 506 hid_dll_.GetFunctionPointer("HidD_GetProductString"));
507 if (!hidd_get_product_string_) 507 if (!hidd_get_product_string_)
508 return false; 508 return false;
509 509
510 return true; 510 return true;
511 } 511 }
512 512
513 } // namespace content 513 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698