| 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/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "webkit/fileapi/file_system_context.h" | 8 #include "webkit/fileapi/file_system_context.h" |
| 9 #include "webkit/fileapi/file_system_file_util.h" | 9 #include "webkit/fileapi/file_system_file_util.h" |
| 10 #include "webkit/fileapi/file_system_operation_context.h" | 10 #include "webkit/fileapi/file_system_operation_context.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 fileapi::FileSystemFileUtil* file_util_; | 72 fileapi::FileSystemFileUtil* file_util_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class RelayCreateOrOpen : public MessageLoopRelay { | 75 class RelayCreateOrOpen : public MessageLoopRelay { |
| 76 public: | 76 public: |
| 77 RelayCreateOrOpen( | 77 RelayCreateOrOpen( |
| 78 const fileapi::FileSystemOperationContext& context, | 78 const fileapi::FileSystemOperationContext& context, |
| 79 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 79 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 80 const FilePath& file_path, | 80 const FilePath& file_path, |
| 81 int file_flags, | 81 int file_flags, |
| 82 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback) | 82 const fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback& callback) |
| 83 : MessageLoopRelay(context), | 83 : MessageLoopRelay(context), |
| 84 message_loop_proxy_(message_loop_proxy), | 84 message_loop_proxy_(message_loop_proxy), |
| 85 file_path_(file_path), | 85 file_path_(file_path), |
| 86 file_flags_(file_flags), | 86 file_flags_(file_flags), |
| 87 callback_(callback), | 87 callback_(callback), |
| 88 file_handle_(base::kInvalidPlatformFileValue), | 88 file_handle_(base::kInvalidPlatformFileValue), |
| 89 created_(false) { | 89 created_(false) { |
| 90 DCHECK(callback); | 90 DCHECK_EQ(false, callback.is_null()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 virtual ~RelayCreateOrOpen() { | 94 virtual ~RelayCreateOrOpen() { |
| 95 if (file_handle_ != base::kInvalidPlatformFileValue) | 95 if (file_handle_ != base::kInvalidPlatformFileValue) |
| 96 fileapi::FileSystemFileUtilProxy::Close(*context(), | 96 fileapi::FileSystemFileUtilProxy::Close(*context(), |
| 97 message_loop_proxy_, file_handle_, NULL); | 97 message_loop_proxy_, file_handle_, NULL); |
| 98 } | 98 } |
| 99 | 99 |
| 100 virtual void RunWork() { | 100 virtual void RunWork() { |
| 101 set_error_code(file_util()->CreateOrOpen( | 101 set_error_code(file_util()->CreateOrOpen( |
| 102 context(), file_path_, file_flags_, &file_handle_, &created_)); | 102 context(), file_path_, file_flags_, &file_handle_, &created_)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 virtual void RunCallback() { | 105 virtual void RunCallback() { |
| 106 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), | 106 callback_.Run(error_code(), base::PassPlatformFile(&file_handle_), |
| 107 created_); | 107 created_); |
| 108 delete callback_; | |
| 109 } | 108 } |
| 110 | 109 |
| 111 private: | 110 private: |
| 112 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 113 FilePath file_path_; | 112 FilePath file_path_; |
| 114 int file_flags_; | 113 int file_flags_; |
| 115 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback_; | 114 fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback callback_; |
| 116 base::PlatformFile file_handle_; | 115 base::PlatformFile file_handle_; |
| 117 bool created_; | 116 bool created_; |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 class RelayWithStatusCallback : public MessageLoopRelay { | 119 class RelayWithStatusCallback : public MessageLoopRelay { |
| 121 public: | 120 public: |
| 122 RelayWithStatusCallback( | 121 RelayWithStatusCallback( |
| 123 const fileapi::FileSystemOperationContext& context, | 122 const fileapi::FileSystemOperationContext& context, |
| 124 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) | 123 fileapi::FileSystemFileUtilProxy::StatusCallback* callback) |
| 125 : MessageLoopRelay(context), | 124 : MessageLoopRelay(context), |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 424 |
| 426 } // namespace | 425 } // namespace |
| 427 | 426 |
| 428 namespace fileapi { | 427 namespace fileapi { |
| 429 | 428 |
| 430 // static | 429 // static |
| 431 bool FileSystemFileUtilProxy::CreateOrOpen( | 430 bool FileSystemFileUtilProxy::CreateOrOpen( |
| 432 const FileSystemOperationContext& context, | 431 const FileSystemOperationContext& context, |
| 433 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 432 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 434 const FilePath& file_path, int file_flags, | 433 const FilePath& file_path, int file_flags, |
| 435 CreateOrOpenCallback* callback) { | 434 const CreateOrOpenCallback& callback) { |
| 436 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context, | 435 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context, |
| 437 message_loop_proxy, file_path, file_flags, callback)); | 436 message_loop_proxy, file_path, file_flags, callback)); |
| 438 } | 437 } |
| 439 | 438 |
| 440 // static | 439 // static |
| 441 bool FileSystemFileUtilProxy::Close( | 440 bool FileSystemFileUtilProxy::Close( |
| 442 const FileSystemOperationContext& context, | 441 const FileSystemOperationContext& context, |
| 443 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 442 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 444 base::PlatformFile file_handle, | 443 base::PlatformFile file_handle, |
| 445 StatusCallback* callback) { | 444 StatusCallback* callback) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 const FileSystemOperationContext& context, | 551 const FileSystemOperationContext& context, |
| 553 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 552 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 554 const FilePath& path, | 553 const FilePath& path, |
| 555 int64 length, | 554 int64 length, |
| 556 StatusCallback* callback) { | 555 StatusCallback* callback) { |
| 557 return Start(FROM_HERE, message_loop_proxy, | 556 return Start(FROM_HERE, message_loop_proxy, |
| 558 new RelayTruncate(context, path, length, callback)); | 557 new RelayTruncate(context, path, length, callback)); |
| 559 } | 558 } |
| 560 | 559 |
| 561 } // namespace fileapi | 560 } // namespace fileapi |
| OLD | NEW |