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

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

Issue 10878082: net: Move file operation code from UploadData to UploadDataStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 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 | « chrome_frame/urlmon_upload_data_stream.cc ('k') | net/base/upload_data.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_DATA_H_ 5 #ifndef NET_BASE_UPLOAD_DATA_H_
6 #define NET_BASE_UPLOAD_DATA_H_ 6 #define NET_BASE_UPLOAD_DATA_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/supports_user_data.h" 13 #include "base/supports_user_data.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 #include "net/base/upload_element.h" 15 #include "net/base/upload_element.h"
16 16
17 class FilePath; 17 class FilePath;
18 class GURL;
19 18
20 namespace base { 19 namespace base {
21 class Time; 20 class Time;
22 } // namespace base 21 } // namespace base
23 22
24 namespace net { 23 namespace net {
25 24
26 // Interface implemented by callers who require callbacks when new chunks 25 // Interface implemented by callers who require callbacks when new chunks
27 // of data are added. 26 // of data are added.
28 class NET_EXPORT_PRIVATE ChunkCallback { 27 class NET_EXPORT_PRIVATE ChunkCallback {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 void set_chunk_callback(ChunkCallback* callback); 60 void set_chunk_callback(ChunkCallback* callback);
62 61
63 // Initializes the object to send chunks of upload data over time rather 62 // Initializes the object to send chunks of upload data over time rather
64 // than all at once. 63 // than all at once.
65 void set_is_chunked(bool set) { is_chunked_ = set; } 64 void set_is_chunked(bool set) { is_chunked_ = set; }
66 bool is_chunked() const { return is_chunked_; } 65 bool is_chunked() const { return is_chunked_; }
67 66
68 void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; } 67 void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; }
69 bool last_chunk_appended() const { return last_chunk_appended_; } 68 bool last_chunk_appended() const { return last_chunk_appended_; }
70 69
71 // Gets the total size in bytes of the data to upload. Computing the
72 // content length can result in performing file IO hence the operation is
73 // done asynchronously. Runs the callback with the content length once the
74 // computation is done.
75 typedef base::Callback<void(uint64 content_length)> ContentLengthCallback;
76 void GetContentLength(const ContentLengthCallback& callback);
77
78 // Returns the total size in bytes of the data to upload, for testing.
79 // This version may perform file IO on the current thread. This function
80 // will fail if called on a thread where file IO is prohibited. Usually
81 // used for testing, but Chrome Frame also uses this version.
82 uint64 GetContentLengthSync();
83
84 // Returns true if the upload data is entirely in memory (i.e. the
85 // upload data is not chunked, and all elemnts are of TYPE_BYTES).
86 bool IsInMemory() const;
87
88 // Resets the offset of each upload data element to zero, so that the
89 // upload data can be reread. This can happen if the same upload data is
90 // reused for a new UploadDataStream.
91 void ResetOffset();
92
93 const std::vector<UploadElement>* elements() const { 70 const std::vector<UploadElement>* elements() const {
94 return &elements_; 71 return &elements_;
95 } 72 }
96 73
97 std::vector<UploadElement>* elements_mutable() { 74 std::vector<UploadElement>* elements_mutable() {
98 return &elements_; 75 return &elements_;
99 } 76 }
100 77
101 void SetElements(const std::vector<UploadElement>& elements); 78 void SetElements(const std::vector<UploadElement>& elements);
102 79
103 void swap_elements(std::vector<UploadElement>* elements) { 80 void swap_elements(std::vector<UploadElement>* elements) {
104 elements_.swap(*elements); 81 elements_.swap(*elements);
105 } 82 }
106 83
107 // Identifies a particular upload instance, which is used by the cache to 84 // Identifies a particular upload instance, which is used by the cache to
108 // formulate a cache key. This value should be unique across browser 85 // formulate a cache key. This value should be unique across browser
109 // sessions. A value of 0 is used to indicate an unspecified identifier. 86 // sessions. A value of 0 is used to indicate an unspecified identifier.
110 void set_identifier(int64 id) { identifier_ = id; } 87 void set_identifier(int64 id) { identifier_ = id; }
111 int64 identifier() const { return identifier_; } 88 int64 identifier() const { return identifier_; }
112 89
113 private: 90 private:
114 // Helper function for GetContentLength().
115 void DoGetContentLength(uint64* content_length);
116
117 friend class base::RefCounted<UploadData>; 91 friend class base::RefCounted<UploadData>;
118 92
119 virtual ~UploadData(); 93 virtual ~UploadData();
120 94
121 std::vector<UploadElement> elements_; 95 std::vector<UploadElement> elements_;
122 int64 identifier_; 96 int64 identifier_;
123 ChunkCallback* chunk_callback_; 97 ChunkCallback* chunk_callback_;
124 bool is_chunked_; 98 bool is_chunked_;
125 bool last_chunk_appended_; 99 bool last_chunk_appended_;
126 100
127 DISALLOW_COPY_AND_ASSIGN(UploadData); 101 DISALLOW_COPY_AND_ASSIGN(UploadData);
128 }; 102 };
129 103
130 } // namespace net 104 } // namespace net
131 105
132 #endif // NET_BASE_UPLOAD_DATA_H_ 106 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW
« no previous file with comments | « chrome_frame/urlmon_upload_data_stream.cc ('k') | net/base/upload_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698