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

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

Issue 141843002: Revert 245509 "net: Use FileStream asynchronously from UploadFil..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | trunk/src/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/files/file.h"
10 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
11 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "net/base/upload_element_reader.h" 15 #include "net/base/upload_element_reader.h"
17 16
18 namespace base { 17 namespace base {
19 class TaskRunner; 18 class TaskRunner;
(...skipping 24 matching lines...) Expand all
44 // UploadElementReader overrides: 43 // UploadElementReader overrides:
45 virtual const UploadFileElementReader* AsFileReader() const OVERRIDE; 44 virtual const UploadFileElementReader* AsFileReader() const OVERRIDE;
46 virtual int Init(const CompletionCallback& callback) OVERRIDE; 45 virtual int Init(const CompletionCallback& callback) OVERRIDE;
47 virtual uint64 GetContentLength() const OVERRIDE; 46 virtual uint64 GetContentLength() const OVERRIDE;
48 virtual uint64 BytesRemaining() const OVERRIDE; 47 virtual uint64 BytesRemaining() const OVERRIDE;
49 virtual int Read(IOBuffer* buf, 48 virtual int Read(IOBuffer* buf,
50 int buf_length, 49 int buf_length,
51 const CompletionCallback& callback) OVERRIDE; 50 const CompletionCallback& callback) OVERRIDE;
52 51
53 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
54 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength); 67 FRIEND_TEST_ALL_PREFIXES(UploadDataStreamTest, FileSmallerThanLength);
55 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, 68 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest,
56 UploadFileSmallerThanLength); 69 UploadFileSmallerThanLength);
57 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test, 70 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy2Test,
58 UploadFileSmallerThanLength); 71 UploadFileSmallerThanLength);
59 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test, 72 FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionSpdy3Test,
60 UploadFileSmallerThanLength); 73 UploadFileSmallerThanLength);
61 74
62 // Resets this instance to the uninitialized state. 75 // Resets this instance to the uninitialized state.
63 void Reset(); 76 void Reset();
64 77
65 // These methods are used to implement Init(). 78 // This method is used to implement Init().
66 void OnOpenCompleted(const CompletionCallback& callback, int result); 79 void OnInitCompleted(ScopedFileStreamPtr* file_stream,
67 void OnSeekCompleted(const CompletionCallback& callback, int64 result); 80 uint64* content_length,
68 void OnGetFileInfoCompleted(const CompletionCallback& callback, 81 const CompletionCallback& callback,
69 base::File::Info* file_info, 82 int result);
70 bool result);
71 83
72 // This method is used to implement Read(). 84 // This method is used to implement Read().
73 void OnReadCompleted(const CompletionCallback& callback, int result); 85 void OnReadCompleted(ScopedFileStreamPtr file_stream,
86 const CompletionCallback& callback,
87 int result);
74 88
75 // Sets an value to override the result for GetContentLength(). 89 // Sets an value to override the result for GetContentLength().
76 // Used for tests. 90 // Used for tests.
77 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests { 91 struct NET_EXPORT_PRIVATE ScopedOverridingContentLengthForTests {
78 ScopedOverridingContentLengthForTests(uint64 value); 92 ScopedOverridingContentLengthForTests(uint64 value);
79 ~ScopedOverridingContentLengthForTests(); 93 ~ScopedOverridingContentLengthForTests();
80 }; 94 };
81 95
82 scoped_refptr<base::TaskRunner> task_runner_; 96 scoped_refptr<base::TaskRunner> task_runner_;
83 const base::FilePath path_; 97 const base::FilePath path_;
84 const uint64 range_offset_; 98 const uint64 range_offset_;
85 const uint64 range_length_; 99 const uint64 range_length_;
86 const base::Time expected_modification_time_; 100 const base::Time expected_modification_time_;
87 scoped_ptr<FileStream> file_stream_; 101 ScopedFileStreamPtr file_stream_;
88 uint64 content_length_; 102 uint64 content_length_;
89 uint64 bytes_remaining_; 103 uint64 bytes_remaining_;
90 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_; 104 base::WeakPtrFactory<UploadFileElementReader> weak_ptr_factory_;
91 105
92 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader); 106 DISALLOW_COPY_AND_ASSIGN(UploadFileElementReader);
93 }; 107 };
94 108
95 } // namespace net 109 } // namespace net
96 110
97 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_ 111 #endif // NET_BASE_UPLOAD_FILE_ELEMENT_READER_H_
OLDNEW
« no previous file with comments | « no previous file | trunk/src/net/base/upload_file_element_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698