OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/proxy/flash_device_id_resource.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "ppapi/proxy/dispatch_reply_message.h" | |
10 #include "ppapi/proxy/ppapi_messages.h" | |
11 #include "ppapi/shared_impl/var.h" | |
12 | |
13 namespace ppapi { | |
14 namespace proxy { | |
15 | |
16 FlashDeviceIDResource::FlashDeviceIDResource(Connection connection, | |
17 PP_Instance instance) | |
18 : PluginResource(connection, instance), | |
19 dest_(NULL) { | |
20 SendCreate(BROWSER, PpapiHostMsg_FlashDeviceID_Create()); | |
21 } | |
22 | |
23 FlashDeviceIDResource::~FlashDeviceIDResource() { | |
24 } | |
25 | |
26 thunk::PPB_Flash_DeviceID_API* | |
27 FlashDeviceIDResource::AsPPB_Flash_DeviceID_API() { | |
28 return this; | |
29 } | |
30 | |
31 int32_t FlashDeviceIDResource::GetDeviceID( | |
32 PP_Var* id, | |
33 scoped_refptr<TrackedCallback> callback) { | |
34 if (TrackedCallback::IsPending(callback_)) | |
35 return PP_ERROR_INPROGRESS; | |
36 if (!id) | |
37 return PP_ERROR_BADARGUMENT; | |
38 | |
39 dest_ = id; | |
40 callback_ = callback; | |
41 | |
42 Call<PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply>( | |
43 BROWSER, | |
44 PpapiHostMsg_FlashDeviceID_GetDeviceID(), | |
45 base::Bind(&FlashDeviceIDResource::OnPluginMsgGetDeviceIDReply, this)); | |
46 return PP_OK_COMPLETIONPENDING; | |
47 } | |
48 | |
49 void FlashDeviceIDResource::OnPluginMsgGetDeviceIDReply( | |
50 const ResourceMessageReplyParams& params, | |
51 const std::string& id) { | |
52 if (params.result() == PP_OK) | |
53 *dest_ = StringVar::StringToPPVar(id); | |
54 else | |
55 *dest_ = PP_MakeUndefined(); | |
56 dest_ = NULL; | |
57 callback_->Run(params.result()); | |
58 } | |
59 | |
60 } // namespace proxy | |
61 } // namespace ppapi | |
OLD | NEW |