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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/renderer/renderer_ppapi_host.h"
14 #include "ppapi/host/host_message_context.h"
15 #include "ppapi/host/resource_host.h"
16 #include "ppapi/shared_impl/file_io_state_manager.h"
17 #include "ppapi/thunk/ppb_file_ref_api.h"
18 #include "webkit/plugins/ppapi/plugin_delegate.h"
20 using ppapi::host::ReplyMessageContext
;
21 using webkit::ppapi::PluginDelegate
;
31 class PepperFileIOHost
: public ppapi::host::ResourceHost
,
32 public base::SupportsWeakPtr
<PepperFileIOHost
> {
34 PepperFileIOHost(RendererPpapiHost
* 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
;
45 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext
* context
,
46 PP_Resource file_ref_resource
,
48 int32_t OnHostMsgQuery(ppapi::host::HostMessageContext
* context
);
49 int32_t OnHostMsgTouch(ppapi::host::HostMessageContext
* context
,
50 PP_Time last_access_time
,
51 PP_Time last_modified_time
);
52 int32_t OnHostMsgRead(ppapi::host::HostMessageContext
* context
,
54 int32_t bytes_to_read
);
55 int32_t OnHostMsgWrite(ppapi::host::HostMessageContext
* context
,
57 const std::string
& buffer
);
58 int32_t OnHostMsgSetLength(ppapi::host::HostMessageContext
* context
,
60 int32_t OnHostMsgClose(ppapi::host::HostMessageContext
* context
);
61 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext
* context
);
63 int32_t OnHostMsgRequestOSFileHandle(
64 ppapi::host::HostMessageContext
* context
);
66 int32_t OnHostMsgGetOSFileDescriptor(
67 ppapi::host::HostMessageContext
* context
);
68 int32_t OnHostMsgWillWrite(ppapi::host::HostMessageContext
* context
,
70 int32_t bytes_to_write
);
71 int32_t OnHostMsgWillSetLength(ppapi::host::HostMessageContext
* context
,
74 // Callback handlers. These mostly convert the PlatformFileError to the
75 // PP_Error code and send back the reply. Note that the argument
76 // ReplyMessageContext is copied so that we have a closure containing all
77 // necessary information to reply.
78 void ExecutePlatformGeneralCallback(ReplyMessageContext reply_context
,
79 base::PlatformFileError error_code
);
80 void ExecutePlatformOpenFileCallback(ReplyMessageContext reply_context
,
81 base::PlatformFileError error_code
,
82 base::PassPlatformFile file
);
83 void ExecutePlatformOpenFileSystemURLCallback(
84 ReplyMessageContext reply_context
,
85 base::PlatformFileError error_code
,
86 base::PassPlatformFile file
,
87 quota::QuotaLimitType quota_policy
,
88 const PluginDelegate::NotifyCloseFileCallback
& callback
);
89 void ExecutePlatformQueryCallback(ReplyMessageContext reply_context
,
90 base::PlatformFileError error_code
,
91 const base::PlatformFileInfo
& file_info
);
92 void ExecutePlatformReadCallback(ReplyMessageContext reply_context
,
93 base::PlatformFileError error_code
,
94 const char* data
, int bytes_read
);
95 void ExecutePlatformWriteCallback(ReplyMessageContext reply_context
,
96 base::PlatformFileError error_code
,
99 // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed.
100 webkit::ppapi::PluginDelegate
* plugin_delegate_
; // Not owned.
102 base::PlatformFile file_
;
104 // The file system type specified in the Open() call. This will be
105 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
106 // indicate that the open command actually succeeded.
107 PP_FileSystemType file_system_type_
;
109 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
110 GURL file_system_url_
;
112 // Used to check if we can pass file handle to plugins.
113 quota::QuotaLimitType quota_policy_
;
115 // Callback function for notifying when the file handle is closed.
116 PluginDelegate::NotifyCloseFileCallback notify_close_file_callback_
;
118 // Pointer to a QuotaFileIO instance, which is valid only while a file
119 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened.
120 scoped_ptr
<webkit::ppapi::QuotaFileIO
> quota_file_io_
;
122 bool is_running_in_process_
;
124 base::WeakPtrFactory
<PepperFileIOHost
> weak_factory_
;
126 ppapi::FileIOStateManager state_manager_
;
128 DISALLOW_COPY_AND_ASSIGN(PepperFileIOHost
);
131 } // namespace content
133 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_IO_HOST_H_