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 |
74 class RelayWithStatusCallback : public MessageLoopRelay { | 119 class RelayWithStatusCallback : public MessageLoopRelay { |
75 public: | 120 public: |
76 RelayWithStatusCallback( | 121 RelayWithStatusCallback( |
77 const fileapi::FileSystemOperationContext& context, | 122 const fileapi::FileSystemOperationContext& context, |
78 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) | 123 const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) |
79 : MessageLoopRelay(context), | 124 : MessageLoopRelay(context), |
80 callback_(callback) { | 125 callback_(callback) { |
81 // It is OK for callback to be NULL. | 126 // It is OK for callback to be NULL. |
82 } | 127 } |
83 | 128 |
84 protected: | 129 protected: |
85 virtual void RunCallback() { | 130 virtual void RunCallback() { |
86 // The caller may not have been interested in the result. | 131 // The caller may not have been interested in the result. |
87 if (!callback_.is_null()) | 132 if (!callback_.is_null()) |
88 callback_.Run(error_code()); | 133 callback_.Run(error_code()); |
89 } | 134 } |
90 | 135 |
91 private: | 136 private: |
92 fileapi::FileSystemFileUtilProxy::StatusCallback callback_; | 137 fileapi::FileSystemFileUtilProxy::StatusCallback callback_; |
93 }; | 138 }; |
94 | 139 |
| 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 |
95 class RelayEnsureFileExists : public MessageLoopRelay { | 158 class RelayEnsureFileExists : public MessageLoopRelay { |
96 public: | 159 public: |
97 RelayEnsureFileExists( | 160 RelayEnsureFileExists( |
98 const fileapi::FileSystemOperationContext& context, | 161 const fileapi::FileSystemOperationContext& context, |
99 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 162 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
100 const FilePath& file_path, | 163 const FilePath& file_path, |
101 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& | 164 const fileapi::FileSystemFileUtilProxy::EnsureFileExistsCallback& |
102 callback) | 165 callback) |
103 : MessageLoopRelay(context), | 166 : MessageLoopRelay(context), |
104 message_loop_proxy_(message_loop_proxy), | 167 message_loop_proxy_(message_loop_proxy), |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 418 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
356 scoped_refptr<MessageLoopRelay> relay) { | 419 scoped_refptr<MessageLoopRelay> relay) { |
357 return relay->Start(message_loop_proxy, from_here); | 420 return relay->Start(message_loop_proxy, from_here); |
358 } | 421 } |
359 | 422 |
360 } // namespace | 423 } // namespace |
361 | 424 |
362 namespace fileapi { | 425 namespace fileapi { |
363 | 426 |
364 // static | 427 // 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 |
365 bool FileSystemFileUtilProxy::EnsureFileExists( | 448 bool FileSystemFileUtilProxy::EnsureFileExists( |
366 const FileSystemOperationContext& context, | 449 const FileSystemOperationContext& context, |
367 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 450 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
368 const FilePath& file_path, | 451 const FilePath& file_path, |
369 const EnsureFileExistsCallback& callback) { | 452 const EnsureFileExistsCallback& callback) { |
370 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( | 453 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( |
371 context, message_loop_proxy, file_path, callback)); | 454 context, message_loop_proxy, file_path, callback)); |
372 } | 455 } |
373 | 456 |
374 // static | 457 // static |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 const FileSystemOperationContext& context, | 549 const FileSystemOperationContext& context, |
467 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 550 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
468 const FilePath& path, | 551 const FilePath& path, |
469 int64 length, | 552 int64 length, |
470 const StatusCallback& callback) { | 553 const StatusCallback& callback) { |
471 return Start(FROM_HERE, message_loop_proxy, | 554 return Start(FROM_HERE, message_loop_proxy, |
472 new RelayTruncate(context, path, length, callback)); | 555 new RelayTruncate(context, path, length, callback)); |
473 } | 556 } |
474 | 557 |
475 } // namespace fileapi | 558 } // namespace fileapi |
OLD | NEW |