Index: content/browser/gamepad/gamepad_platform_data_fetcher_android.cc |
diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc b/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc |
index 1e38cc7f5a97a8937e692651ea45dfc1a27d8209..b9b73602b0bfa4e745bef0a5a8dde68cb5f0eda3 100644 |
--- a/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc |
+++ b/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc |
@@ -35,25 +35,25 @@ GamepadPlatformDataFetcherAndroid::RegisterGamepadPlatformDataFetcherAndroid( |
} |
GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() { |
- PauseHint(false); |
} |
GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() { |
PauseHint(true); |
} |
+void GamepadPlatformDataFetcherAndroid::OnAddedToProvider() { |
+ PauseHint(false); |
+} |
+ |
void GamepadPlatformDataFetcherAndroid::GetGamepadData( |
- blink::WebGamepads* pads, |
bool devices_changed_hint) { |
TRACE_EVENT0("GAMEPAD", "GetGamepadData"); |
- pads->length = 0; |
- |
JNIEnv* env = AttachCurrentThread(); |
if (!env) |
return; |
- Java_GamepadList_updateGamepadData(env, reinterpret_cast<intptr_t>(pads)); |
+ Java_GamepadList_updateGamepadData(env, reinterpret_cast<intptr_t>(this)); |
} |
void GamepadPlatformDataFetcherAndroid::PauseHint(bool paused) { |
@@ -66,7 +66,7 @@ void GamepadPlatformDataFetcherAndroid::PauseHint(bool paused) { |
static void SetGamepadData(JNIEnv* env, |
const JavaParamRef<jobject>& obj, |
- jlong gamepads, |
+ jlong data_fetcher, |
jint index, |
jboolean mapping, |
jboolean connected, |
@@ -74,47 +74,47 @@ static void SetGamepadData(JNIEnv* env, |
jlong timestamp, |
const JavaParamRef<jfloatArray>& jaxes, |
const JavaParamRef<jfloatArray>& jbuttons) { |
- DCHECK(gamepads); |
- blink::WebGamepads* pads = reinterpret_cast<WebGamepads*>(gamepads); |
- DCHECK_EQ(pads->length, unsigned(index)); |
+ DCHECK(data_fetcher); |
+ GamepadPlatformDataFetcherAndroid* fetcher = |
+ reinterpret_cast<GamepadPlatformDataFetcherAndroid*>(data_fetcher); |
DCHECK_LT(index, static_cast<int>(blink::WebGamepads::itemsLengthCap)); |
- ++pads->length; |
- |
- blink::WebGamepad& pad = pads->items[index]; |
- |
- pad.connected = connected; |
- |
- pad.timestamp = timestamp; |
- |
// Do not set gamepad parameters for all the gamepad devices that are not |
// attached. |
if (!connected) |
return; |
- // Map the Gamepad DeviceName String to the WebGamepad Id. Ideally it should |
- // be mapped to vendor and product information but it is only available at |
- // kernel level and it can not be queried using class |
- // android.hardware.input.InputManager. |
- // TODO(SaurabhK): Store a cached WebGamePad object in |
- // GamepadPlatformDataFetcherAndroid and only update constant WebGamepad |
- // values when a device has changed. |
- base::string16 device_name; |
- base::android::ConvertJavaStringToUTF16(env, devicename, &device_name); |
- const size_t name_to_copy = |
- std::min(device_name.size(), WebGamepad::idLengthCap - 1); |
- memcpy(pad.id, |
- device_name.data(), |
- name_to_copy * sizeof(base::string16::value_type)); |
- pad.id[name_to_copy] = 0; |
- |
- base::string16 mapping_name = base::UTF8ToUTF16(mapping ? "standard" : ""); |
- const size_t mapping_to_copy = |
- std::min(mapping_name.size(), WebGamepad::mappingLengthCap - 1); |
- memcpy(pad.mapping, |
- mapping_name.data(), |
- mapping_to_copy * sizeof(base::string16::value_type)); |
- pad.mapping[mapping_to_copy] = 0; |
+ PadState* state = fetcher->provider()->GetPadState( |
+ GAMEPAD_SOURCE_ANDROID, index); |
+ |
+ if (!state) |
+ return; |
+ |
+ blink::WebGamepad& pad = state->data; |
+ |
+ // Is this the first time we've seen this device? |
+ if (state->active_state == GAMEPAD_NEWLY_ACTIVE) { |
+ // Map the Gamepad DeviceName String to the WebGamepad Id. Ideally it should |
+ // be mapped to vendor and product information but it is only available at |
+ // kernel level and it can not be queried using class |
+ // android.hardware.input.InputManager. |
+ base::string16 device_name; |
+ base::android::ConvertJavaStringToUTF16(env, devicename, &device_name); |
+ const size_t name_to_copy = |
+ std::min(device_name.size(), WebGamepad::idLengthCap - 1); |
+ memcpy(pad.id, |
+ device_name.data(), |
+ name_to_copy * sizeof(base::string16::value_type)); |
+ pad.id[name_to_copy] = 0; |
+ |
+ base::string16 mapping_name = base::UTF8ToUTF16(mapping ? "standard" : ""); |
+ const size_t mapping_to_copy = |
+ std::min(mapping_name.size(), WebGamepad::mappingLengthCap - 1); |
+ memcpy(pad.mapping, |
+ mapping_name.data(), |
+ mapping_to_copy * sizeof(base::string16::value_type)); |
+ pad.mapping[mapping_to_copy] = 0; |
+ } |
pad.timestamp = timestamp; |