OLD | NEW |
---|---|
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 #ifndef NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ | 5 #ifndef NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ |
6 #define NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ | 6 #define NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "net/base/upload_element_reader.h" | 15 #include "net/base/upload_element_reader.h" |
15 | 16 |
17 namespace base { | |
18 class TaskRunner; | |
19 } | |
20 | |
16 namespace net { | 21 namespace net { |
17 | 22 |
18 class FileStream; | 23 class FileStream; |
19 | 24 |
20 // An UploadElementReader implementation for file. | 25 // An UploadElementReader implementation for file. |
21 class NET_EXPORT UploadFileElementReader : public UploadElementReader { | 26 class NET_EXPORT UploadFileElementReader : public UploadElementReader { |
22 public: | 27 public: |
23 // Deletes FileStream on the worker pool to avoid blocking the IO thread. | 28 // Deletes FileStream on the worker pool to avoid blocking the IO thread. |
24 // This class is used as a template argument of scoped_ptr_malloc. | 29 // This class is used as a template argument of scoped_ptr. |
25 class FileStreamDeleter { | 30 class FileStreamDeleter { |
26 public: | 31 public: |
32 explicit FileStreamDeleter(base::TaskRunner* task_runner); | |
33 ~FileStreamDeleter(); | |
27 void operator() (FileStream* file_stream) const; | 34 void operator() (FileStream* file_stream) const; |
35 | |
36 private: | |
37 scoped_refptr<base::TaskRunner> task_runner_; | |
28 }; | 38 }; |
29 | 39 |
30 typedef scoped_ptr_malloc<FileStream, FileStreamDeleter> ScopedFileStreamPtr; | 40 typedef scoped_ptr<FileStream, FileStreamDeleter> ScopedFileStreamPtr; |
31 | 41 |
32 UploadFileElementReader(const FilePath& path, | 42 UploadFileElementReader(base::TaskRunner* task_runner, |
mmenke
2013/01/07 16:42:24
Think it's worth mentioning that |task_runner| sho
hashimoto
2013/01/08 02:27:36
Stopped allowing NULL task_runner.
| |
43 const FilePath& path, | |
33 uint64 range_offset, | 44 uint64 range_offset, |
34 uint64 range_length, | 45 uint64 range_length, |
35 const base::Time& expected_modification_time); | 46 const base::Time& expected_modification_time); |
36 virtual ~UploadFileElementReader(); | 47 virtual ~UploadFileElementReader(); |
37 | 48 |
38 const FilePath& path() const { return path_; } | 49 const FilePath& path() const { return path_; } |
39 uint64 range_offset() const { return range_offset_; } | 50 uint64 range_offset() const { return range_offset_; } |
40 uint64 range_length() const { return range_length_; } | 51 uint64 range_length() const { return range_length_; } |
41 const base::Time& expected_modification_time() const { | 52 const base::Time& expected_modification_time() const { |
42 return expected_modification_time_; | 53 return expected_modification_time_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 const CompletionCallback& callback, | 85 const CompletionCallback& callback, |
75 int result); | 86 int result); |
76 | 87 |
77 // Sets an value to override the result for GetContentLength(). | 88 // Sets an value to override the result for GetContentLength(). |
78 // Used for tests. | 89 // Used for tests. |
79 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { | 90 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { |
80 ScopedOverridingContentLengthForTests(uint64 value); | 91 ScopedOverridingContentLengthForTests(uint64 value); |
81 ~ScopedOverridingContentLengthForTests(); | 92 ~ScopedOverridingContentLengthForTests(); |
82 }; | 93 }; |
83 | 94 |
95 scoped_refptr<base::TaskRunner> task_runner_; | |
84 const FilePath path_; | 96 const FilePath path_; |
85 const uint64 range_offset_; | 97 const uint64 range_offset_; |
86 const uint64 range_length_; | 98 const uint64 range_length_; |
87 const base::Time expected_modification_time_; | 99 const base::Time expected_modification_time_; |
88 ScopedFileStreamPtr file_stream_; | 100 ScopedFileStreamPtr file_stream_; |
89 uint64 content_length_; | 101 uint64 content_length_; |
90 uint64 bytes_remaining_; | 102 uint64 bytes_remaining_; |
91 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; | 103 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; |
92 | 104 |
93 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); | 105 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); |
(...skipping 26 matching lines...) Expand all Loading... | |
120 scoped_ptr<FileStream> file_stream_; | 132 scoped_ptr<FileStream> file_stream_; |
121 uint64 content_length_; | 133 uint64 content_length_; |
122 uint64 bytes_remaining_; | 134 uint64 bytes_remaining_; |
123 | 135 |
124 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReaderSync); | 136 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReaderSync); |
125 }; | 137 }; |
126 | 138 |
127 } // namespace net | 139 } // namespace net |
128 | 140 |
129 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ | 141 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ |
OLD | NEW |