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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_LOCAL_FILE_READER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_LOCAL_FILE_READER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/completion_callback.h"
12 #include "net/base/file_stream.h"
16 class SequencedTaskRunner
;
26 // This is simple local file reader implementation focusing on Drive's use
27 // case. All the operations run on |sequenced_task_runner| asynchronously and
28 // the result will be notified to the caller via |callback|s on the caller's
30 class LocalFileReader
{
32 explicit LocalFileReader(base::SequencedTaskRunner
* sequenced_task_runner
);
35 // Opens the file at |file_path|. The initial position of the read will be
36 // at |offset| from the beginning of the file.
37 // Upon completion, |callback| will be called.
38 // |callback| must not be null.
39 void Open(const base::FilePath
& file_path
,
41 const net::CompletionCallback
& callback
);
43 // Reads the file and copies the data into |buffer|. |buffer_length|
44 // is the length of |buffer|.
45 // Upon completion, |callback| will be called with the result.
46 // |callback| must not be null.
47 void Read(net::IOBuffer
* buffer
,
49 const net::CompletionCallback
& callback
);
52 void DidOpen(const net::CompletionCallback
& callback
,
55 void DidSeek(const net::CompletionCallback
& callback
,
59 net::FileStream file_stream_
;
61 // Note: This should remain the last member so it'll be destroyed and
62 // invalidate the weak pointers before any other members are destroyed.
63 base::WeakPtrFactory
<LocalFileReader
> weak_ptr_factory_
;
64 DISALLOW_COPY_AND_ASSIGN(LocalFileReader
);
70 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_LOCAL_FILE_READER_H_