1 // Copyright 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h"
14 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "ppapi/c/pp_file_info.h"
18 #include "ppapi/c/pp_time.h"
19 #include "ppapi/host/host_message_context.h"
20 #include "ppapi/host/resource_host.h"
21 #include "ppapi/shared_impl/file_io_state_manager.h"
23 #include "webkit/browser/fileapi/file_system_context.h"
26 class PepperFileSystemBrowserHost
;
28 class PepperFileIOHost
: public ppapi::host::ResourceHost
,
29 public base::SupportsWeakPtr
<PepperFileIOHost
> {
31 typedef base::Callback
<void (base::PlatformFileError
)>
32 NotifyCloseFileCallback
;
34 PepperFileIOHost(BrowserPpapiHostImpl
* host
,
36 PP_Resource resource
);
37 virtual ~PepperFileIOHost();
39 // ppapi::host::ResourceHost override.
40 virtual int32_t OnResourceMessageReceived(
41 const IPC::Message
& msg
,
42 ppapi::host::HostMessageContext
* context
) OVERRIDE
;
44 struct UIThreadStuff
{
47 base::ProcessId resolved_render_process_id
;
48 scoped_refptr
<fileapi::FileSystemContext
> file_system_context
;
51 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext
* context
,
52 PP_Resource file_ref_resource
,
54 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext
* context
,
55 PP_Time last_access_time
,
56 PP_Time last_modified_time
);
57 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext
* context
,
59 int32_t OnHostMsgClose(ppapi::host::HostMessageContext
* context
,
60 int64_t max_written_offset
);
61 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext
* context
);
62 int32_t OnHostMsgRequestOSFileHandle(
63 ppapi::host::HostMessageContext
* context
);
65 void GotPluginAllowedToCallRequestOSFileHandle(
66 ppapi::host::ReplyMessageContext reply_context
,
69 // Callback handlers. These mostly convert the PlatformFileError to the
70 // PP_Error code and send back the reply. Note that the argument
71 // ReplyMessageContext is copied so that we have a closure containing all
72 // necessary information to reply.
73 void ExecutePlatformGeneralCallback(
74 ppapi::host::ReplyMessageContext reply_context
,
75 base::PlatformFileError error_code
);
76 void ExecutePlatformOpenFileCallback(
77 ppapi::host::ReplyMessageContext reply_context
,
78 base::PlatformFileError error_code
,
79 base::PassPlatformFile file
,
82 void GotUIThreadStuffForInternalFileSystems(
83 ppapi::host::ReplyMessageContext reply_context
,
84 int platform_file_flags
,
85 UIThreadStuff ui_thread_stuff
);
86 void DidOpenInternalFile(
87 ppapi::host::ReplyMessageContext reply_context
,
88 base::PlatformFileError result
,
89 base::PlatformFile file
,
90 const base::Closure
& on_close_callback
);
91 void GotResolvedRenderProcessId(
92 ppapi::host::ReplyMessageContext reply_context
,
94 int platform_file_flags
,
95 base::ProcessId resolved_render_process_id
);
97 void DidOpenQuotaFile(ppapi::host::ReplyMessageContext reply_context
,
98 base::PlatformFile file
,
99 int64_t max_written_offset
);
100 bool CallSetLength(ppapi::host::ReplyMessageContext reply_context
,
103 void DidCloseFile(base::PlatformFileError error
);
105 void SendOpenErrorReply(ppapi::host::ReplyMessageContext reply_context
);
107 // Adds file_ to |reply_context| with the specified |open_flags|.
108 bool AddFileToReplyContext(
110 ppapi::host::ReplyMessageContext
* reply_context
) const;
112 BrowserPpapiHostImpl
* browser_ppapi_host_
;
114 RenderProcessHost
* render_process_host_
;
115 int render_process_id_
;
116 base::ProcessId resolved_render_process_id_
;
118 base::PlatformFile file_
;
121 // The file system type specified in the Open() call. This will be
122 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
123 // indicate that the open command actually succeeded.
124 PP_FileSystemType file_system_type_
;
125 base::WeakPtr
<PepperFileSystemBrowserHost
> file_system_host_
;
127 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
128 scoped_refptr
<fileapi::FileSystemContext
> file_system_context_
;
129 fileapi::FileSystemURL file_system_url_
;
130 base::Closure on_close_callback_
;
131 int64_t max_written_offset_
;
134 ppapi::FileIOStateManager state_manager_
;
136 scoped_refptr
<base::MessageLoopProxy
> file_message_loop_
;
138 base::WeakPtrFactory
<PepperFileIOHost
> weak_factory_
;
140 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost
);
143 } // namespace content
145 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_