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/ext_crx_file_system_private_resource.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/pp_file_info.h"
10 #include "ppapi/proxy/file_system_resource.h"
11 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/proxy/resource_message_params.h"
13 #include "ppapi/shared_impl/host_resource.h"
14 #include "ppapi/shared_impl/tracked_callback.h"
15 #include "ppapi/thunk/enter.h"
21 void RunTrackedCallback(scoped_refptr
<TrackedCallback
> callback
,
27 ExtCrxFileSystemPrivateResource::ExtCrxFileSystemPrivateResource(
28 Connection connection
, PP_Instance instance
)
29 : PluginResource(connection
, instance
), called_open_(false) {
30 SendCreate(BROWSER
, PpapiHostMsg_Ext_CrxFileSystem_Create());
33 ExtCrxFileSystemPrivateResource::~ExtCrxFileSystemPrivateResource() {
36 thunk::PPB_Ext_CrxFileSystem_Private_API
*
37 ExtCrxFileSystemPrivateResource::AsPPB_Ext_CrxFileSystem_Private_API() {
41 int32_t ExtCrxFileSystemPrivateResource::Open(
42 PP_Instance
/* unused */,
43 PP_Resource
* file_system_resource
,
44 scoped_refptr
<TrackedCallback
> callback
) {
46 return PP_ERROR_FAILED
;
49 if (!file_system_resource
)
50 return PP_ERROR_BADARGUMENT
;
52 Call
<PpapiPluginMsg_Ext_CrxFileSystem_BrowserOpenReply
>(BROWSER
,
53 PpapiHostMsg_Ext_CrxFileSystem_BrowserOpen(),
54 base::Bind(&ExtCrxFileSystemPrivateResource::OnBrowserOpenComplete
, this,
57 return PP_OK_COMPLETIONPENDING
;
60 void ExtCrxFileSystemPrivateResource::OnBrowserOpenComplete(
61 PP_Resource
* file_system_resource
,
62 scoped_refptr
<TrackedCallback
> callback
,
63 const ResourceMessageReplyParams
& params
,
64 const std::string
& fsid
) {
65 if (!TrackedCallback::IsPending(callback
))
68 if (params
.result() != PP_OK
) {
69 callback
->Run(params
.result());
73 FileSystemResource
* fs
= new FileSystemResource(
74 connection(), pp_instance(), PP_FILESYSTEMTYPE_ISOLATED
);
75 *file_system_resource
= fs
->GetReference();
76 if (*file_system_resource
== 0)
77 callback
->Run(PP_ERROR_FAILED
);
78 fs
->InitIsolatedFileSystem(fsid
, base::Bind(&RunTrackedCallback
, callback
));