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

Side by Side Diff: base/files/file_proxy.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/files/file_path_watcher_unittest.cc ('k') | base/files/file_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/files/file_proxy.h" 5 #include "base/files/file_proxy.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 error_ = (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; 185 error_ = (bytes_read_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
186 } 186 }
187 187
188 void Reply(const FileProxy::ReadCallback& callback) { 188 void Reply(const FileProxy::ReadCallback& callback) {
189 PassFile(); 189 PassFile();
190 DCHECK(!callback.is_null()); 190 DCHECK(!callback.is_null());
191 callback.Run(error_, buffer_.get(), bytes_read_); 191 callback.Run(error_, buffer_.get(), bytes_read_);
192 } 192 }
193 193
194 private: 194 private:
195 scoped_ptr<char[]> buffer_; 195 std::unique_ptr<char[]> buffer_;
196 int bytes_to_read_; 196 int bytes_to_read_;
197 int bytes_read_; 197 int bytes_read_;
198 DISALLOW_COPY_AND_ASSIGN(ReadHelper); 198 DISALLOW_COPY_AND_ASSIGN(ReadHelper);
199 }; 199 };
200 200
201 class WriteHelper : public FileHelper { 201 class WriteHelper : public FileHelper {
202 public: 202 public:
203 WriteHelper(FileProxy* proxy, 203 WriteHelper(FileProxy* proxy,
204 File file, 204 File file,
205 const char* buffer, int bytes_to_write) 205 const char* buffer, int bytes_to_write)
206 : FileHelper(proxy, std::move(file)), 206 : FileHelper(proxy, std::move(file)),
207 buffer_(new char[bytes_to_write]), 207 buffer_(new char[bytes_to_write]),
208 bytes_to_write_(bytes_to_write), 208 bytes_to_write_(bytes_to_write),
209 bytes_written_(0) { 209 bytes_written_(0) {
210 memcpy(buffer_.get(), buffer, bytes_to_write); 210 memcpy(buffer_.get(), buffer, bytes_to_write);
211 } 211 }
212 212
213 void RunWork(int64_t offset) { 213 void RunWork(int64_t offset) {
214 bytes_written_ = file_.Write(offset, buffer_.get(), bytes_to_write_); 214 bytes_written_ = file_.Write(offset, buffer_.get(), bytes_to_write_);
215 error_ = (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK; 215 error_ = (bytes_written_ < 0) ? File::FILE_ERROR_FAILED : File::FILE_OK;
216 } 216 }
217 217
218 void Reply(const FileProxy::WriteCallback& callback) { 218 void Reply(const FileProxy::WriteCallback& callback) {
219 PassFile(); 219 PassFile();
220 if (!callback.is_null()) 220 if (!callback.is_null())
221 callback.Run(error_, bytes_written_); 221 callback.Run(error_, bytes_written_);
222 } 222 }
223 223
224 private: 224 private:
225 scoped_ptr<char[]> buffer_; 225 std::unique_ptr<char[]> buffer_;
226 int bytes_to_write_; 226 int bytes_to_write_;
227 int bytes_written_; 227 int bytes_written_;
228 DISALLOW_COPY_AND_ASSIGN(WriteHelper); 228 DISALLOW_COPY_AND_ASSIGN(WriteHelper);
229 }; 229 };
230 230
231 } // namespace 231 } // namespace
232 232
233 FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) { 233 FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) {
234 } 234 }
235 235
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 bool FileProxy::Flush(const StatusCallback& callback) { 350 bool FileProxy::Flush(const StatusCallback& callback) {
351 DCHECK(file_.IsValid()); 351 DCHECK(file_.IsValid());
352 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); 352 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_));
353 return task_runner_->PostTaskAndReply( 353 return task_runner_->PostTaskAndReply(
354 FROM_HERE, 354 FROM_HERE,
355 Bind(&GenericFileHelper::Flush, Unretained(helper)), 355 Bind(&GenericFileHelper::Flush, Unretained(helper)),
356 Bind(&GenericFileHelper::Reply, Owned(helper), callback)); 356 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
357 } 357 }
358 358
359 } // namespace base 359 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_unittest.cc ('k') | base/files/file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698