| 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 // |task_runner| is used to perform file operations. It must not be NULL. |
| 43 UploadFileElementReader(base::TaskRunner* task_runner, |
| 44 const FilePath& path, |
| 33 uint64 range_offset, | 45 uint64 range_offset, |
| 34 uint64 range_length, | 46 uint64 range_length, |
| 35 const base::Time& expected_modification_time); | 47 const base::Time& expected_modification_time); |
| 36 virtual ~UploadFileElementReader(); | 48 virtual ~UploadFileElementReader(); |
| 37 | 49 |
| 38 const FilePath& path() const { return path_; } | 50 const FilePath& path() const { return path_; } |
| 39 uint64 range_offset() const { return range_offset_; } | 51 uint64 range_offset() const { return range_offset_; } |
| 40 uint64 range_length() const { return range_length_; } | 52 uint64 range_length() const { return range_length_; } |
| 41 const base::Time& expected_modification_time() const { | 53 const base::Time& expected_modification_time() const { |
| 42 return expected_modification_time_; | 54 return expected_modification_time_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 const CompletionCallback& callback, | 86 const CompletionCallback& callback, |
| 75 int result); | 87 int result); |
| 76 | 88 |
| 77 // Sets an value to override the result for GetContentLength(). | 89 // Sets an value to override the result for GetContentLength(). |
| 78 // Used for tests. | 90 // Used for tests. |
| 79 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { | 91 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { |
| 80 ScopedOverridingContentLengthForTests(uint64 value); | 92 ScopedOverridingContentLengthForTests(uint64 value); |
| 81 ~ScopedOverridingContentLengthForTests(); | 93 ~ScopedOverridingContentLengthForTests(); |
| 82 }; | 94 }; |
| 83 | 95 |
| 96 scoped_refptr<base::TaskRunner> task_runner_; |
| 84 const FilePath path_; | 97 const FilePath path_; |
| 85 const uint64 range_offset_; | 98 const uint64 range_offset_; |
| 86 const uint64 range_length_; | 99 const uint64 range_length_; |
| 87 const base::Time expected_modification_time_; | 100 const base::Time expected_modification_time_; |
| 88 ScopedFileStreamPtr file_stream_; | 101 ScopedFileStreamPtr file_stream_; |
| 89 uint64 content_length_; | 102 uint64 content_length_; |
| 90 uint64 bytes_remaining_; | 103 uint64 bytes_remaining_; |
| 91 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; | 104 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; |
| 92 | 105 |
| 93 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); | 106 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 120 scoped_ptr<FileStream> file_stream_; | 133 scoped_ptr<FileStream> file_stream_; |
| 121 uint64 content_length_; | 134 uint64 content_length_; |
| 122 uint64 bytes_remaining_; | 135 uint64 bytes_remaining_; |
| 123 | 136 |
| 124 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReaderSync); | 137 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReaderSync); |
| 125 }; | 138 }; |
| 126 | 139 |
| 127 } // namespace net | 140 } // namespace net |
| 128 | 141 |
| 129 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ | 142 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ |
| OLD | NEW |