OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ | |
6 #define PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ | |
7 | |
8 #include <string> | |
9 | |
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" | |
21 | |
22 namespace ppapi { | |
23 | |
24 struct PPB_FileRef_CreateInfo; | |
25 | |
26 namespace proxy { | |
27 | |
28 class SerializedVarReturnValue; | |
29 | |
30 class PPAPI_PROXY_EXPORT PPB_FileRef_Proxy | |
31 : public NON_EXPORTED_BASE(InterfaceProxy) { | |
32 public: | |
33 explicit PPB_FileRef_Proxy(Dispatcher* dispatcher); | |
34 virtual ~PPB_FileRef_Proxy(); | |
35 | |
36 static PP_Resource CreateProxyResource(PP_Instance instance, | |
37 PP_Resource file_system, | |
38 const char* path); | |
39 static PP_Resource CreateProxyResource( | |
40 const PPB_FileRef_CreateInfo& serialized); | |
41 | |
42 // InterfaceProxy implementation. | |
43 virtual bool OnMessageReceived(const IPC::Message& msg); | |
44 | |
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. | |
48 // | |
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); | |
53 | |
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. | |
58 // | |
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); | |
63 | |
64 static const ApiID kApiID = API_ID_PPB_FILE_REF; | |
65 | |
66 private: | |
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, | |
78 PP_Time last_access, | |
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); | |
92 | |
93 // Host -> Plugin message handlers. | |
94 void OnMsgCallbackComplete(const HostResource& host_resource, | |
95 uint32_t callback_id, | |
96 int32_t result); | |
97 void OnMsgQueryCallbackComplete(const HostResource& host_resource, | |
98 const PP_FileInfo& info, | |
99 uint32_t callback_id, | |
100 int32_t result); | |
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, | |
106 int32_t result); | |
107 | |
108 struct HostCallbackParams { | |
109 HostCallbackParams(const HostResource& host_res, uint32_t cb_id) | |
110 : host_resource(host_res), callback_id(cb_id) { | |
111 } | |
112 HostResource host_resource; | |
113 uint32_t callback_id; | |
114 }; | |
115 | |
116 void OnCallbackCompleteInHost(int32_t result, | |
117 const HostResource& host_resource, | |
118 uint32_t callback_id); | |
119 void OnQueryCallbackCompleteInHost( | |
120 int32_t result, | |
121 const HostResource& host_resource, | |
122 linked_ptr<PP_FileInfo> info, | |
123 uint32_t callback_id); | |
124 void OnReadDirectoryEntriesCallbackCompleteInHost( | |
125 int32_t result, | |
126 HostCallbackParams params, | |
127 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, | |
128 linked_ptr<std::vector<PP_FileType> > file_types); | |
129 | |
130 ProxyCompletionCallbackFactory<PPB_FileRef_Proxy> callback_factory_; | |
131 | |
132 DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Proxy); | |
133 }; | |
134 | |
135 } // namespace proxy | |
136 } // namespace ppapi | |
137 | |
138 #endif // PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ | |
OLD | NEW |