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 #include "webkit/fileapi/file_system_file_util_proxy.h" | 5 #include "webkit/fileapi/file_system_file_util_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "webkit/fileapi/file_system_context.h" | 9 #include "webkit/fileapi/file_system_context.h" |
10 #include "webkit/fileapi/file_system_file_util.h" | 10 #include "webkit/fileapi/file_system_file_util.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 origin_message_loop_proxy_->PostTask( | 64 origin_message_loop_proxy_->PostTask( |
65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this)); | 65 FROM_HERE, base::Bind(&MessageLoopRelay::RunCallback, this)); |
66 } | 66 } |
67 | 67 |
68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 68 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
69 base::PlatformFileError error_code_; | 69 base::PlatformFileError error_code_; |
70 fileapi::FileSystemOperationContext context_; | 70 fileapi::FileSystemOperationContext context_; |
71 fileapi::FileSystemFileUtil* file_util_; | 71 fileapi::FileSystemFileUtil* file_util_; |
72 }; | 72 }; |
73 | 73 |
74 class RelayCreateOrOpen : public MessageLoopRelay { | |
75 public: | |
76 RelayCreateOrOpen( | |
77 const fileapi::FileSystemOperationContext& context, | |
78 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | |
79 const FilePath& file_path, | |
80 int file_flags, | |
81 const fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback& callback) | |
82 : MessageLoopRelay(context), | |
83 message_loop_proxy_(message_loop_proxy), | |
84 file_path_(file_path), | |
85 file_flags_(file_flags), | |
86 callback_(callback), | |
87 file_handle_(base::kInvalidPlatformFileValue), | |
88 created_(false) { | |
89 DCHECK_EQ(false, callback.is_null()); | |
90 } | |
91 | |
92 protected: | |
93 virtual ~RelayCreateOrOpen() { | |
94 if (file_handle_ != base::kInvalidPlatformFileValue) | |
95 fileapi::FileSystemFileUtilProxy::Close( | |
96 *context(), message_loop_proxy_, file_handle_, | |
97 fileapi::FileSystemFileUtilProxy::StatusCallback()); | |
98 } | |
99 | |
100 virtual void RunWork() { | |
101 set_error_code(file_util()->CreateOrOpen( | |
102 context(), file_path_, file_flags_, &file_handle_, &created_)); | |
103 } | |
104 | |
105 virtual void RunCallback() { | |
106 callback_.Run(error_code(), base::PassPlatformFile(&file_handle_), | |
107 created_); | |
108 } | |
109 | |
110 private: | |
111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
112 FilePath file_path_; | |
113 int file_flags_; | |
114 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback callback_; | |
115 base::PlatformFile file_handle_; | |
116 bool created_; | |
117 }; | |
118 | |
119 class RelayWithStatusCallback : public MessageLoopRelay { | 74 class RelayWithStatusCallback : public MessageLoopRelay { |
120 public: | 75 public: |
121 RelayWithStatusCallback( | 76 RelayWithStatusCallback( |
122 const fileapi::FileSystemOperationContext& context, | 77 const fileapi::FileSystemOperationContext& context, |
123 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | 78 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) |
124 : MessageLoopRelay(context), | 79 : MessageLoopRelay(context), |
125 callback_(callback) { | 80 callback_(callback) { |
126 // It is OK for callback to be NULL. | 81 // It is OK for callback to be NULL. |
127 } | 82 } |
128 | 83 |
129 protected: | 84 protected: |
130 virtual void RunCallback() { | 85 virtual void RunCallback() { |
131 // The caller may not have been interested in the result. | 86 // The caller may not have been interested in the result. |
132 if (!callback_.is_null()) | 87 if (!callback_.is_null()) |
133 callback_.Run(error_code()); | 88 callback_.Run(error_code()); |
134 } | 89 } |
135 | 90 |
136 private: | 91 private: |
137 fileapi::FileSystemFileUtilProxy::StatusCallback callback_; | 92 fileapi::FileSystemFileUtilProxy::StatusCallback callback_; |
138 }; | 93 }; |
139 | 94 |
140 class RelayClose : public RelayWithStatusCallback { | |
141 public: | |
142 RelayClose(const fileapi::FileSystemOperationContext& context, | |
143 base::PlatformFile file_handle, | |
144 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | |
145 : RelayWithStatusCallback(context, callback), | |
146 file_handle_(file_handle) { | |
147 } | |
148 | |
149 protected: | |
150 virtual void RunWork() { | |
151 set_error_code(file_util()->Close(context(), file_handle_)); | |
152 } | |
153 | |
154 private: | |
155 base::PlatformFile file_handle_; | |
156 }; | |
157 | |
158 class RelayEnsureFileExists : public MessageLoopRelay { | 95 class RelayEnsureFileExists : public MessageLoopRelay { |
159 public: | 96 public: |
160 RelayEnsureFileExists( | 97 RelayEnsureFileExists( |
161 const fileapi::FileSystemOperationContext& context, | 98 const fileapi::FileSystemOperationContext& context, |
162 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 99 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
163 const FilePath& file_path, | 100 const FilePath& file_path, |
164 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& | 101 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& |
165 callback) | 102 callback) |
166 : MessageLoopRelay(context), | 103 : MessageLoopRelay(context), |
167 message_loop_proxy_(message_loop_proxy), | 104 message_loop_proxy_(message_loop_proxy), |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 355 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
419 scoped_refptr<MessageLoopRelay> relay) { | 356 scoped_refptr<MessageLoopRelay> relay) { |
420 return relay->Start(message_loop_proxy, from_here); | 357 return relay->Start(message_loop_proxy, from_here); |
421 } | 358 } |
422 | 359 |
423 } // namespace | 360 } // namespace |
424 | 361 |
425 namespace fileapi { | 362 namespace fileapi { |
426 | 363 |
427 // static | 364 // static |
428 bool FileSystemFileUtilProxy::CreateOrOpen( | |
429 const FileSystemOperationContext& context, | |
430 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
431 const FilePath& file_path, int file_flags, | |
432 const CreateOrOpenCallback& callback) { | |
433 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context, | |
434 message_loop_proxy, file_path, file_flags, callback)); | |
435 } | |
436 | |
437 // static | |
438 bool FileSystemFileUtilProxy::Close( | |
439 const FileSystemOperationContext& context, | |
440 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
441 base::PlatformFile file_handle, | |
442 const StatusCallback& callback) { | |
443 return Start(FROM_HERE, message_loop_proxy, | |
444 new RelayClose(context, file_handle, callback)); | |
445 } | |
446 | |
447 // static | |
448 bool FileSystemFileUtilProxy::EnsureFileExists( | 365 bool FileSystemFileUtilProxy::EnsureFileExists( |
449 const FileSystemOperationContext& context, | 366 const FileSystemOperationContext& context, |
450 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 367 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
451 const FilePath& file_path, | 368 const FilePath& file_path, |
452 const EnsureFileExistsCallback& callback) { | 369 const EnsureFileExistsCallback& callback) { |
453 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( | 370 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( |
454 context, message_loop_proxy, file_path, callback)); | 371 context, message_loop_proxy, file_path, callback)); |
455 } | 372 } |
456 | 373 |
457 // static | 374 // static |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 const FileSystemOperationContext& context, | 466 const FileSystemOperationContext& context, |
550 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 467 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
551 const FilePath& path, | 468 const FilePath& path, |
552 int64 length, | 469 int64 length, |
553 const StatusCallback& callback) { | 470 const StatusCallback& callback) { |
554 return Start(FROM_HERE, message_loop_proxy, | 471 return Start(FROM_HERE, message_loop_proxy, |
555 new RelayTruncate(context, path, length, callback)); | 472 new RelayTruncate(context, path, length, callback)); |
556 } | 473 } |
557 | 474 |
558 } // namespace fileapi | 475 } // namespace fileapi |
OLD | NEW |