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