OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "content/common/content_export.h" | |
11 #include "content/public/renderer/renderer_ppapi_host.h" | |
12 #include "ppapi/host/host_message_context.h" | |
13 #include "ppapi/host/resource_host.h" | |
14 #include "ppapi/shared_impl/ppb_file_io_shared.h" | |
15 #include "ppapi/thunk/ppb_file_ref_api.h" | |
16 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
17 | |
18 using webkit::ppapi::PluginDelegate; | |
19 | |
20 namespace webkit { | |
21 namespace ppapi { | |
22 class QuotaFileIO; | |
23 } // namespace ppapi | |
24 } // namespace webkit | |
25 | |
26 namespace content { | |
27 | |
28 class CONTENT_EXPORT PepperFileIOHost | |
raymes
2012/11/27 06:54:28
You probably don't need to export this (and so can
victorhsieh
2012/11/27 09:44:42
Done.
| |
29 : public ppapi::host::ResourceHost, | |
30 public ppapi::PPB_FileIO_Shared, | |
31 public base::SupportsWeakPtr<PepperFileIOHost> { | |
32 public: | |
33 PepperFileIOHost(RendererPpapiHost* host, | |
34 PP_Instance instance, | |
35 PP_Resource resource); | |
36 virtual ~PepperFileIOHost(); | |
37 | |
38 virtual int32_t OnResourceMessageReceived( | |
raymes
2012/11/26 22:30:54
Add "ppapi::host::ResourceHost override"
victorhsieh
2012/11/27 09:44:42
Done.
| |
39 const IPC::Message& msg, | |
40 ppapi::host::HostMessageContext* context) OVERRIDE; | |
41 | |
42 private: | |
43 int32_t OnHostMsgOpen( | |
44 ppapi::host::HostMessageContext* context, | |
raymes
2012/11/26 22:30:54
nit: please move this to the previous line and ind
victorhsieh
2012/11/27 09:44:42
Done.
| |
45 PP_Resource file_ref_resource, | |
46 int32_t open_flags); | |
47 int32_t OnHostMsgQuery( | |
48 ppapi::host::HostMessageContext* context); | |
49 int32_t OnHostMsgTouch( | |
50 ppapi::host::HostMessageContext* context, | |
51 PP_Time last_access_time, | |
52 PP_Time last_modified_time); | |
53 int32_t OnHostMsgRead( | |
54 ppapi::host::HostMessageContext* context, | |
55 int64_t offset, | |
56 int32_t bytes_to_read); | |
57 int32_t OnHostMsgWrite( | |
58 ppapi::host::HostMessageContext* context, | |
59 int64_t offset, | |
60 const std::string& buffer); | |
61 int32_t OnHostMsgSetLength( | |
62 ppapi::host::HostMessageContext* context, | |
63 int64_t length); | |
64 int32_t OnHostMsgClose( | |
65 ppapi::host::HostMessageContext* context); | |
66 int32_t OnHostMsgFlush( | |
67 ppapi::host::HostMessageContext* context); | |
68 // Trusted API. | |
69 int32_t OnHostMsgWillWrite( | |
70 ppapi::host::HostMessageContext* context, | |
71 int64_t offset, | |
72 int32_t bytes_to_write); | |
73 int32_t OnHostMsgWillSetLength( | |
74 ppapi::host::HostMessageContext* context, | |
75 int64_t length); | |
76 | |
77 // PPB_FileIO_Shared implementations. | |
78 virtual int32_t CommonPreCondition(bool should_be_open, | |
79 OperationType new_op) OVERRIDE; | |
80 virtual void CommonPostCondition(OperationType new_op) OVERRIDE; | |
81 virtual int32_t OpenValidated(PP_Resource file_ref_resource, | |
82 ppapi::thunk::PPB_FileRef_API* file_ref_api, | |
83 int32_t open_flags) OVERRIDE; | |
84 virtual int32_t QueryValidated() OVERRIDE; | |
85 virtual int32_t TouchValidated(PP_Time last_access_time, | |
86 PP_Time last_modified_time) OVERRIDE; | |
87 virtual int32_t ReadValidated(int64_t offset, | |
88 int32_t bytes_to_read) OVERRIDE; | |
89 virtual int32_t WriteValidated(int64_t offset, | |
90 const char* buffer, | |
91 int32_t bytes_to_write) OVERRIDE; | |
92 virtual int32_t SetLengthValidated(int64_t length) OVERRIDE; | |
93 virtual int32_t FlushValidated() OVERRIDE; | |
94 | |
95 // Callback handlers. These mostly convert the PlatformFileError to the | |
96 // PP_Error code and send back the reply. Note that the argument | |
97 // ReplyMessageContext is copied so that we have a closure containing all | |
98 // necessary information to reply. This enables the host to handle operations | |
99 // statelessly and parallelly. | |
raymes
2012/11/27 06:54:28
parallely -> in parallel
victorhsieh
2012/11/27 09:44:42
Done.
| |
100 void ExecutePlatformGeneralCallback( | |
101 ppapi::host::ReplyMessageContext reply_context, | |
102 base::PlatformFileError error_code); | |
103 void ExecutePlatformOpenFileCallback( | |
104 ppapi::host::ReplyMessageContext reply_context, | |
105 base::PlatformFileError error_code, | |
106 base::PassPlatformFile file); | |
107 void ExecutePlatformOpenFileSystemURLCallback( | |
108 ppapi::host::ReplyMessageContext reply_context, | |
109 base::PlatformFileError error_code, | |
110 base::PassPlatformFile file, | |
111 const PluginDelegate::NotifyCloseFileCallback& callback); | |
112 void ExecutePlatformQueryCallback( | |
113 ppapi::host::ReplyMessageContext reply_context, | |
114 base::PlatformFileError error_code, | |
115 const base::PlatformFileInfo& file_info); | |
116 void ExecutePlatformReadCallback( | |
117 ppapi::host::ReplyMessageContext reply_context, | |
118 base::PlatformFileError error_code, | |
119 const char* data, int bytes_read); | |
120 void ExecutePlatformWriteCallback( | |
121 ppapi::host::ReplyMessageContext reply_context, | |
122 base::PlatformFileError error_code, | |
123 int bytes_written); | |
124 void ExecutePlatformWillWriteCallback( | |
125 ppapi::host::ReplyMessageContext reply_context, | |
126 base::PlatformFileError error_code, | |
127 int bytes_written); | |
128 | |
129 webkit::ppapi::PluginDelegate* plugin_delegate_; // Not owned. | |
130 | |
131 base::PlatformFile file_; | |
132 | |
133 // The file system type specified in the Open() call. This will be | |
134 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not | |
135 // indicate that the open command actually succeeded. | |
136 PP_FileSystemType file_system_type_; | |
137 | |
138 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | |
139 GURL file_system_url_; | |
140 | |
141 // Callback function for notifying when the file handle is closed. | |
142 PluginDelegate::NotifyCloseFileCallback notify_close_file_callback_; | |
143 | |
144 // Pointer to a QuotaFileIO instance, which is valid only while a file | |
145 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. | |
146 scoped_ptr<webkit::ppapi::QuotaFileIO> quota_file_io_; | |
147 | |
148 // A temporary storage just to pass a ReplyMessageContext from | |
149 // OnHostMsg{OP} to {OP}Validated. It is a short-living data and must be | |
raymes
2012/11/27 06:54:28
"It is a short-living" -> "It is short-living"
victorhsieh
2012/11/27 09:44:42
Done.
raymes
2012/11/27 16:41:30
Also this doesn't seem updated.
victorhsieh
2012/11/28 04:11:55
Oops, it's somehow got reverted. Done.
| |
150 // copied in {OP}Validated immediately. In fact, it is copied to the | |
151 // closure of platform operation callback via Bind. | |
152 ppapi::host::ReplyMessageContext temp_reply_context_; | |
153 | |
154 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); | |
157 }; | |
158 | |
159 } // namespace content | |
160 | |
161 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
OLD | NEW |