| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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" | |
| 22 #include "url/gurl.h" | |
| 23 #include "webkit/browser/fileapi/file_system_context.h" | |
| 24 #include "webkit/browser/fileapi/file_system_operation_runner.h" | |
| 25 #include "webkit/common/quota/quota_types.h" | |
| 26 | |
| 27 using ppapi::host::ReplyMessageContext; | |
| 28 | |
| 29 namespace content { | |
| 30 class QuotaFileIO; | |
| 31 | |
| 32 class PepperFileIOHost : public ppapi::host::ResourceHost, | |
| 33 public base::SupportsWeakPtr<PepperFileIOHost> { | |
| 34 public: | |
| 35 typedef base::Callback<void (base::PlatformFileError)> | |
| 36 NotifyCloseFileCallback; | |
| 37 | |
| 38 PepperFileIOHost(BrowserPpapiHostImpl* host, | |
| 39 PP_Instance instance, | |
| 40 PP_Resource resource); | |
| 41 virtual ~PepperFileIOHost(); | |
| 42 | |
| 43 // ppapi::host::ResourceHost override. | |
| 44 virtual int32_t OnResourceMessageReceived( | |
| 45 const IPC::Message& msg, | |
| 46 ppapi::host::HostMessageContext* context) OVERRIDE; | |
| 47 | |
| 48 struct UIThreadStuff { | |
| 49 UIThreadStuff(); | |
| 50 ~UIThreadStuff(); | |
| 51 base::ProcessId resolved_render_process_id; | |
| 52 scoped_refptr<fileapi::FileSystemContext> file_system_context; | |
| 53 }; | |
| 54 private: | |
| 55 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, | |
| 56 PP_Resource file_ref_resource, | |
| 57 int32_t open_flags); | |
| 58 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext* context, | |
| 59 PP_Time last_access_time, | |
| 60 PP_Time last_modified_time); | |
| 61 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext* context, | |
| 62 int64_t offset, | |
| 63 const std::string& buffer); | |
| 64 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext* context, | |
| 65 int64_t length); | |
| 66 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); | |
| 67 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context); | |
| 68 int32_t OnHostMsgRequestOSFileHandle( | |
| 69 ppapi::host::HostMessageContext* context); | |
| 70 | |
| 71 void GotPluginAllowedToCallRequestOSFileHandle( | |
| 72 ppapi::host::ReplyMessageContext reply_context, | |
| 73 bool plugin_allowed); | |
| 74 | |
| 75 // Callback handlers. These mostly convert the PlatformFileError to the | |
| 76 // PP_Error code and send back the reply. Note that the argument | |
| 77 // ReplyMessageContext is copied so that we have a closure containing all | |
| 78 // necessary information to reply. | |
| 79 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context, | |
| 80 base::PlatformFileError error_code); | |
| 81 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context, | |
| 82 base::PlatformFileError error_code, | |
| 83 base::PassPlatformFile file, | |
| 84 bool unused_created); | |
| 85 void ExecutePlatformWriteCallback(ReplyMessageContext reply_context, | |
| 86 base::PlatformFileError error_code, | |
| 87 int bytes_written); | |
| 88 | |
| 89 void GotUIThreadStuffForInternalFileSystems( | |
| 90 ReplyMessageContext reply_context, | |
| 91 int platform_file_flags, | |
| 92 UIThreadStuff ui_thread_stuff); | |
| 93 void DidOpenInternalFile( | |
| 94 ReplyMessageContext reply_context, | |
| 95 base::PlatformFileError result, | |
| 96 base::PlatformFile file, | |
| 97 const base::Closure& on_close_callback); | |
| 98 void GotResolvedRenderProcessId( | |
| 99 ReplyMessageContext reply_context, | |
| 100 base::FilePath path, | |
| 101 int platform_file_flags, | |
| 102 base::ProcessId resolved_render_process_id); | |
| 103 | |
| 104 void DidCloseFile(base::PlatformFileError error); | |
| 105 | |
| 106 // Adds file_ to |reply_context| with the specified |open_flags|. | |
| 107 bool AddFileToReplyContext( | |
| 108 int32_t open_flags, | |
| 109 ppapi::host::ReplyMessageContext* reply_context) const; | |
| 110 | |
| 111 BrowserPpapiHostImpl* browser_ppapi_host_; | |
| 112 | |
| 113 RenderProcessHost* render_process_host_; | |
| 114 int render_process_id_; | |
| 115 base::ProcessId resolved_render_process_id_; | |
| 116 | |
| 117 base::PlatformFile file_; | |
| 118 | |
| 119 // The file system type specified in the Open() call. This will be | |
| 120 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not | |
| 121 // indicate that the open command actually succeeded. | |
| 122 PP_FileSystemType file_system_type_; | |
| 123 | |
| 124 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | |
| 125 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | |
| 126 scoped_ptr<fileapi::FileSystemOperationRunner> file_system_operation_runner_; | |
| 127 fileapi::FileSystemURL file_system_url_; | |
| 128 base::Closure on_close_callback_; | |
| 129 | |
| 130 // Used to check if we can pass file handle to plugins. | |
| 131 quota::QuotaLimitType quota_policy_; | |
| 132 | |
| 133 // Pointer to a QuotaFileIO instance, which is valid only while a file | |
| 134 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. | |
| 135 scoped_ptr<QuotaFileIO> quota_file_io_; | |
| 136 | |
| 137 int32_t open_flags_; | |
| 138 | |
| 139 ppapi::FileIOStateManager state_manager_; | |
| 140 | |
| 141 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | |
| 142 | |
| 143 base::WeakPtrFactory<PepperFileIOHost> weak_factory_; | |
| 144 | |
| 145 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost); | |
| 146 }; | |
| 147 | |
| 148 } // namespace content | |
| 149 | |
| 150 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_ | |
| OLD | NEW |