OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "content/public/renderer/renderer_ppapi_host.h" | 14 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
15 #include "ipc/ipc_listener.h" | 15 #include "ipc/ipc_listener.h" |
16 #include "ipc/ipc_platform_file.h" | 16 #include "ipc/ipc_platform_file.h" |
17 #include "ppapi/c/pp_file_info.h" | 17 #include "ppapi/c/pp_file_info.h" |
18 #include "ppapi/c/pp_time.h" | 18 #include "ppapi/c/pp_time.h" |
19 #include "ppapi/host/host_message_context.h" | 19 #include "ppapi/host/host_message_context.h" |
20 #include "ppapi/host/resource_host.h" | 20 #include "ppapi/host/resource_host.h" |
21 #include "ppapi/shared_impl/file_io_state_manager.h" | 21 #include "ppapi/shared_impl/file_io_state_manager.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 #include "webkit/browser/fileapi/file_system_context.h" | |
24 #include "webkit/browser/fileapi/file_system_operation_runner.h" | |
23 #include "webkit/common/quota/quota_types.h" | 25 #include "webkit/common/quota/quota_types.h" |
24 | 26 |
25 using ppapi::host::ReplyMessageContext; | 27 using ppapi::host::ReplyMessageContext; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 class QuotaFileIO; | 30 class QuotaFileIO; |
29 | 31 |
30 class PepperFileIOHost : public ppapi::host::ResourceHost, | 32 class PepperFileIOHost : public ppapi::host::ResourceHost, |
31 public base::SupportsWeakPtr<PepperFileIOHost>, | 33 public base::SupportsWeakPtr<PepperFileIOHost> { |
32 public IPC::Listener { | |
33 public: | 34 public: |
34 typedef base::Callback<void (base::PlatformFileError)> | 35 typedef base::Callback<void (base::PlatformFileError)> |
35 NotifyCloseFileCallback; | 36 NotifyCloseFileCallback; |
36 | 37 |
37 PepperFileIOHost(RendererPpapiHost* host, | 38 PepperFileIOHost(BrowserPpapiHostImpl* host, |
38 PP_Instance instance, | 39 PP_Instance instance, |
39 PP_Resource resource); | 40 PP_Resource resource); |
40 virtual ~PepperFileIOHost(); | 41 virtual ~PepperFileIOHost(); |
41 | 42 |
42 // ppapi::host::ResourceHost override. | 43 // ppapi::host::ResourceHost override. |
43 virtual int32_t OnResourceMessageReceived( | 44 virtual int32_t OnResourceMessageReceived( |
44 const IPC::Message& msg, | 45 const IPC::Message& msg, |
45 ppapi::host::HostMessageContext* context) OVERRIDE; | 46 ppapi::host::HostMessageContext* context) OVERRIDE; |
46 | 47 |
47 private: | 48 private: |
48 // IPC::Listener implementation. | |
49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
50 | |
51 void OnAsyncFileOpened( | |
52 base::PlatformFileError error_code, | |
53 IPC::PlatformFileForTransit file_for_transit); | |
54 | |
55 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, | 49 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, |
56 PP_Resource file_ref_resource, | 50 PP_Resource file_ref_resource, |
57 int32_t open_flags); | 51 int32_t open_flags); |
58 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context, | 52 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context, |
59 PP_Time last_access_time, | 53 PP_Time last_access_time, |
60 PP_Time last_modified_time); | 54 PP_Time last_modified_time); |
61 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context, | 55 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context, |
62 int64_t offset, | 56 int64_t offset, |
63 const std::string& buffer); | 57 const std::string& buffer); |
64 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context, | 58 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context, |
65 int64_t length); | 59 int64_t length); |
66 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); | 60 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); |
67 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); | 61 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); |
68 // Private API. | |
69 int32_t OnHostMsgRequestOSFileHandle( | 62 int32_t OnHostMsgRequestOSFileHandle( |
70 ppapi::host::HostMessageContext* context); | 63 ppapi::host::HostMessageContext* context); |
71 | 64 |
65 void FinishRequestOSFileHandle(ppapi::host::ReplyMessageContext reply_context, | |
66 RenderProcessHost* render_process_host); | |
67 | |
72 // Callback handlers. These mostly convert the PlatformFileError to the | 68 // Callback handlers. These mostly convert the PlatformFileError to the |
73 // PP_Error code and send back the reply. Note that the argument | 69 // PP_Error code and send back the reply. Note that the argument |
74 // ReplyMessageContext is copied so that we have a closure containing all | 70 // ReplyMessageContext is copied so that we have a closure containing all |
75 // necessary information to reply. | 71 // necessary information to reply. |
76 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context, | 72 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context, |
77 base::PlatformFileError error_code); | 73 base::PlatformFileError error_code); |
78 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context, | 74 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context, |
79 base::PlatformFileError error_code, | 75 base::PlatformFileError error_code, |
80 base::PassPlatformFile file); | 76 base::PassPlatformFile file, |
81 void ExecutePlatformOpenFileSystemURLCallback( | 77 bool unused_created); |
82 ReplyMessageContext reply_context, | |
83 base::PlatformFileError error_code, | |
84 base::PassPlatformFile file, | |
85 quota::QuotaLimitType quota_policy, | |
86 const NotifyCloseFileCallback& callback); | |
87 void ExecutePlatformQueryCallback(ReplyMessageContext reply_context, | |
88 base::PlatformFileError error_code, | |
89 const base::PlatformFileInfo& file_info); | |
90 void ExecutePlatformReadCallback(ReplyMessageContext reply_context, | |
91 base::PlatformFileError error_code, | |
92 const char* data, int bytes_read); | |
93 void ExecutePlatformWriteCallback(ReplyMessageContext reply_context, | 78 void ExecutePlatformWriteCallback(ReplyMessageContext reply_context, |
94 base::PlatformFileError error_code, | 79 base::PlatformFileError error_code, |
95 int bytes_written); | 80 int bytes_written); |
96 | 81 |
97 RendererPpapiHost* renderer_ppapi_host_; | 82 // Callback handler for GetFileSystemContext. |
83 void GotFileSystemContext( | |
84 ReplyMessageContext reply_context, | |
85 int platform_file_flags, | |
86 scoped_refptr<fileapi::FileSystemContext> fs_context); | |
kinuko
2013/10/23 07:16:04
nit: indent
teravest
2013/10/23 16:54:27
Done.
| |
87 void DidOpenFile( | |
88 ReplyMessageContext reply_context, | |
89 base::PlatformFileError result, | |
90 base::PlatformFile file, | |
91 const base::Closure& on_close_callback); | |
92 | |
93 // Retrieves the RenderProcessHost (from the UI thread, if necessary) and | |
94 // invokes the specified callback. | |
95 void GetRenderProcessHost(base::Callback<void(RenderProcessHost*)> callback); | |
96 // Stores the RenderProcessHost and invokes the callback passed to | |
97 // GetRenderProcessHost(). | |
98 void GotRenderProcessHost(base::Callback<void(RenderProcessHost*)> callback, | |
99 RenderProcessHost* host); | |
100 | |
101 // Adds file_ to |reply_context| with the specified |open_flags|. | |
102 bool AddFileToReplyContext( | |
103 int32_t open_flags, | |
104 ppapi::host::ReplyMessageContext* reply_context) const; | |
105 | |
106 BrowserPpapiHostImpl* browser_ppapi_host_; | |
107 | |
108 RenderProcessHost* render_process_host_; | |
109 int render_process_id_; | |
110 | |
98 base::PlatformFile file_; | 111 base::PlatformFile file_; |
99 | 112 |
100 // The file system type specified in the Open() call. This will be | 113 // The file system type specified in the Open() call. This will be |
101 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not | 114 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not |
102 // indicate that the open command actually succeeded. | 115 // indicate that the open command actually succeeded. |
103 PP_FileSystemType file_system_type_; | 116 PP_FileSystemType file_system_type_; |
104 | 117 |
105 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | 118 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. |
106 GURL file_system_url_; | 119 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
120 scoped_ptr<fileapi::FileSystemOperationRunner> file_system_operation_runner_; | |
121 fileapi::FileSystemURL file_system_url_; | |
122 base::Closure on_close_callback_; | |
107 | 123 |
108 // Used to check if we can pass file handle to plugins. | 124 // Used to check if we can pass file handle to plugins. |
109 quota::QuotaLimitType quota_policy_; | 125 quota::QuotaLimitType quota_policy_; |
110 | 126 |
111 // Callback function for notifying when the file handle is closed. | 127 // Callback function for notifying when the file handle is closed. |
112 NotifyCloseFileCallback notify_close_file_callback_; | 128 NotifyCloseFileCallback notify_close_file_callback_; |
113 | 129 |
114 // Pointer to a QuotaFileIO instance, which is valid only while a file | 130 // Pointer to a QuotaFileIO instance, which is valid only while a file |
115 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. | 131 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. |
116 scoped_ptr<QuotaFileIO> quota_file_io_; | 132 scoped_ptr<QuotaFileIO> quota_file_io_; |
117 | 133 |
118 int32_t open_flags_; | 134 int32_t open_flags_; |
119 | 135 |
120 ppapi::FileIOStateManager state_manager_; | 136 ppapi::FileIOStateManager state_manager_; |
121 | 137 |
122 int routing_id_; | 138 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
123 | |
124 base::Callback<void(base::PlatformFileError, base::PassPlatformFile)> | |
125 pending_open_callback_; | |
126 | 139 |
127 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; | 140 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; |
128 | 141 |
129 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); | 142 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); |
130 }; | 143 }; |
131 | 144 |
132 } // namespace content | 145 } // namespace content |
133 | 146 |
134 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | 147 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ |
OLD | NEW |