Revert 233414 "x11: Move XInput2 availability information out of..."
[chromium-blink-merge.git] / ppapi / proxy / file_system_resource.cc
blobaf1928b4c66c73ee486a46ce4b861ec8f23e211d
1 // Copyright (c) 2013 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.
5 #include "ppapi/proxy/file_system_resource.h"
7 #include "base/bind.h"
8 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/tracked_callback.h"
13 using ppapi::thunk::PPB_FileSystem_API;
15 namespace ppapi {
16 namespace proxy {
18 FileSystemResource::FileSystemResource(Connection connection,
19 PP_Instance instance,
20 PP_FileSystemType type)
21 : PluginResource(connection, instance),
22 type_(type),
23 called_open_(false),
24 callback_count_(0) {
25 DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID);
26 SendCreate(RENDERER, PpapiHostMsg_FileSystem_Create(type_));
27 SendCreate(BROWSER, PpapiHostMsg_FileSystem_Create(type_));
30 FileSystemResource::FileSystemResource(Connection connection,
31 PP_Instance instance,
32 int pending_renderer_id,
33 int pending_browser_id,
34 PP_FileSystemType type)
35 : PluginResource(connection, instance),
36 type_(type),
37 called_open_(true) {
38 DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID);
39 AttachToPendingHost(RENDERER, pending_renderer_id);
40 AttachToPendingHost(BROWSER, pending_browser_id);
43 FileSystemResource::~FileSystemResource() {
46 PPB_FileSystem_API* FileSystemResource::AsPPB_FileSystem_API() {
47 return this;
50 int32_t FileSystemResource::Open(int64_t expected_size,
51 scoped_refptr<TrackedCallback> callback) {
52 DCHECK(type_ != PP_FILESYSTEMTYPE_ISOLATED);
53 if (called_open_)
54 return PP_ERROR_FAILED;
55 called_open_ = true;
57 Call<PpapiPluginMsg_FileSystem_OpenReply>(RENDERER,
58 PpapiHostMsg_FileSystem_Open(expected_size),
59 base::Bind(&FileSystemResource::OpenComplete,
60 this,
61 callback));
62 Call<PpapiPluginMsg_FileSystem_OpenReply>(BROWSER,
63 PpapiHostMsg_FileSystem_Open(expected_size),
64 base::Bind(&FileSystemResource::OpenComplete,
65 this,
66 callback));
67 return PP_OK_COMPLETIONPENDING;
70 PP_FileSystemType FileSystemResource::GetType() {
71 return type_;
74 int32_t FileSystemResource::InitIsolatedFileSystem(
75 const std::string& fsid,
76 const base::Callback<void(int32_t)>& callback) {
77 // This call is mutually exclusive with Open() above, so we can reuse the
78 // called_open state.
79 DCHECK(type_ == PP_FILESYSTEMTYPE_ISOLATED);
80 if (called_open_)
81 return PP_ERROR_FAILED;
82 called_open_ = true;
84 Call<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply>(RENDERER,
85 PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid),
86 base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete,
87 this,
88 callback));
89 Call<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply>(BROWSER,
90 PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid),
91 base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete,
92 this,
93 callback));
94 return PP_OK_COMPLETIONPENDING;
97 void FileSystemResource::OpenComplete(
98 scoped_refptr<TrackedCallback> callback,
99 const ResourceMessageReplyParams& params) {
100 ++callback_count_;
101 // Received callback from browser and renderer.
102 if (callback_count_ == 2)
103 callback->Run(params.result());
106 void FileSystemResource::InitIsolatedFileSystemComplete(
107 const base::Callback<void(int32_t)>& callback,
108 const ResourceMessageReplyParams& params) {
109 ++callback_count_;
110 // Received callback from browser and renderer.
111 if (callback_count_ == 2)
112 callback.Run(params.result());
115 } // namespace proxy
116 } // namespace ppapi