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 PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 virtual int64_t GetAppendModeWriteAmount() const OVERRIDE; | 61 virtual int64_t GetAppendModeWriteAmount() const OVERRIDE; |
62 virtual void SetMaxWrittenOffset(int64_t max_written_offset) OVERRIDE; | 62 virtual void SetMaxWrittenOffset(int64_t max_written_offset) OVERRIDE; |
63 virtual void SetAppendModeWriteAmount( | 63 virtual void SetAppendModeWriteAmount( |
64 int64_t append_mode_write_amount) OVERRIDE; | 64 int64_t append_mode_write_amount) OVERRIDE; |
65 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; | 65 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
66 virtual void Close() OVERRIDE; | 66 virtual void Close() OVERRIDE; |
67 virtual int32_t RequestOSFileHandle( | 67 virtual int32_t RequestOSFileHandle( |
68 PP_FileHandle* handle, | 68 PP_FileHandle* handle, |
69 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 69 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
70 | 70 |
71 private: | |
72 // FileHandleHolder is used to guarantee that file operations will have a | 71 // FileHandleHolder is used to guarantee that file operations will have a |
73 // valid FD to operate on, even if they're in a different thread. | 72 // valid FD to operate on, even if they're in a different thread. |
74 // If instead we just passed the raw FD, the FD could be closed before the | 73 // If instead we just passed the raw FD, the FD could be closed before the |
75 // file operation has a chance to run. It could interact with an invalid FD, | 74 // file operation has a chance to run. It could interact with an invalid FD, |
76 // or worse, the FD value could be reused if another file is opened quickly | 75 // or worse, the FD value could be reused if another file is opened quickly |
77 // (POSIX is required to provide the lowest available value when opening a | 76 // (POSIX is required to provide the lowest available value when opening a |
78 // file). This could result in strange problems such as writing data to the | 77 // file). This could result in strange problems such as writing data to the |
79 // wrong file. | 78 // wrong file. |
80 // | 79 // |
81 // Operations that run on a background thread should hold one of these to | 80 // Operations that run on a background thread should hold one of these to |
(...skipping 12 matching lines...) Expand all Loading... |
94 PP_FileHandle raw_handle() { | 93 PP_FileHandle raw_handle() { |
95 return raw_handle_; | 94 return raw_handle_; |
96 } | 95 } |
97 static bool IsValid( | 96 static bool IsValid( |
98 const scoped_refptr<FileIOResource::FileHandleHolder>& handle); | 97 const scoped_refptr<FileIOResource::FileHandleHolder>& handle); |
99 private: | 98 private: |
100 friend class base::RefCountedThreadSafe<FileHandleHolder>; | 99 friend class base::RefCountedThreadSafe<FileHandleHolder>; |
101 ~FileHandleHolder(); | 100 ~FileHandleHolder(); |
102 PP_FileHandle raw_handle_; | 101 PP_FileHandle raw_handle_; |
103 }; | 102 }; |
| 103 scoped_refptr<FileHandleHolder> file_handle() { |
| 104 return file_handle_; |
| 105 } |
104 | 106 |
| 107 private: |
105 // Class to perform file query operations across multiple threads. | 108 // Class to perform file query operations across multiple threads. |
106 class QueryOp : public base::RefCountedThreadSafe<QueryOp> { | 109 class QueryOp : public base::RefCountedThreadSafe<QueryOp> { |
107 public: | 110 public: |
108 explicit QueryOp(scoped_refptr<FileHandleHolder> file_handle); | 111 explicit QueryOp(scoped_refptr<FileHandleHolder> file_handle); |
109 | 112 |
110 // Queries the file. Called on the file thread (non-blocking) or the plugin | 113 // Queries the file. Called on the file thread (non-blocking) or the plugin |
111 // thread (blocking). This should not be called when we hold the proxy lock. | 114 // thread (blocking). This should not be called when we hold the proxy lock. |
112 int32_t DoWork(); | 115 int32_t DoWork(); |
113 | 116 |
114 const base::PlatformFileInfo& file_info() const { return file_info_; } | 117 const base::PlatformFileInfo& file_info() const { return file_info_; } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 bool check_quota_; | 226 bool check_quota_; |
224 bool called_close_; | 227 bool called_close_; |
225 | 228 |
226 DISALLOW_COPY_AND_ASSIGN(FileIOResource); | 229 DISALLOW_COPY_AND_ASSIGN(FileIOResource); |
227 }; | 230 }; |
228 | 231 |
229 } // namespace proxy | 232 } // namespace proxy |
230 } // namespace ppapi | 233 } // namespace ppapi |
231 | 234 |
232 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 235 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
OLD | NEW |