1 // Copyright 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/isolated_file_system_private_resource.h"
8 #include "base/logging.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_file_info.h"
11 #include "ppapi/proxy/file_system_resource.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/resource_message_params.h"
14 #include "ppapi/shared_impl/host_resource.h"
15 #include "ppapi/shared_impl/tracked_callback.h"
16 #include "ppapi/thunk/enter.h"
22 void RunTrackedCallback(scoped_refptr
<TrackedCallback
> callback
,
28 IsolatedFileSystemPrivateResource::IsolatedFileSystemPrivateResource(
29 Connection connection
, PP_Instance instance
)
30 : PluginResource(connection
, instance
) {
31 SendCreate(BROWSER
, PpapiHostMsg_IsolatedFileSystem_Create());
34 IsolatedFileSystemPrivateResource::~IsolatedFileSystemPrivateResource() {
37 thunk::PPB_IsolatedFileSystem_Private_API
*
38 IsolatedFileSystemPrivateResource::AsPPB_IsolatedFileSystem_Private_API() {
42 int32_t IsolatedFileSystemPrivateResource::Open(
43 PP_Instance
/* unused */,
44 PP_IsolatedFileSystemType_Private type
,
45 PP_Resource
* file_system_resource
,
46 scoped_refptr
<TrackedCallback
> callback
) {
47 if (!file_system_resource
)
48 return PP_ERROR_BADARGUMENT
;
50 Call
<PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply
>(BROWSER
,
51 PpapiHostMsg_IsolatedFileSystem_BrowserOpen(type
),
52 base::Bind(&IsolatedFileSystemPrivateResource::OnBrowserOpenComplete
,
53 this, type
, file_system_resource
, callback
));
54 return PP_OK_COMPLETIONPENDING
;
57 void IsolatedFileSystemPrivateResource::OnBrowserOpenComplete(
58 PP_IsolatedFileSystemType_Private type
,
59 PP_Resource
* file_system_resource
,
60 scoped_refptr
<TrackedCallback
> callback
,
61 const ResourceMessageReplyParams
& params
,
62 const std::string
& fsid
) {
63 if (!TrackedCallback::IsPending(callback
))
66 if (params
.result() != PP_OK
) {
67 callback
->Run(params
.result());
71 FileSystemResource
* fs
= new FileSystemResource(
72 connection(), pp_instance(), PP_FILESYSTEMTYPE_ISOLATED
);
73 *file_system_resource
= fs
->GetReference();
74 if (*file_system_resource
== 0)
75 callback
->Run(PP_ERROR_FAILED
);
76 fs
->InitIsolatedFileSystem(
77 fsid
, type
, base::Bind(&RunTrackedCallback
, callback
));