OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ | 5 #ifndef COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ |
6 #define COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ | 6 #define COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include <stdint.h> |
| 9 |
| 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
11 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
12 #include "net/base/file_stream.h" | 14 #include "net/base/file_stream.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 class FilePath; | 17 class FilePath; |
16 class SequencedTaskRunner; | 18 class SequencedTaskRunner; |
17 } // namespace base | 19 } // namespace base |
18 | 20 |
(...skipping 11 matching lines...) Expand all Loading... |
30 class LocalFileReader { | 32 class LocalFileReader { |
31 public: | 33 public: |
32 explicit LocalFileReader(base::SequencedTaskRunner* sequenced_task_runner); | 34 explicit LocalFileReader(base::SequencedTaskRunner* sequenced_task_runner); |
33 ~LocalFileReader(); | 35 ~LocalFileReader(); |
34 | 36 |
35 // Opens the file at |file_path|. The initial position of the read will be | 37 // Opens the file at |file_path|. The initial position of the read will be |
36 // at |offset| from the beginning of the file. | 38 // at |offset| from the beginning of the file. |
37 // Upon completion, |callback| will be called. | 39 // Upon completion, |callback| will be called. |
38 // |callback| must not be null. | 40 // |callback| must not be null. |
39 void Open(const base::FilePath& file_path, | 41 void Open(const base::FilePath& file_path, |
40 int64 offset, | 42 int64_t offset, |
41 const net::CompletionCallback& callback); | 43 const net::CompletionCallback& callback); |
42 | 44 |
43 // Reads the file and copies the data into |buffer|. |buffer_length| | 45 // Reads the file and copies the data into |buffer|. |buffer_length| |
44 // is the length of |buffer|. | 46 // is the length of |buffer|. |
45 // Upon completion, |callback| will be called with the result. | 47 // Upon completion, |callback| will be called with the result. |
46 // |callback| must not be null. | 48 // |callback| must not be null. |
47 void Read(net::IOBuffer* buffer, | 49 void Read(net::IOBuffer* buffer, |
48 int buffer_length, | 50 int buffer_length, |
49 const net::CompletionCallback& callback); | 51 const net::CompletionCallback& callback); |
50 | 52 |
51 private: | 53 private: |
52 void DidOpen(const net::CompletionCallback& callback, | 54 void DidOpen(const net::CompletionCallback& callback, |
53 int64 offset, | 55 int64_t offset, |
54 int error); | 56 int error); |
55 void DidSeek(const net::CompletionCallback& callback, | 57 void DidSeek(const net::CompletionCallback& callback, |
56 int64 offset, | 58 int64_t offset, |
57 int64 error); | 59 int64_t error); |
58 | 60 |
59 net::FileStream file_stream_; | 61 net::FileStream file_stream_; |
60 | 62 |
61 // Note: This should remain the last member so it'll be destroyed and | 63 // Note: This should remain the last member so it'll be destroyed and |
62 // invalidate the weak pointers before any other members are destroyed. | 64 // invalidate the weak pointers before any other members are destroyed. |
63 base::WeakPtrFactory<LocalFileReader> weak_ptr_factory_; | 65 base::WeakPtrFactory<LocalFileReader> weak_ptr_factory_; |
64 DISALLOW_COPY_AND_ASSIGN(LocalFileReader); | 66 DISALLOW_COPY_AND_ASSIGN(LocalFileReader); |
65 }; | 67 }; |
66 | 68 |
67 } // namespace util | 69 } // namespace util |
68 } // namespace drive | 70 } // namespace drive |
69 | 71 |
70 #endif // COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ | 72 #endif // COMPONENTS_DRIVE_LOCAL_FILE_READER_H_ |
OLD | NEW |