Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: net/base/upload_file_element_reader.h

Issue 11778016: net: Stop using base::WorkerPool from UploadFileElementReader (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix CF Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/upload_data_stream_unittest.cc ('k') | net/base/upload_file_element_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // |task_runner| is used to perform file operations. It must not be NULL.
24 // This class is used as a template argument of scoped_ptr_malloc. 29 UploadFileElementReader(base::TaskRunner* task_runner,
25 class FileStreamDeleter { 30 const FilePath& path,
26 public:
27 void operator() (FileStream* file_stream) const;
28 };
29
30 typedef scoped_ptr_malloc<FileStream, FileStreamDeleter> ScopedFileStreamPtr;
31
32 UploadFileElementReader(const FilePath& path,
33 uint64 range_offset, 31 uint64 range_offset,
34 uint64 range_length, 32 uint64 range_length,
35 const base::Time& expected_modification_time); 33 const base::Time& expected_modification_time);
36 virtual ~UploadFileElementReader(); 34 virtual ~UploadFileElementReader();
37 35
38 const FilePath& path() const { return path_; } 36 const FilePath& path() const { return path_; }
39 uint64 range_offset() const { return range_offset_; } 37 uint64 range_offset() const { return range_offset_; }
40 uint64 range_length() const { return range_length_; } 38 uint64 range_length() const { return range_length_; }
41 const base::Time& expected_modification_time() const { 39 const base::Time& expected_modification_time() const {
42 return expected_modification_time_; 40 return expected_modification_time_;
43 } 41 }
44 42
45 // UploadElementReader overrides: 43 // UploadElementReader overrides:
46 virtual const UploadFileElementReader* AsFileReader() const OVERRIDE; 44 virtual const UploadFileElementReader* AsFileReader() const OVERRIDE;
47 virtual int Init(const CompletionCallback& callback) OVERRIDE; 45 virtual int Init(const CompletionCallback& callback) OVERRIDE;
48 virtual uint64 GetContentLength() const OVERRIDE; 46 virtual uint64 GetContentLength() const OVERRIDE;
49 virtual uint64 BytesRemaining() const OVERRIDE; 47 virtual uint64 BytesRemaining() const OVERRIDE;
50 virtual int Read(IOBuffer* buf, 48 virtual int Read(IOBuffer* buf,
51 int buf_length, 49 int buf_length,
52 const CompletionCallback& callback) OVERRIDE; 50 const CompletionCallback& callback) OVERRIDE;
53 51
54 private: 52 private:
53 // Deletes FileStream with |task_runner| to avoid blocking the IO thread.
54 // This class is used as a template argument of scoped_ptr.
55 class FileStreamDeleter {
56 public:
57 explicit FileStreamDeleter(base::TaskRunner* task_runner);
58 ~FileStreamDeleter();
59 void operator() (FileStream* file_stream) const;
60
61 private:
62 scoped_refptr<base::TaskRunner> task_runner_;
63 };
64
65 typedef scoped_ptr<FileStream, FileStreamDeleter> ScopedFileStreamPtr;
66
55 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); 67 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength);
56 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, 68 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest,
57 UploadFileSmallerThanLength); 69 UploadFileSmallerThanLength);
58 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, 70 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test,
59 UploadFileSmallerThanLength); 71 UploadFileSmallerThanLength);
60 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, 72 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test,
61 UploadFileSmallerThanLength); 73 UploadFileSmallerThanLength);
62 74
63 // Resets this instance to the uninitialized state. 75 // Resets this instance to the uninitialized state.
64 void Reset(); 76 void Reset();
65 77
66 // This method is used to implement Init(). 78 // This method is used to implement Init().
67 void OnInitCompleted(ScopedFileStreamPtr* file_stream, 79 void OnInitCompleted(ScopedFileStreamPtr* file_stream,
68 uint64* content_length, 80 uint64* content_length,
69 const CompletionCallback& callback, 81 const CompletionCallback& callback,
70 int result); 82 int result);
71 83
72 // This method is used to implement Read(). 84 // This method is used to implement Read().
73 void OnReadCompleted(ScopedFileStreamPtr file_stream, 85 void OnReadCompleted(ScopedFileStreamPtr file_stream,
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
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_
OLDNEW
« no previous file with comments | « net/base/upload_data_stream_unittest.cc ('k') | net/base/upload_file_element_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698