| 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/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "net/base/upload_element_reader.h" | 14 #include "net/base/upload_element_reader.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 class FileStream; | 18 class FileStream; |
| 18 | 19 |
| 19 // An UploadElementReader implementation for file. | 20 // An UploadElementReader implementation for file. |
| 20 class NET_EXPORT_PRIVATE UploadFileElementReader : public UploadElementReader { | 21 class NET_EXPORT_PRIVATE UploadFileElementReader : public UploadElementReader { |
| 21 public: | 22 public: |
| 22 UploadFileElementReader(const FilePath& path, | 23 UploadFileElementReader(const FilePath& path, |
| 23 uint64 range_offset, | 24 uint64 range_offset, |
| 24 uint64 range_length, | 25 uint64 range_length, |
| 25 const base::Time& expected_modification_time); | 26 const base::Time& expected_modification_time); |
| 26 virtual ~UploadFileElementReader(); | 27 virtual ~UploadFileElementReader(); |
| 27 | 28 |
| 28 // UploadElementReader overrides: | 29 // UploadElementReader overrides: |
| 30 virtual int Init(const CompletionCallback& callback) OVERRIDE; |
| 29 virtual int InitSync() OVERRIDE; | 31 virtual int InitSync() OVERRIDE; |
| 30 virtual uint64 GetContentLength() const OVERRIDE; | 32 virtual uint64 GetContentLength() const OVERRIDE; |
| 31 virtual uint64 BytesRemaining() const OVERRIDE; | 33 virtual uint64 BytesRemaining() const OVERRIDE; |
| 32 virtual int ReadSync(char* buf, int buf_length) OVERRIDE; | 34 virtual int ReadSync(char* buf, int buf_length) OVERRIDE; |
| 33 | 35 |
| 34 private: | 36 private: |
| 37 // This method is used to implement Init(). |
| 38 void OnInitCompleted(scoped_ptr<FileStream>* file_stream, |
| 39 uint64* content_length, |
| 40 int* result, |
| 41 const CompletionCallback& callback); |
| 42 |
| 35 // Sets an value to override the result for GetContentLength(). | 43 // Sets an value to override the result for GetContentLength(). |
| 36 // Used for tests. | 44 // Used for tests. |
| 37 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { | 45 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { |
| 38 ScopedOverridingContentLengthForTests(uint64 value); | 46 ScopedOverridingContentLengthForTests(uint64 value); |
| 39 ~ScopedOverridingContentLengthForTests(); | 47 ~ScopedOverridingContentLengthForTests(); |
| 40 }; | 48 }; |
| 41 | 49 |
| 42 FilePath path_; | 50 FilePath path_; |
| 43 uint64 range_offset_; | 51 uint64 range_offset_; |
| 44 uint64 range_length_; | 52 uint64 range_length_; |
| 45 base::Time expected_modification_time_; | 53 base::Time expected_modification_time_; |
| 46 scoped_ptr<FileStream> file_stream_; | 54 scoped_ptr<FileStream> file_stream_; |
| 47 uint64 content_length_; | 55 uint64 content_length_; |
| 48 uint64 bytes_remaining_; | 56 uint64 bytes_remaining_; |
| 57 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; |
| 49 | 58 |
| 50 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); | 59 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); |
| 51 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, | 60 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, |
| 52 UploadFileSmallerThanLength); | 61 UploadFileSmallerThanLength); |
| 53 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, | 62 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, |
| 54 UploadFileSmallerThanLength); | 63 UploadFileSmallerThanLength); |
| 55 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, | 64 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, |
| 56 UploadFileSmallerThanLength); | 65 UploadFileSmallerThanLength); |
| 57 | 66 |
| 58 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); | 67 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); |
| 59 }; | 68 }; |
| 60 | 69 |
| 61 } // namespace net | 70 } // namespace net |
| 62 | 71 |
| 63 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ | 72 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ |
| OLD | NEW |