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 // Stable API Message Handlers. |
bbudge
2013/10/22 01:59:39
I don't understand the comment.
teravest
2013/10/22 15:45:05
OK, Removed (and removed an undefined method).
| |
49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
50 | |
51 void OnAsyncFileOpened( | 50 void OnAsyncFileOpened( |
52 base::PlatformFileError error_code, | 51 base::PlatformFileError error_code, |
53 IPC::PlatformFileForTransit file_for_transit); | 52 IPC::PlatformFileForTransit file_for_transit); |
54 | 53 |
55 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, | 54 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, |
56 PP_Resource file_ref_resource, | 55 PP_Resource file_ref_resource, |
57 int32_t open_flags); | 56 int32_t open_flags); |
58 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context, | 57 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context, |
59 PP_Time last_access_time, | 58 PP_Time last_access_time, |
60 PP_Time last_modified_time); | 59 PP_Time last_modified_time); |
61 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context, | 60 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context, |
62 int64_t offset, | 61 int64_t offset, |
63 const std::string& buffer); | 62 const std::string& buffer); |
64 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context, | 63 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context, |
65 int64_t length); | 64 int64_t length); |
66 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); | 65 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); |
67 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); | 66 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); |
68 // Private API. | 67 // Private API. |
69 int32_t OnHostMsgRequestOSFileHandle( | 68 int32_t OnHostMsgRequestOSFileHandle( |
70 ppapi::host::HostMessageContext* context); | 69 ppapi::host::HostMessageContext* context); |
71 | 70 |
71 void FinishRequestOSFileHandle(ppapi::host::ReplyMessageContext reply_context, | |
72 RenderProcessHost* render_process_host); | |
73 | |
72 // Callback handlers. These mostly convert the PlatformFileError to the | 74 // Callback handlers. These mostly convert the PlatformFileError to the |
73 // PP_Error code and send back the reply. Note that the argument | 75 // PP_Error code and send back the reply. Note that the argument |
74 // ReplyMessageContext is copied so that we have a closure containing all | 76 // ReplyMessageContext is copied so that we have a closure containing all |
75 // necessary information to reply. | 77 // necessary information to reply. |
76 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context, | 78 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context, |
77 base::PlatformFileError error_code); | 79 base::PlatformFileError error_code); |
78 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context, | 80 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context, |
79 base::PlatformFileError error_code, | 81 base::PlatformFileError error_code, |
80 base::PassPlatformFile file); | 82 base::PassPlatformFile file, |
81 void ExecutePlatformOpenFileSystemURLCallback( | 83 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, | 84 void ExecutePlatformWriteCallback(ReplyMessageContext reply_context, |
94 base::PlatformFileError error_code, | 85 base::PlatformFileError error_code, |
95 int bytes_written); | 86 int bytes_written); |
96 | 87 |
97 RendererPpapiHost* renderer_ppapi_host_; | 88 // Callback handler for GetFileSystemContext. |
89 void GotFileSystemContext( | |
90 ReplyMessageContext reply_context, | |
91 int platform_file_flags, | |
92 scoped_refptr<fileapi::FileSystemContext> fs_context); | |
93 void DidOpenFile( | |
94 ReplyMessageContext reply_context, | |
95 base::PlatformFileError result, | |
96 base::PlatformFile file, | |
97 const base::Closure& on_close_callback, | |
98 base::ProcessHandle peer_handle); | |
99 | |
100 // Retrieves the RenderProcessHost (from the UI thread, if necessary) and | |
101 // invokes the specified callback. | |
102 void GetRenderProcessHost(base::Callback<void(RenderProcessHost*)> callback); | |
103 // Stores the RenderProcessHost and invokes the callback passed to | |
104 // GetRenderProcessHost(). | |
105 void GotRenderProcessHost(base::Callback<void(RenderProcessHost*)> callback, | |
106 RenderProcessHost* host); | |
107 | |
108 // Adds file_ to |reply_context| with the specified |open_flags|. | |
109 bool AddFileToReplyContext( | |
110 int32_t open_flags, | |
111 ppapi::host::ReplyMessageContext* reply_context) const; | |
112 | |
113 BrowserPpapiHostImpl* browser_ppapi_host_; | |
114 | |
115 RenderProcessHost* render_process_host_; | |
116 int render_process_id_; | |
117 | |
98 base::PlatformFile file_; | 118 base::PlatformFile file_; |
99 | 119 |
100 // The file system type specified in the Open() call. This will be | 120 // The file system type specified in the Open() call. This will be |
101 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not | 121 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not |
102 // indicate that the open command actually succeeded. | 122 // indicate that the open command actually succeeded. |
103 PP_FileSystemType file_system_type_; | 123 PP_FileSystemType file_system_type_; |
104 | 124 |
105 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | 125 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. |
106 GURL file_system_url_; | 126 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
127 scoped_ptr<fileapi::FileSystemOperationRunner> file_system_operation_runner_; | |
128 fileapi::FileSystemURL file_system_url_; | |
129 base::Closure on_close_callback_; | |
107 | 130 |
108 // Used to check if we can pass file handle to plugins. | 131 // Used to check if we can pass file handle to plugins. |
109 quota::QuotaLimitType quota_policy_; | 132 quota::QuotaLimitType quota_policy_; |
110 | 133 |
111 // Callback function for notifying when the file handle is closed. | 134 // Callback function for notifying when the file handle is closed. |
112 NotifyCloseFileCallback notify_close_file_callback_; | 135 NotifyCloseFileCallback notify_close_file_callback_; |
113 | 136 |
114 // Pointer to a QuotaFileIO instance, which is valid only while a file | 137 // Pointer to a QuotaFileIO instance, which is valid only while a file |
115 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. | 138 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. |
116 scoped_ptr<QuotaFileIO> quota_file_io_; | 139 scoped_ptr<QuotaFileIO> quota_file_io_; |
117 | 140 |
118 int32_t open_flags_; | 141 int32_t open_flags_; |
119 | 142 |
120 ppapi::FileIOStateManager state_manager_; | 143 ppapi::FileIOStateManager state_manager_; |
121 | 144 |
122 int routing_id_; | 145 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
123 | |
124 base::Callback<void(base::PlatformFileError, base::PassPlatformFile)> | |
125 pending_open_callback_; | |
126 | 146 |
127 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; | 147 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; |
128 | 148 |
129 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); | 149 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); |
130 }; | 150 }; |
131 | 151 |
132 } // namespace content | 152 } // namespace content |
133 | 153 |
134 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | 154 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ |
OLD | NEW |