BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / components / drive / local_file_reader.cc
blobe96b24157bd06901a41aeeee8c340edefeda9746
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/drive/local_file_reader.h"
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/sequenced_task_runner.h"
10 #include "net/base/completion_callback.h"
11 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h"
14 namespace drive {
15 namespace util {
17 LocalFileReader::LocalFileReader(
18 base::SequencedTaskRunner* sequenced_task_runner)
19 : file_stream_(sequenced_task_runner),
20 weak_ptr_factory_(this) {
23 LocalFileReader::~LocalFileReader() {
26 void LocalFileReader::Open(const base::FilePath& file_path,
27 int64 offset,
28 const net::CompletionCallback& callback) {
29 DCHECK(!callback.is_null());
30 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
31 base::File::FLAG_ASYNC;
33 int rv = file_stream_.Open(file_path, flags,
34 Bind(&LocalFileReader::DidOpen,
35 weak_ptr_factory_.GetWeakPtr(),
36 callback, offset));
37 DCHECK_EQ(rv, net::ERR_IO_PENDING);
40 void LocalFileReader::Read(net::IOBuffer* in_buffer,
41 int buffer_length,
42 const net::CompletionCallback& callback) {
43 DCHECK(!callback.is_null());
44 DCHECK(file_stream_.IsOpen());
45 int rv = file_stream_.Read(in_buffer, buffer_length, callback);
46 DCHECK_EQ(rv, net::ERR_IO_PENDING);
49 void LocalFileReader::DidOpen(const net::CompletionCallback& callback,
50 int64 offset,
51 int error) {
52 if (error != net::OK)
53 return callback.Run(error);
55 int rv = file_stream_.Seek(
56 offset, Bind(&LocalFileReader::DidSeek, weak_ptr_factory_.GetWeakPtr(),
57 callback, offset));
58 DCHECK_EQ(rv, net::ERR_IO_PENDING);
61 void LocalFileReader::DidSeek(const net::CompletionCallback& callback,
62 int64 offset,
63 int64 error) {
64 callback.Run(error == offset ? net::OK : net::ERR_FAILED);
67 } // namespace util
68 } // namespace drive