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

Side by Side Diff: webkit/blob/local_file_reader.cc

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 7 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
« no previous file with comments | « webkit/blob/local_file_reader.h ('k') | webkit/chromeos/fileapi/cros_mount_point_provider.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 (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/blob/local_file_reader.h" 5 #include "webkit/blob/local_file_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/file_util_proxy.h" 8 #include "base/file_util_proxy.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop_proxy.h"
12 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/task_runner.h"
13 #include "net/base/file_stream.h" 13 #include "net/base/file_stream.h"
14 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 16
17 namespace webkit_blob { 17 namespace webkit_blob {
18 18
19 namespace { 19 namespace {
20 20
21 const int kOpenFlagsForRead = base::PLATFORM_FILE_OPEN | 21 const int kOpenFlagsForRead = base::PLATFORM_FILE_OPEN |
22 base::PLATFORM_FILE_READ | 22 base::PLATFORM_FILE_READ |
(...skipping 18 matching lines...) Expand all
41 case base::PLATFORM_FILE_ERROR_NOT_FOUND: 41 case base::PLATFORM_FILE_ERROR_NOT_FOUND:
42 return net::ERR_FILE_NOT_FOUND; 42 return net::ERR_FILE_NOT_FOUND;
43 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: 43 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
44 return net::ERR_ACCESS_DENIED; 44 return net::ERR_ACCESS_DENIED;
45 default: 45 default:
46 return net::ERR_FAILED; 46 return net::ERR_FAILED;
47 } 47 }
48 } 48 }
49 49
50 LocalFileReader::LocalFileReader( 50 LocalFileReader::LocalFileReader(
51 base::MessageLoopProxy* file_thread_proxy, 51 base::TaskRunner* task_runner,
52 const FilePath& file_path, 52 const FilePath& file_path,
53 int64 initial_offset, 53 int64 initial_offset,
54 const base::Time& expected_modification_time) 54 const base::Time& expected_modification_time)
55 : file_thread_proxy_(file_thread_proxy), 55 : task_runner_(task_runner),
56 file_path_(file_path), 56 file_path_(file_path),
57 initial_offset_(initial_offset), 57 initial_offset_(initial_offset),
58 expected_modification_time_(expected_modification_time), 58 expected_modification_time_(expected_modification_time),
59 has_pending_open_(false), 59 has_pending_open_(false),
60 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 60 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
61 61
62 LocalFileReader::~LocalFileReader() { 62 LocalFileReader::~LocalFileReader() {
63 } 63 }
64 64
65 int LocalFileReader::Read(net::IOBuffer* buf, int buf_len, 65 int LocalFileReader::Read(net::IOBuffer* buf, int buf_len,
66 const net::CompletionCallback& callback) { 66 const net::CompletionCallback& callback) {
67 DCHECK(!has_pending_open_); 67 DCHECK(!has_pending_open_);
68 if (stream_impl_.get()) 68 if (stream_impl_.get())
69 return stream_impl_->Read(buf, buf_len, callback); 69 return stream_impl_->Read(buf, buf_len, callback);
70 return Open(base::Bind(&LocalFileReader::DidOpenForRead, 70 return Open(base::Bind(&LocalFileReader::DidOpenForRead,
71 weak_factory_.GetWeakPtr(), 71 weak_factory_.GetWeakPtr(),
72 make_scoped_refptr(buf), buf_len, callback)); 72 make_scoped_refptr(buf), buf_len, callback));
73 } 73 }
74 74
75 int LocalFileReader::GetLength(const net::Int64CompletionCallback& callback) { 75 int LocalFileReader::GetLength(const net::Int64CompletionCallback& callback) {
76 const bool posted = base::FileUtilProxy::GetFileInfo( 76 const bool posted = base::FileUtilProxy::GetFileInfo(
77 file_thread_proxy_, file_path_, 77 task_runner_, file_path_,
78 base::Bind(&LocalFileReader::DidGetFileInfoForGetLength, 78 base::Bind(&LocalFileReader::DidGetFileInfoForGetLength,
79 weak_factory_.GetWeakPtr(), callback)); 79 weak_factory_.GetWeakPtr(), callback));
80 DCHECK(posted); 80 DCHECK(posted);
81 return net::ERR_IO_PENDING; 81 return net::ERR_IO_PENDING;
82 } 82 }
83 83
84 int LocalFileReader::Open(const net::CompletionCallback& callback) { 84 int LocalFileReader::Open(const net::CompletionCallback& callback) {
85 DCHECK(!has_pending_open_); 85 DCHECK(!has_pending_open_);
86 DCHECK(!stream_impl_.get()); 86 DCHECK(!stream_impl_.get());
87 has_pending_open_ = true; 87 has_pending_open_ = true;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return; 170 return;
171 } 171 }
172 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { 172 if (!VerifySnapshotTime(expected_modification_time_, file_info)) {
173 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); 173 callback.Run(net::ERR_UPLOAD_FILE_CHANGED);
174 return; 174 return;
175 } 175 }
176 callback.Run(file_info.size); 176 callback.Run(file_info.size);
177 } 177 }
178 178
179 } // namespace webkit_blob 179 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/local_file_reader.h ('k') | webkit/chromeos/fileapi/cros_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698