summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/flash_device_id_resource.cc
blob: 39ff63bb7c35215d2280e0f591b2c2d6b7c34049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/proxy/flash_device_id_resource.h"

#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/dispatch_reply_message.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/var.h"

namespace ppapi {
namespace proxy {

FlashDeviceIDResource::FlashDeviceIDResource(Connection connection,
                                             PP_Instance instance)
    : PluginResource(connection, instance),
      dest_(NULL) {
  SendCreateToBrowser(PpapiHostMsg_FlashDeviceID_Create());
}

FlashDeviceIDResource::~FlashDeviceIDResource() {
}

thunk::PPB_Flash_DeviceID_API*
FlashDeviceIDResource::AsPPB_Flash_DeviceID_API() {
  return this;
}

int32_t FlashDeviceIDResource::GetDeviceID(
    PP_Var* id,
    scoped_refptr<TrackedCallback> callback) {
  if (TrackedCallback::IsPending(callback_))
    return PP_ERROR_INPROGRESS;
  if (!id)
    return PP_ERROR_BADARGUMENT;

  dest_ = id;
  callback_ = callback;

  CallBrowser(PpapiHostMsg_FlashDeviceID_GetDeviceID());
  return PP_OK_COMPLETIONPENDING;
}

void FlashDeviceIDResource::OnReplyReceived(
    const ResourceMessageReplyParams& params,
    const IPC::Message& msg) {
  IPC_BEGIN_MESSAGE_MAP(FlashDeviceIDResource, msg)
    PPAPI_DISPATCH_RESOURCE_REPLY(
        PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply,
        OnPluginMsgGetDeviceIDReply)
  IPC_END_MESSAGE_MAP()
}

void FlashDeviceIDResource::OnPluginMsgGetDeviceIDReply(
    const ResourceMessageReplyParams& params,
    const std::string& id) {
  if (params.result() == PP_OK)
    *dest_ = StringVar::StringToPPVar(id);
  else
    *dest_ = PP_MakeUndefined();
  dest_ = NULL;
  TrackedCallback::ClearAndRun(&callback_, params.result());
}

}  // namespace proxy
}  // namespace ppapi