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

Side by Side Diff: ppapi/thunk/ppb_gamepad_thunk.cc

Issue 11359063: Refactor the way singleton-style resources are exposed via PPB_Instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 <string.h> 5 #include <string.h>
6 6
7 #include "ppapi/c/ppb_gamepad.h" 7 #include "ppapi/c/ppb_gamepad.h"
8 #include "ppapi/thunk/thunk.h" 8 #include "ppapi/thunk/thunk.h"
9 #include "ppapi/thunk/enter.h" 9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_gamepad_api.h" 10 #include "ppapi/thunk/ppb_gamepad_api.h"
11 #include "ppapi/thunk/ppb_instance_api.h" 11 #include "ppapi/thunk/ppb_instance_api.h"
12 #include "ppapi/thunk/resource_creation_api.h" 12 #include "ppapi/thunk/resource_creation_api.h"
13 13
14 namespace ppapi { 14 namespace ppapi {
15 namespace thunk { 15 namespace thunk {
16 16
17 namespace { 17 namespace {
18 18
19 void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) { 19 void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) {
20 EnterInstance enter(instance); 20 EnterInstanceAPI<PPB_Gamepad_API> enter(instance, GAMEPAD_SINGLETON_ID);
21 if (enter.succeeded()) { 21 if (enter.succeeded()) {
22 PPB_Gamepad_API* api = enter.functions()->GetGamepadAPI(instance); 22 enter.functions()->Sample(data);
23 if (api) { 23 return;
24 api->Sample(data);
25 return;
26 }
27 } 24 }
28 // Failure, zero out. 25 // Failure, zero out.
29 memset(data, 0, sizeof(PP_GamepadsSampleData)); 26 memset(data, 0, sizeof(PP_GamepadsSampleData));
30 } 27 }
31 28
32 const PPB_Gamepad g_ppb_gamepad_thunk = { 29 const PPB_Gamepad g_ppb_gamepad_thunk = {
33 &SampleGamepads, 30 &SampleGamepads,
34 }; 31 };
35 32
36 } // namespace 33 } // namespace
37 34
38 const PPB_Gamepad* GetPPB_Gamepad_1_0_Thunk() { 35 const PPB_Gamepad* GetPPB_Gamepad_1_0_Thunk() {
39 return &g_ppb_gamepad_thunk; 36 return &g_ppb_gamepad_thunk;
40 } 37 }
41 38
42 } // namespace thunk 39 } // namespace thunk
43 } // namespace ppapi 40 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698