Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / local_file_reader.h
blob0b824da1861a31153e7a4e74c648bb6d3ff8de20
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"
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
17 } // namespace base
19 namespace net {
20 class IOBuffer;
21 } // namespace net
23 namespace drive {
24 namespace util {
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
29 // thread.
30 class LocalFileReader {
31 public:
32 explicit LocalFileReader(base::SequencedTaskRunner* sequenced_task_runner);
33 ~LocalFileReader();
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,
40 int64 offset,
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,
48 int buffer_length,
49 const net::CompletionCallback& callback);
51 private:
52 void DidOpen(const net::CompletionCallback& callback,
53 int64 offset,
54 int error);
55 void DidSeek(const net::CompletionCallback& callback,
56 int64 offset,
57 int64 error);
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);
67 } // namespace util
68 } // namespace drive
70 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_LOCAL_FILE_READER_H_