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"
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
;
18 FileSystemResource::FileSystemResource(Connection connection
,
20 PP_FileSystemType type
)
21 : PluginResource(connection
, instance
),
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
,
32 int pending_renderer_id
,
33 int pending_browser_id
,
34 PP_FileSystemType type
)
35 : PluginResource(connection
, instance
),
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() {
50 int32_t FileSystemResource::Open(int64_t expected_size
,
51 scoped_refptr
<TrackedCallback
> callback
) {
52 DCHECK(type_
!= PP_FILESYSTEMTYPE_ISOLATED
);
54 return PP_ERROR_FAILED
;
57 Call
<PpapiPluginMsg_FileSystem_OpenReply
>(RENDERER
,
58 PpapiHostMsg_FileSystem_Open(expected_size
),
59 base::Bind(&FileSystemResource::OpenComplete
,
62 Call
<PpapiPluginMsg_FileSystem_OpenReply
>(BROWSER
,
63 PpapiHostMsg_FileSystem_Open(expected_size
),
64 base::Bind(&FileSystemResource::OpenComplete
,
67 return PP_OK_COMPLETIONPENDING
;
70 PP_FileSystemType
FileSystemResource::GetType() {
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
79 DCHECK(type_
== PP_FILESYSTEMTYPE_ISOLATED
);
81 return PP_ERROR_FAILED
;
84 Call
<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply
>(RENDERER
,
85 PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid
),
86 base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete
,
89 Call
<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply
>(BROWSER
,
90 PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid
),
91 base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete
,
94 return PP_OK_COMPLETIONPENDING
;
97 void FileSystemResource::OpenComplete(
98 scoped_refptr
<TrackedCallback
> callback
,
99 const ResourceMessageReplyParams
& params
) {
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
) {
110 // Received callback from browser and renderer.
111 if (callback_count_
== 2)
112 callback
.Run(params
.result());