Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.h

Issue 11419131: Refactor FileIO to the new design (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/public/renderer/renderer_ppapi_host.h"
11 #include "ppapi/host/host_message_context.h"
12 #include "ppapi/host/resource_host.h"
13 #include "ppapi/shared_impl/ppb_file_io_shared.h"
14 #include "ppapi/thunk/ppb_file_ref_api.h"
15 #include "webkit/plugins/ppapi/plugin_delegate.h"
16
17 using webkit::ppapi::PluginDelegate;
18
19 namespace webkit {
20 namespace ppapi {
21 class QuotaFileIO;
22 } // namespace ppapi
23 } // namespace webkit
24
25 namespace content {
26
27 class PepperFileIOHost : public ppapi::host::ResourceHost,
28 public ppapi::PPB_FileIO_Shared,
29 public base::SupportsWeakPtr<PepperFileIOHost> {
30 public:
31 PepperFileIOHost(RendererPpapiHost* host,
32 PP_Instance instance,
33 PP_Resource resource);
34 virtual ~PepperFileIOHost();
35
36 // ppapi::host::ResourceHost override
37 virtual int32_t OnResourceMessageReceived(
38 const IPC::Message& msg,
39 ppapi::host::HostMessageContext* context) OVERRIDE;
40
41 private:
42 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
43 PP_Resource file_ref_resource,
44 int32_t open_flags);
45 int32_t OnHostMsgQuery(ppapi::host::HostMessageContext* context);
46 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context,
47 PP_Time last_access_time,
48 PP_Time last_modified_time);
49 int32_t OnHostMsgRead(ppapi::host::HostMessageContext* context,
50 int64_t offset,
51 int32_t bytes_to_read);
52 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context,
53 int64_t offset,
54 const std::string& buffer);
55 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context,
56 int64_t length);
57 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
58 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
59 // Trusted API.
60 int32_t OnHostMsgGetOSFileDescriptor(
61 ppapi::host::HostMessageContext* context);
62 int32_t OnHostMsgWillWrite(ppapi::host::HostMessageContext* context,
63 int64_t offset,
64 int32_t bytes_to_write);
65 int32_t OnHostMsgWillSetLength(ppapi::host::HostMessageContext* context,
66 int64_t length);
67
68 // PPB_FileIO_Shared implementations.
69 virtual int32_t CommonPreCondition(bool should_be_open,
70 OperationType new_op) OVERRIDE;
71 virtual void CommonPostCondition(OperationType new_op) OVERRIDE;
72 virtual int32_t OpenValidated(PP_Resource file_ref_resource,
73 ppapi::thunk::PPB_FileRef_API* file_ref_api,
74 int32_t open_flags) OVERRIDE;
75 virtual int32_t QueryValidated() OVERRIDE;
76 virtual int32_t TouchValidated(PP_Time last_access_time,
77 PP_Time last_modified_time) OVERRIDE;
78 virtual int32_t ReadValidated(int64_t offset,
79 int32_t bytes_to_read) OVERRIDE;
80 virtual int32_t WriteValidated(int64_t offset,
81 const char* buffer,
82 int32_t bytes_to_write) OVERRIDE;
83 virtual int32_t SetLengthValidated(int64_t length) OVERRIDE;
84 virtual int32_t FlushValidated() OVERRIDE;
85
86 // Callback handlers. These mostly convert the PlatformFileError to the
87 // PP_Error code and send back the reply. Note that the argument
88 // ReplyMessageContext is copied so that we have a closure containing all
89 // necessary information to reply. This enables the host to handle operations
90 // statelessly and parallelly.
91 void ExecutePlatformGeneralCallback(
92 ppapi::host::ReplyMessageContext reply_context,
93 base::PlatformFileError error_code);
94 void ExecutePlatformOpenFileCallback(
95 ppapi::host::ReplyMessageContext reply_context,
96 base::PlatformFileError error_code,
97 base::PassPlatformFile file);
98 void ExecutePlatformOpenFileSystemURLCallback(
99 ppapi::host::ReplyMessageContext reply_context,
100 base::PlatformFileError error_code,
101 base::PassPlatformFile file,
102 const PluginDelegate::NotifyCloseFileCallback& callback);
103 void ExecutePlatformQueryCallback(
104 ppapi::host::ReplyMessageContext reply_context,
105 base::PlatformFileError error_code,
106 const base::PlatformFileInfo& file_info);
107 void ExecutePlatformReadCallback(
108 ppapi::host::ReplyMessageContext reply_context,
109 base::PlatformFileError error_code,
110 const char* data, int bytes_read);
111 void ExecutePlatformWriteCallback(
112 ppapi::host::ReplyMessageContext reply_context,
113 base::PlatformFileError error_code,
114 int bytes_written);
115 void ExecutePlatformWillWriteCallback(
116 ppapi::host::ReplyMessageContext reply_context,
117 base::PlatformFileError error_code,
118 int bytes_written);
119
120 // TODO: eliminate plugin_delegate_ as it's no longer needed.
121 webkit::ppapi::PluginDelegate* plugin_delegate_; // Not owned.
122
123 base::PlatformFile file_;
124
125 // The file system type specified in the Open() call. This will be
126 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
127 // indicate that the open command actually succeeded.
128 PP_FileSystemType file_system_type_;
129
130 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
131 GURL file_system_url_;
132
133 // Callback function for notifying when the file handle is closed.
134 PluginDelegate::NotifyCloseFileCallback notify_close_file_callback_;
135
136 // Pointer to a QuotaFileIO instance, which is valid only while a file
137 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened.
138 scoped_ptr<webkit::ppapi::QuotaFileIO> quota_file_io_;
139
140 // A temporary storage just to pass a ReplyMessageContext from
141 // OnHostMsg{OP} to {OP}Validated. It is a short-living data and must be
142 // copied in {OP}Validated immediately. In fact, it is copied to the
143 // closure of platform operation callback via Bind.
144 ppapi::host::ReplyMessageContext temp_reply_context_;
145
146 base::WeakPtrFactory<PepperFileIOHost> weak_factory_;
147
148 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost);
149 };
150
151 } // namespace content
152
153 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698