| 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/plugins/ppapi/quota_file_io.h" | 5 #include "webkit/plugins/ppapi/quota_file_io.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const char* buffer, | 66 const char* buffer, |
| 67 int32_t bytes_to_write, | 67 int32_t bytes_to_write, |
| 68 const WriteCallback& callback) | 68 const WriteCallback& callback) |
| 69 : PendingOperationBase(quota_io, is_will_operation), | 69 : PendingOperationBase(quota_io, is_will_operation), |
| 70 offset_(offset), | 70 offset_(offset), |
| 71 bytes_to_write_(bytes_to_write), | 71 bytes_to_write_(bytes_to_write), |
| 72 callback_(callback), | 72 callback_(callback), |
| 73 finished_(false), | 73 finished_(false), |
| 74 status_(base::PLATFORM_FILE_OK), | 74 status_(base::PLATFORM_FILE_OK), |
| 75 bytes_written_(0), | 75 bytes_written_(0), |
| 76 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 76 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 77 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_factory_(this)) { | |
| 78 if (!is_will_operation) { | 77 if (!is_will_operation) { |
| 79 // TODO(kinuko): check the API convention if we really need to keep a | 78 // TODO(kinuko): Check the API convention if we really need to keep a copy |
| 80 // copy of the buffer during the async write operations. | 79 // of the buffer during the async write operations. |
| 81 buffer_.reset(new char[bytes_to_write]); | 80 buffer_.reset(new char[bytes_to_write]); |
| 82 memcpy(buffer_.get(), buffer, bytes_to_write); | 81 memcpy(buffer_.get(), buffer, bytes_to_write); |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 virtual ~WriteOperation() {} | 84 virtual ~WriteOperation() {} |
| 86 virtual void Run() OVERRIDE { | 85 virtual void Run() OVERRIDE { |
| 87 DCHECK(quota_io_); | 86 DCHECK(quota_io_); |
| 88 if (quota_io_->CheckIfExceedsQuota(offset_ + bytes_to_write_)) { | 87 if (quota_io_->CheckIfExceedsQuota(offset_ + bytes_to_write_)) { |
| 89 DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); | 88 DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); |
| 90 return; | 89 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 } | 112 } |
| 114 | 113 |
| 115 virtual void DidFail(PlatformFileError error) OVERRIDE { | 114 virtual void DidFail(PlatformFileError error) OVERRIDE { |
| 116 DidFinish(error, 0); | 115 DidFinish(error, 0); |
| 117 } | 116 } |
| 118 | 117 |
| 119 bool finished() const { return finished_; } | 118 bool finished() const { return finished_; } |
| 120 | 119 |
| 121 virtual void WillRunCallback() { | 120 virtual void WillRunCallback() { |
| 122 base::MessageLoopProxy::current()->PostTask( | 121 base::MessageLoopProxy::current()->PostTask( |
| 123 FROM_HERE, runnable_factory_.NewRunnableMethod( | 122 FROM_HERE, |
| 124 &WriteOperation::RunCallback)); | 123 base::Bind(&WriteOperation::RunCallback, weak_factory_.GetWeakPtr())); |
| 125 } | 124 } |
| 126 | 125 |
| 127 private: | 126 private: |
| 128 void DidFinish(PlatformFileError status, int bytes_written) { | 127 void DidFinish(PlatformFileError status, int bytes_written) { |
| 129 finished_ = true; | 128 finished_ = true; |
| 130 status_ = status; | 129 status_ = status; |
| 131 bytes_written_ = bytes_written; | 130 bytes_written_ = bytes_written; |
| 132 int64_t max_offset = | 131 int64_t max_offset = |
| 133 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written; | 132 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written; |
| 134 // This may delete itself by calling RunCallback. | 133 // This may delete itself by calling RunCallback. |
| 135 quota_io_->DidWrite(this, max_offset); | 134 quota_io_->DidWrite(this, max_offset); |
| 136 } | 135 } |
| 137 | 136 |
| 138 virtual void RunCallback() { | 137 virtual void RunCallback() { |
| 139 DCHECK_EQ(false, callback_.is_null()); | 138 DCHECK_EQ(false, callback_.is_null()); |
| 140 callback_.Run(status_, bytes_written_); | 139 callback_.Run(status_, bytes_written_); |
| 141 delete this; | 140 delete this; |
| 142 } | 141 } |
| 143 | 142 |
| 144 const int64_t offset_; | 143 const int64_t offset_; |
| 145 scoped_array<char> buffer_; | 144 scoped_array<char> buffer_; |
| 146 const int32_t bytes_to_write_; | 145 const int32_t bytes_to_write_; |
| 147 WriteCallback callback_; | 146 WriteCallback callback_; |
| 148 bool finished_; | 147 bool finished_; |
| 149 PlatformFileError status_; | 148 PlatformFileError status_; |
| 150 int64_t bytes_written_; | 149 int64_t bytes_written_; |
| 151 base::WeakPtrFactory<WriteOperation> weak_factory_; | 150 base::WeakPtrFactory<WriteOperation> weak_factory_; |
| 152 ScopedRunnableMethodFactory<WriteOperation> runnable_factory_; | |
| 153 }; | 151 }; |
| 154 | 152 |
| 155 class QuotaFileIO::SetLengthOperation : public PendingOperationBase { | 153 class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
| 156 public: | 154 public: |
| 157 SetLengthOperation(QuotaFileIO* quota_io, | 155 SetLengthOperation(QuotaFileIO* quota_io, |
| 158 bool is_will_operation, | 156 bool is_will_operation, |
| 159 int64_t length, | 157 int64_t length, |
| 160 const StatusCallback& callback) | 158 const StatusCallback& callback) |
| 161 : PendingOperationBase(quota_io, is_will_operation), | 159 : PendingOperationBase(quota_io, is_will_operation), |
| 162 length_(length), | 160 length_(length), |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 | 396 |
| 399 | 397 |
| 400 PluginDelegate* plugin_delegate = GetPluginDelegate(); | 398 PluginDelegate* plugin_delegate = GetPluginDelegate(); |
| 401 if (plugin_delegate) | 399 if (plugin_delegate) |
| 402 plugin_delegate->DidUpdateFile(file_url_, delta); | 400 plugin_delegate->DidUpdateFile(file_url_, delta); |
| 403 inflight_operations_ = 0; | 401 inflight_operations_ = 0; |
| 404 } | 402 } |
| 405 | 403 |
| 406 } // namespace ppapi | 404 } // namespace ppapi |
| 407 } // namespace webkit | 405 } // namespace webkit |
| OLD | NEW |