| 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 #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/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 FileSystemContext* file_system_context) | 33 FileSystemContext* file_system_context) |
| 34 : simple_writer_(simple_writer), | 34 : simple_writer_(simple_writer), |
| 35 operation_(NULL), | 35 operation_(NULL), |
| 36 file_system_context_(file_system_context) { | 36 file_system_context_(file_system_context) { |
| 37 // The IO thread needs to be running for this class to work. | 37 // The IO thread needs to be running for this class to work. |
| 38 SimpleResourceLoaderBridge::EnsureIOThread(); | 38 SimpleResourceLoaderBridge::EnsureIOThread(); |
| 39 io_thread_ = SimpleResourceLoaderBridge::GetIoThread(); | 39 io_thread_ = SimpleResourceLoaderBridge::GetIoThread(); |
| 40 main_thread_ = base::MessageLoopProxy::current(); | 40 main_thread_ = base::MessageLoopProxy::current(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual ~IOThreadProxy() { | |
| 44 } | |
| 45 | |
| 46 void Truncate(const GURL& path, int64 offset) { | 43 void Truncate(const GURL& path, int64 offset) { |
| 47 if (!io_thread_->BelongsToCurrentThread()) { | 44 if (!io_thread_->BelongsToCurrentThread()) { |
| 48 io_thread_->PostTask( | 45 io_thread_->PostTask( |
| 49 FROM_HERE, | 46 FROM_HERE, |
| 50 base::Bind(&IOThreadProxy::Truncate, this, path, offset)); | 47 base::Bind(&IOThreadProxy::Truncate, this, path, offset)); |
| 51 return; | 48 return; |
| 52 } | 49 } |
| 53 DCHECK(!operation_); | 50 DCHECK(!operation_); |
| 54 operation_ = GetNewOperation(path); | 51 operation_ = GetNewOperation(path); |
| 55 operation_->Truncate(path, offset, | 52 operation_->Truncate(path, offset, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 return; | 75 return; |
| 79 } | 76 } |
| 80 if (!operation_) { | 77 if (!operation_) { |
| 81 DidFailOnMainThread(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 78 DidFailOnMainThread(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 82 return; | 79 return; |
| 83 } | 80 } |
| 84 operation_->Cancel(base::Bind(&IOThreadProxy::DidFinish, this)); | 81 operation_->Cancel(base::Bind(&IOThreadProxy::DidFinish, this)); |
| 85 } | 82 } |
| 86 | 83 |
| 87 private: | 84 private: |
| 85 friend class base::RefCountedThreadSafe<IOThreadProxy>; |
| 86 virtual ~IOThreadProxy() {} |
| 87 |
| 88 FileSystemOperationInterface* GetNewOperation(const GURL& path) { | 88 FileSystemOperationInterface* GetNewOperation(const GURL& path) { |
| 89 return file_system_context_->CreateFileSystemOperation(path, io_thread_); | 89 return file_system_context_->CreateFileSystemOperation(path, io_thread_); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DidSucceedOnMainThread() { | 92 void DidSucceedOnMainThread() { |
| 93 if (!main_thread_->BelongsToCurrentThread()) { | 93 if (!main_thread_->BelongsToCurrentThread()) { |
| 94 main_thread_->PostTask( | 94 main_thread_->PostTask( |
| 95 FROM_HERE, | 95 FROM_HERE, |
| 96 base::Bind(&IOThreadProxy::DidSucceedOnMainThread, this)); | 96 base::Bind(&IOThreadProxy::DidSucceedOnMainThread, this)); |
| 97 return; | 97 return; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 void SimpleFileWriter::DoWrite( | 178 void SimpleFileWriter::DoWrite( |
| 179 const GURL& path, const GURL& blob_url, int64 offset) { | 179 const GURL& path, const GURL& blob_url, int64 offset) { |
| 180 io_thread_proxy_->Write(path, blob_url, offset); | 180 io_thread_proxy_->Write(path, blob_url, offset); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SimpleFileWriter::DoCancel() { | 183 void SimpleFileWriter::DoCancel() { |
| 184 io_thread_proxy_->Cancel(); | 184 io_thread_proxy_->Cancel(); |
| 185 } | 185 } |
| OLD | NEW |