Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1694)

Side by Side Diff: webkit/plugins/ppapi/quota_file_io.cc

Issue 8231004: Remaining cleanup (base::Bind): Replacing FileUtilProxy calls with new callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
80 // copy of the buffer during the async write operations. 79 // copy 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_);
(...skipping 25 matching lines...) Expand all
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,
124 weak_factory_.GetWeakPtr()));
125 } 125 }
126 126
127 private: 127 private:
128 void DidFinish(PlatformFileError status, int bytes_written) { 128 void DidFinish(PlatformFileError status, int bytes_written) {
129 finished_ = true; 129 finished_ = true;
130 status_ = status; 130 status_ = status;
131 bytes_written_ = bytes_written; 131 bytes_written_ = bytes_written;
132 int64_t max_offset = 132 int64_t max_offset =
133 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written; 133 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written;
134 // This may delete itself by calling RunCallback. 134 // This may delete itself by calling RunCallback.
135 quota_io_->DidWrite(this, max_offset); 135 quota_io_->DidWrite(this, max_offset);
136 } 136 }
137 137
138 virtual void RunCallback() { 138 virtual void RunCallback() {
139 DCHECK_EQ(false, callback_.is_null()); 139 DCHECK_EQ(false, callback_.is_null());
140 callback_.Run(status_, bytes_written_); 140 callback_.Run(status_, bytes_written_);
141 delete this; 141 delete this;
142 } 142 }
143 143
144 const int64_t offset_; 144 const int64_t offset_;
145 scoped_array<char> buffer_; 145 scoped_array<char> buffer_;
146 const int32_t bytes_to_write_; 146 const int32_t bytes_to_write_;
147 WriteCallback callback_; 147 WriteCallback callback_;
148 bool finished_; 148 bool finished_;
149 PlatformFileError status_; 149 PlatformFileError status_;
150 int64_t bytes_written_; 150 int64_t bytes_written_;
151 base::WeakPtrFactory<WriteOperation> weak_factory_; 151 base::WeakPtrFactory<WriteOperation> weak_factory_;
152 ScopedRunnableMethodFactory<WriteOperation> runnable_factory_;
153 }; 152 };
154 153
155 class QuotaFileIO::SetLengthOperation : public PendingOperationBase { 154 class QuotaFileIO::SetLengthOperation : public PendingOperationBase {
156 public: 155 public:
157 SetLengthOperation(QuotaFileIO* quota_io, 156 SetLengthOperation(QuotaFileIO* quota_io,
158 bool is_will_operation, 157 bool is_will_operation,
159 int64_t length, 158 int64_t length,
160 const StatusCallback& callback) 159 const StatusCallback& callback)
161 : PendingOperationBase(quota_io, is_will_operation), 160 : PendingOperationBase(quota_io, is_will_operation),
162 length_(length), 161 length_(length),
(...skipping 13 matching lines...) Expand all
176 return; 175 return;
177 } 176 }
178 177
179 PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate(); 178 PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate();
180 if (!plugin_delegate) { 179 if (!plugin_delegate) {
181 DidFail(base::PLATFORM_FILE_ERROR_FAILED); 180 DidFail(base::PLATFORM_FILE_ERROR_FAILED);
182 return; 181 return;
183 } 182 }
184 183
185 if (!base::FileUtilProxy::Truncate( 184 if (!base::FileUtilProxy::Truncate(
186 plugin_delegate->GetFileThreadMessageLoopProxy(), quota_io_->file_, 185 plugin_delegate->GetFileThreadMessageLoopProxy(),
187 length_, 186 quota_io_->file_, length_,
188 base::Bind(&SetLengthOperation::DidFinish, 187 base::Bind(&SetLengthOperation::DidFinish,
189 weak_factory_.GetWeakPtr()))) { 188 weak_factory_.GetWeakPtr()))) {
190 DidFail(base::PLATFORM_FILE_ERROR_FAILED); 189 DidFail(base::PLATFORM_FILE_ERROR_FAILED);
191 return; 190 return;
192 } 191 }
193 } 192 }
194 193
195 virtual void DidFail(PlatformFileError error) OVERRIDE { 194 virtual void DidFail(PlatformFileError error) OVERRIDE {
196 DidFinish(error); 195 DidFinish(error);
197 } 196 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 397
399 398
400 PluginDelegate* plugin_delegate = GetPluginDelegate(); 399 PluginDelegate* plugin_delegate = GetPluginDelegate();
401 if (plugin_delegate) 400 if (plugin_delegate)
402 plugin_delegate->DidUpdateFile(file_url_, delta); 401 plugin_delegate->DidUpdateFile(file_url_, delta);
403 inflight_operations_ = 0; 402 inflight_operations_ = 0;
404 } 403 }
405 404
406 } // namespace ppapi 405 } // namespace ppapi
407 } // namespace webkit 406 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698