1 // Copyright (c) 2011 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 #ifndef PPAPI_PROXY_PPB_FILE_REF_PROXY_H_
6 #define PPAPI_PROXY_PPB_FILE_REF_PROXY_H_
10 #include "base/basictypes.h"
11 #include "base/memory/linked_ptr.h"
12 #include "ppapi/c/pp_file_info.h"
13 #include "ppapi/c/pp_module.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/pp_time.h"
16 #include "ppapi/proxy/interface_proxy.h"
17 #include "ppapi/proxy/ppapi_proxy_export.h"
18 #include "ppapi/proxy/proxy_completion_callback_factory.h"
19 #include "ppapi/shared_impl/host_resource.h"
20 #include "ppapi/utility/completion_callback_factory.h"
24 struct PPB_FileRef_CreateInfo
;
28 class SerializedVarReturnValue
;
30 class PPAPI_PROXY_EXPORT PPB_FileRef_Proxy
31 : public NON_EXPORTED_BASE(InterfaceProxy
) {
33 explicit PPB_FileRef_Proxy(Dispatcher
* dispatcher
);
34 virtual ~PPB_FileRef_Proxy();
36 static PP_Resource
CreateProxyResource(PP_Instance instance
,
37 PP_Resource file_system
,
39 static PP_Resource
CreateProxyResource(
40 const PPB_FileRef_CreateInfo
& serialized
);
42 // InterfaceProxy implementation.
43 virtual bool OnMessageReceived(const IPC::Message
& msg
);
45 // Takes a resource in the host and converts it into a serialized file ref
46 // "create info" for reconstitution in the plugin. This struct contains all
47 // the necessary information about the file ref.
49 // Various PPAPI functions return file refs from various interfaces, so this
50 // function is public so anybody can send a file ref.
51 static void SerializeFileRef(PP_Resource file_ref
,
52 PPB_FileRef_CreateInfo
* result
);
54 // Creates a plugin resource from the given CreateInfo sent from the host.
55 // The value will be the result of calling SerializeFileRef on the host.
56 // This represents passing the resource ownership to the plugin. This
57 // function also checks the validity of the result and returns 0 on failure.
59 // Various PPAPI functions return file refs from various interfaces, so this
60 // function is public so anybody can receive a file ref.
61 static PP_Resource
DeserializeFileRef(
62 const PPB_FileRef_CreateInfo
& serialized
);
64 static const ApiID kApiID
= API_ID_PPB_FILE_REF
;
67 // Plugin -> host message handlers.
68 void OnMsgCreate(PP_Instance instance
,
69 PP_Resource file_system
,
70 const std::string
& path
,
71 PPB_FileRef_CreateInfo
* result
);
72 void OnMsgGetParent(const HostResource
& host_resource
,
73 PPB_FileRef_CreateInfo
* result
);
74 void OnMsgMakeDirectory(const HostResource
& host_resource
,
75 PP_Bool make_ancestors
,
76 uint32_t callback_id
);
77 void OnMsgTouch(const HostResource
& host_resource
,
79 PP_Time last_modified
,
80 uint32_t callback_id
);
81 void OnMsgDelete(const HostResource
& host_resource
,
82 uint32_t callback_id
);
83 void OnMsgRename(const HostResource
& file_ref
,
84 const HostResource
& new_file_ref
,
85 uint32_t callback_id
);
86 void OnMsgQuery(const HostResource
& file_ref
,
87 uint32_t callback_id
);
88 void OnMsgGetAbsolutePath(const HostResource
& host_resource
,
89 SerializedVarReturnValue result
);
90 void OnMsgReadDirectoryEntries(const HostResource
& file_ref
,
91 uint32_t callback_id
);
93 // Host -> Plugin message handlers.
94 void OnMsgCallbackComplete(const HostResource
& host_resource
,
97 void OnMsgQueryCallbackComplete(const HostResource
& host_resource
,
98 const PP_FileInfo
& info
,
101 void OnMsgReadDirectoryEntriesCallbackComplete(
102 const HostResource
& host_resource
,
103 const std::vector
<ppapi::PPB_FileRef_CreateInfo
>& infos
,
104 const std::vector
<PP_FileType
>& file_types
,
105 uint32_t callback_id
,
108 struct HostCallbackParams
{
109 HostCallbackParams(const HostResource
& host_res
, uint32_t cb_id
)
110 : host_resource(host_res
), callback_id(cb_id
) {
112 HostResource host_resource
;
113 uint32_t callback_id
;
116 void OnCallbackCompleteInHost(int32_t result
,
117 const HostResource
& host_resource
,
118 uint32_t callback_id
);
119 void OnQueryCallbackCompleteInHost(
121 const HostResource
& host_resource
,
122 linked_ptr
<PP_FileInfo
> info
,
123 uint32_t callback_id
);
124 void OnReadDirectoryEntriesCallbackCompleteInHost(
126 HostCallbackParams params
,
127 linked_ptr
<std::vector
<ppapi::PPB_FileRef_CreateInfo
> > files
,
128 linked_ptr
<std::vector
<PP_FileType
> > file_types
);
130 ProxyCompletionCallbackFactory
<PPB_FileRef_Proxy
> callback_factory_
;
132 DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Proxy
);
138 #endif // PPAPI_PROXY_PPB_FILE_REF_PROXY_H_