OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_callback_factory.h" | 11 #include "base/memory/scoped_callback_factory.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "ppapi/c/dev/pp_file_info_dev.h" | 14 #include "ppapi/c/dev/pp_file_info_dev.h" |
15 #include "ppapi/c/pp_time.h" | 15 #include "ppapi/c/pp_time.h" |
| 16 #include "ppapi/thunk/ppb_file_io_api.h" |
16 #include "webkit/plugins/ppapi/callbacks.h" | 17 #include "webkit/plugins/ppapi/callbacks.h" |
17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 18 #include "webkit/plugins/ppapi/plugin_delegate.h" |
18 #include "webkit/plugins/ppapi/resource.h" | 19 #include "webkit/plugins/ppapi/resource.h" |
19 | 20 |
20 struct PP_CompletionCallback; | 21 struct PP_CompletionCallback; |
21 struct PPB_FileIO_Dev; | 22 struct PPB_FileIO_Dev; |
22 struct PPB_FileIOTrusted_Dev; | 23 struct PPB_FileIOTrusted_Dev; |
23 | 24 |
24 namespace webkit { | 25 namespace webkit { |
25 namespace ppapi { | 26 namespace ppapi { |
26 | 27 |
27 class PluginModule; | 28 class PluginModule; |
28 class PPB_FileRef_Impl; | 29 class PPB_FileRef_Impl; |
29 | 30 |
30 class PPB_FileIO_Impl : public Resource { | 31 class PPB_FileIO_Impl : public Resource, |
| 32 public ::ppapi::thunk::PPB_FileIO_API { |
31 public: | 33 public: |
32 explicit PPB_FileIO_Impl(PluginInstance* instance); | 34 explicit PPB_FileIO_Impl(PluginInstance* instance); |
33 virtual ~PPB_FileIO_Impl(); | 35 virtual ~PPB_FileIO_Impl(); |
34 | 36 |
35 // Returns a pointer to the interface implementing PPB_FileIO that is exposed | 37 static PP_Resource Create(PP_Instance instance); |
36 // to the plugin. | |
37 static const PPB_FileIO_Dev* GetInterface(); | |
38 | 38 |
39 // Returns a pointer to the interface implementing PPB_FileIOTrusted that is | 39 // ResourceObjectBase overrides. |
40 // exposed to the plugin. | 40 ::ppapi::thunk::PPB_FileIO_API* AsPPB_FileIO_API(); |
41 static const PPB_FileIOTrusted_Dev* GetTrustedInterface(); | |
42 | 41 |
43 // Resource overrides. | 42 // PPB_FileIO_API implementation. |
44 virtual PPB_FileIO_Impl* AsPPB_FileIO_Impl(); | 43 virtual int32_t Open(PP_Resource file_ref, |
45 | 44 int32_t open_flags, |
46 // PPB_FileIO implementation. | 45 PP_CompletionCallback callback) OVERRIDE; |
47 int32_t Open(PPB_FileRef_Impl* file_ref, | 46 virtual int32_t Query(PP_FileInfo_Dev* info, |
48 int32_t open_flags, | 47 PP_CompletionCallback callback) OVERRIDE; |
49 PP_CompletionCallback callback); | 48 virtual int32_t Touch(PP_Time last_access_time, |
50 int32_t Query(PP_FileInfo_Dev* info, | 49 PP_Time last_modified_time, |
51 PP_CompletionCallback callback); | 50 PP_CompletionCallback callback) OVERRIDE; |
52 int32_t Touch(PP_Time last_access_time, | 51 virtual int32_t Read(int64_t offset, |
53 PP_Time last_modified_time, | 52 char* buffer, |
54 PP_CompletionCallback callback); | 53 int32_t bytes_to_read, |
55 int32_t Read(int64_t offset, | 54 PP_CompletionCallback callback) OVERRIDE; |
56 char* buffer, | 55 virtual int32_t Write(int64_t offset, |
57 int32_t bytes_to_read, | 56 const char* buffer, |
58 PP_CompletionCallback callback); | 57 int32_t bytes_to_write, |
59 int32_t Write(int64_t offset, | 58 PP_CompletionCallback callback) OVERRIDE; |
60 const char* buffer, | 59 virtual int32_t SetLength(int64_t length, |
61 int32_t bytes_to_write, | 60 PP_CompletionCallback callback) OVERRIDE; |
62 PP_CompletionCallback callback); | 61 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; |
63 int32_t SetLength(int64_t length, | 62 virtual void Close() OVERRIDE; |
64 PP_CompletionCallback callback); | 63 virtual int32_t GetOSFileDescriptor() OVERRIDE; |
65 int32_t Flush(PP_CompletionCallback callback); | 64 virtual int32_t WillWrite(int64_t offset, |
66 void Close(); | 65 int32_t bytes_to_write, |
67 | 66 PP_CompletionCallback callback) OVERRIDE; |
68 // PPB_FileIOTrusted implementation. | 67 virtual int32_t WillSetLength(int64_t length, |
69 int32_t GetOSFileDescriptor(); | 68 PP_CompletionCallback callback) OVERRIDE; |
70 int32_t WillWrite(int64_t offset, | |
71 int32_t bytes_to_write, | |
72 PP_CompletionCallback callback); | |
73 int32_t WillSetLength(int64_t length, | |
74 PP_CompletionCallback callback); | |
75 | 69 |
76 private: | 70 private: |
77 // Verifies: | 71 // Verifies: |
78 // - that |callback| is valid (only nonblocking operation supported); | 72 // - that |callback| is valid (only nonblocking operation supported); |
79 // - that the file is already open or not, depending on |should_be_open|; and | 73 // - that the file is already open or not, depending on |should_be_open|; and |
80 // - that no callback is already pending. | 74 // - that no callback is already pending. |
81 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if | 75 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if |
82 // the call should be aborted and that code returned to the plugin. | 76 // the call should be aborted and that code returned to the plugin. |
83 int32_t CommonCallValidation(bool should_be_open, | 77 int32_t CommonCallValidation(bool should_be_open, |
84 PP_CompletionCallback callback); | 78 PP_CompletionCallback callback); |
(...skipping 28 matching lines...) Expand all Loading... |
113 // Pointer back to the caller's read buffer; used by |Read()|. Not owned. | 107 // Pointer back to the caller's read buffer; used by |Read()|. Not owned. |
114 char* read_buffer_; | 108 char* read_buffer_; |
115 | 109 |
116 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); | 110 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); |
117 }; | 111 }; |
118 | 112 |
119 } // namespace ppapi | 113 } // namespace ppapi |
120 } // namespace webkit | 114 } // namespace webkit |
121 | 115 |
122 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | 116 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ |
OLD | NEW |