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

Side by Side Diff: webkit/fileapi/file_system_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: fixesz 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
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/fileapi/file_system_file_reader.h" 5 #include "webkit/fileapi/file_system_file_reader.h"
6 6
7 #include "base/file_util_proxy.h" 7 #include "base/file_util_proxy.h"
8 #include "base/message_loop_proxy.h"
9 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "base/sequenced_task_runner.h"
10 #include "net/base/file_stream.h" 10 #include "net/base/file_stream.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "webkit/blob/local_file_reader.h" 13 #include "webkit/blob/local_file_reader.h"
14 #include "webkit/fileapi/file_system_context.h" 14 #include "webkit/fileapi/file_system_context.h"
15 #include "webkit/fileapi/file_system_operation_interface.h" 15 #include "webkit/fileapi/file_system_operation_interface.h"
16 16
17 using webkit_blob::LocalFileReader; 17 using webkit_blob::LocalFileReader;
18 18
19 namespace fileapi { 19 namespace fileapi {
20 20
21 namespace { 21 namespace {
22 22
23 void ReadAdapter(base::WeakPtr<FileSystemFileReader> reader, 23 void ReadAdapter(base::WeakPtr<FileSystemFileReader> reader,
24 net::IOBuffer* buf, int buf_len, 24 net::IOBuffer* buf, int buf_len,
25 const net::CompletionCallback& callback) { 25 const net::CompletionCallback& callback) {
26 if (!reader.get()) 26 if (!reader.get())
27 return; 27 return;
28 int rv = reader->Read(buf, buf_len, callback); 28 int rv = reader->Read(buf, buf_len, callback);
29 if (rv != net::ERR_IO_PENDING) 29 if (rv != net::ERR_IO_PENDING)
30 callback.Run(rv); 30 callback.Run(rv);
31 } 31 }
32 32
33 } 33 }
34 34
35 FileSystemFileReader::FileSystemFileReader( 35 FileSystemFileReader::FileSystemFileReader(
36 base::MessageLoopProxy* file_thread_proxy, 36 base::SequencedTaskRunner* task_runner,
37 FileSystemContext* file_system_context, 37 FileSystemContext* file_system_context,
38 const GURL& url, 38 const GURL& url,
39 int64 initial_offset) 39 int64 initial_offset)
40 : file_thread_proxy_(file_thread_proxy), 40 : task_runner_(task_runner),
michaeln 2012/04/27 22:31:08 ditto, maybe we can pick this 'runner' up from the
kinuko 2012/05/04 19:05:35 Done.
41 file_system_context_(file_system_context), 41 file_system_context_(file_system_context),
42 url_(url), 42 url_(url),
43 initial_offset_(initial_offset), 43 initial_offset_(initial_offset),
44 has_pending_create_snapshot_(false), 44 has_pending_create_snapshot_(false),
45 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 45 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
46 } 46 }
47 47
48 FileSystemFileReader::~FileSystemFileReader() { 48 FileSystemFileReader::~FileSystemFileReader() {
49 } 49 }
50 50
51 int FileSystemFileReader::Read( 51 int FileSystemFileReader::Read(
52 net::IOBuffer* buf, int buf_len, 52 net::IOBuffer* buf, int buf_len,
53 const net::CompletionCallback& callback) { 53 const net::CompletionCallback& callback) {
54 if (local_file_reader_.get()) 54 if (local_file_reader_.get())
55 return local_file_reader_->Read(buf, buf_len, callback); 55 return local_file_reader_->Read(buf, buf_len, callback);
56 DCHECK(!has_pending_create_snapshot_); 56 DCHECK(!has_pending_create_snapshot_);
57 FileSystemOperationInterface* operation = 57 FileSystemOperationInterface* operation =
58 file_system_context_->CreateFileSystemOperation( 58 file_system_context_->CreateFileSystemOperation(url_);
59 url_, file_thread_proxy_);
60 if (!operation) 59 if (!operation)
61 return net::ERR_INVALID_URL; 60 return net::ERR_INVALID_URL;
62 has_pending_create_snapshot_ = true; 61 has_pending_create_snapshot_ = true;
63 operation->CreateSnapshotFile( 62 operation->CreateSnapshotFile(
64 url_, 63 url_,
65 base::Bind(&FileSystemFileReader::DidCreateSnapshot, 64 base::Bind(&FileSystemFileReader::DidCreateSnapshot,
66 weak_factory_.GetWeakPtr(), 65 weak_factory_.GetWeakPtr(),
67 base::Bind(&ReadAdapter, weak_factory_.GetWeakPtr(), 66 base::Bind(&ReadAdapter, weak_factory_.GetWeakPtr(),
68 make_scoped_refptr(buf), buf_len, callback), 67 make_scoped_refptr(buf), buf_len, callback),
69 callback)); 68 callback));
(...skipping 13 matching lines...) Expand all
83 82
84 if (file_error != base::PLATFORM_FILE_OK) { 83 if (file_error != base::PLATFORM_FILE_OK) {
85 callback.Run(LocalFileReader::PlatformFileErrorToNetError(file_error)); 84 callback.Run(LocalFileReader::PlatformFileErrorToNetError(file_error));
86 return; 85 return;
87 } 86 }
88 87
89 // Keep the reference (if it's non-null) so that the file won't go away. 88 // Keep the reference (if it's non-null) so that the file won't go away.
90 snapshot_ref_ = file_ref; 89 snapshot_ref_ = file_ref;
91 90
92 local_file_reader_.reset( 91 local_file_reader_.reset(
93 new LocalFileReader(file_thread_proxy_, 92 new LocalFileReader(task_runner_,
michaeln 2012/04/27 22:31:08 maybe we could use a context_->file_task_runner()
kinuko 2012/05/04 19:05:35 SGTM, done.
94 platform_path, 93 platform_path,
95 initial_offset_, 94 initial_offset_,
96 base::Time())); 95 base::Time()));
97 96
98 read_closure.Run(); 97 read_closure.Run();
99 } 98 }
100 99
101 } // namespace fileapi 100 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698