| 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/tools/test_shell/simple_file_writer.h" | 5 #include "webkit/tools/test_shell/simple_file_writer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 9 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| 10 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 11 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
| 12 #include "webkit/fileapi/file_system_operation.h" | 13 #include "webkit/fileapi/file_system_operation.h" |
| 13 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
| 14 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 15 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 15 | 16 |
| 16 using fileapi::FileSystemCallbackDispatcher; | 17 using fileapi::FileSystemCallbackDispatcher; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 38 SimpleResourceLoaderBridge::EnsureIOThread(); | 39 SimpleResourceLoaderBridge::EnsureIOThread(); |
| 39 io_thread_ = SimpleResourceLoaderBridge::GetIoThread(); | 40 io_thread_ = SimpleResourceLoaderBridge::GetIoThread(); |
| 40 main_thread_ = base::MessageLoopProxy::current(); | 41 main_thread_ = base::MessageLoopProxy::current(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 virtual ~IOThreadProxy() { | 44 virtual ~IOThreadProxy() { |
| 44 } | 45 } |
| 45 | 46 |
| 46 void Truncate(const GURL& path, int64 offset) { | 47 void Truncate(const GURL& path, int64 offset) { |
| 47 if (!io_thread_->BelongsToCurrentThread()) { | 48 if (!io_thread_->BelongsToCurrentThread()) { |
| 48 io_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 49 io_thread_->PostTask( |
| 49 this, &IOThreadProxy::Truncate, path, offset)); | 50 FROM_HERE, |
| 51 base::Bind(&IOThreadProxy::Truncate, this, path, offset)); |
| 50 return; | 52 return; |
| 51 } | 53 } |
| 52 DCHECK(!operation_); | 54 DCHECK(!operation_); |
| 53 operation_ = GetNewOperation(); | 55 operation_ = GetNewOperation(); |
| 54 operation_->Truncate(path, offset); | 56 operation_->Truncate(path, offset); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void Write(const GURL& path, const GURL& blob_url, int64 offset) { | 59 void Write(const GURL& path, const GURL& blob_url, int64 offset) { |
| 58 if (!io_thread_->BelongsToCurrentThread()) { | 60 if (!io_thread_->BelongsToCurrentThread()) { |
| 59 io_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 61 io_thread_->PostTask( |
| 60 this, &IOThreadProxy::Write, path, blob_url, offset)); | 62 FROM_HERE, |
| 63 base::Bind(&IOThreadProxy::Write, this, path, blob_url, offset)); |
| 61 return; | 64 return; |
| 62 } | 65 } |
| 63 DCHECK(request_context_); | 66 DCHECK(request_context_); |
| 64 DCHECK(!operation_); | 67 DCHECK(!operation_); |
| 65 operation_ = GetNewOperation(); | 68 operation_ = GetNewOperation(); |
| 66 operation_->Write(request_context_, path, blob_url, offset); | 69 operation_->Write(request_context_, path, blob_url, offset); |
| 67 } | 70 } |
| 68 | 71 |
| 69 void Cancel() { | 72 void Cancel() { |
| 70 if (!io_thread_->BelongsToCurrentThread()) { | 73 if (!io_thread_->BelongsToCurrentThread()) { |
| 71 io_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 74 io_thread_->PostTask( |
| 72 this, &IOThreadProxy::Cancel)); | 75 FROM_HERE, |
| 76 base::Bind(&IOThreadProxy::Cancel, this)); |
| 73 return; | 77 return; |
| 74 } | 78 } |
| 75 if (!operation_) { | 79 if (!operation_) { |
| 76 DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 80 DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 77 return; | 81 return; |
| 78 } | 82 } |
| 79 operation_->Cancel(GetNewOperation()); | 83 operation_->Cancel(GetNewOperation()); |
| 80 } | 84 } |
| 81 | 85 |
| 82 private: | 86 private: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 129 |
| 126 FileSystemOperation* GetNewOperation() { | 130 FileSystemOperation* GetNewOperation() { |
| 127 // The FileSystemOperation takes ownership of the CallbackDispatcher. | 131 // The FileSystemOperation takes ownership of the CallbackDispatcher. |
| 128 return new FileSystemOperation(new CallbackDispatcher(this), | 132 return new FileSystemOperation(new CallbackDispatcher(this), |
| 129 io_thread_, file_system_context_.get(), | 133 io_thread_, file_system_context_.get(), |
| 130 NULL); | 134 NULL); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void DidSucceed() { | 137 void DidSucceed() { |
| 134 if (!main_thread_->BelongsToCurrentThread()) { | 138 if (!main_thread_->BelongsToCurrentThread()) { |
| 135 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 139 main_thread_->PostTask( |
| 136 this, &IOThreadProxy::DidSucceed)); | 140 FROM_HERE, |
| 141 base::Bind(&IOThreadProxy::DidSucceed, this)); |
| 137 return; | 142 return; |
| 138 } | 143 } |
| 139 if (simple_writer_) | 144 if (simple_writer_) |
| 140 simple_writer_->DidSucceed(); | 145 simple_writer_->DidSucceed(); |
| 141 } | 146 } |
| 142 | 147 |
| 143 void DidFail(base::PlatformFileError error_code) { | 148 void DidFail(base::PlatformFileError error_code) { |
| 144 if (!main_thread_->BelongsToCurrentThread()) { | 149 if (!main_thread_->BelongsToCurrentThread()) { |
| 145 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 150 main_thread_->PostTask( |
| 146 this, &IOThreadProxy::DidFail, error_code)); | 151 FROM_HERE, |
| 152 base::Bind(&IOThreadProxy::DidFail, this, error_code)); |
| 147 return; | 153 return; |
| 148 } | 154 } |
| 149 if (simple_writer_) | 155 if (simple_writer_) |
| 150 simple_writer_->DidFail(error_code); | 156 simple_writer_->DidFail(error_code); |
| 151 } | 157 } |
| 152 | 158 |
| 153 void DidWrite(int64 bytes, bool complete) { | 159 void DidWrite(int64 bytes, bool complete) { |
| 154 if (!main_thread_->BelongsToCurrentThread()) { | 160 if (!main_thread_->BelongsToCurrentThread()) { |
| 155 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 161 main_thread_->PostTask( |
| 156 this, &IOThreadProxy::DidWrite, bytes, complete)); | 162 FROM_HERE, |
| 163 base::Bind(&IOThreadProxy::DidWrite, this, bytes, complete)); |
| 157 return; | 164 return; |
| 158 } | 165 } |
| 159 if (simple_writer_) | 166 if (simple_writer_) |
| 160 simple_writer_->DidWrite(bytes, complete); | 167 simple_writer_->DidWrite(bytes, complete); |
| 161 } | 168 } |
| 162 | 169 |
| 163 void ClearOperation() { | 170 void ClearOperation() { |
| 164 DCHECK(io_thread_->BelongsToCurrentThread()); | 171 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 165 operation_ = NULL; | 172 operation_ = NULL; |
| 166 } | 173 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 194 } | 201 } |
| 195 | 202 |
| 196 void SimpleFileWriter::DoWrite( | 203 void SimpleFileWriter::DoWrite( |
| 197 const GURL& path, const GURL& blob_url, int64 offset) { | 204 const GURL& path, const GURL& blob_url, int64 offset) { |
| 198 io_thread_proxy_->Write(path, blob_url, offset); | 205 io_thread_proxy_->Write(path, blob_url, offset); |
| 199 } | 206 } |
| 200 | 207 |
| 201 void SimpleFileWriter::DoCancel() { | 208 void SimpleFileWriter::DoCancel() { |
| 202 io_thread_proxy_->Cancel(); | 209 io_thread_proxy_->Cancel(); |
| 203 } | 210 } |
| OLD | NEW |