| 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_DATA_H_ | 5 #ifndef NET_BASE_UPLOAD_DATA_H_ |
| 6 #define NET_BASE_UPLOAD_DATA_H_ | 6 #define NET_BASE_UPLOAD_DATA_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/time.h" | 16 #include "base/time.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 class FileStream; | 22 class FileStream; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void SetToChunk(const char* bytes, int bytes_len, bool is_last_chunk); | 101 void SetToChunk(const char* bytes, int bytes_len, bool is_last_chunk); |
| 101 | 102 |
| 102 bool is_last_chunk() const { return is_last_chunk_; } | 103 bool is_last_chunk() const { return is_last_chunk_; } |
| 103 // Sets whether this is the last chunk. Used during IPC marshalling. | 104 // Sets whether this is the last chunk. Used during IPC marshalling. |
| 104 void set_is_last_chunk(bool is_last_chunk) { | 105 void set_is_last_chunk(bool is_last_chunk) { |
| 105 is_last_chunk_ = is_last_chunk; | 106 is_last_chunk_ = is_last_chunk; |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Returns the byte-length of the element. For files that do not exist, 0 | 109 // Returns the byte-length of the element. For files that do not exist, 0 |
| 109 // is returned. This is done for consistency with Mozilla. | 110 // is returned. This is done for consistency with Mozilla. |
| 110 // Once called, this function will always return the same value. | |
| 111 uint64 GetContentLength(); | 111 uint64 GetContentLength(); |
| 112 | 112 |
| 113 // Returns a FileStream opened for reading for this element, positioned at | 113 // Returns a FileStream opened for reading for this element, positioned at |
| 114 // |file_range_offset_|. The caller gets ownership and is responsible | 114 // |file_range_offset_|. The caller gets ownership and is responsible |
| 115 // for cleaning up the FileStream. Returns NULL if this element is not of | 115 // for cleaning up the FileStream. Returns NULL if this element is not of |
| 116 // type TYPE_FILE or if the file is not openable. | 116 // type TYPE_FILE or if the file is not openable. |
| 117 FileStream* NewFileStreamForReading(); | 117 FileStream* NewFileStreamForReading(); |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 // Allows tests to override the result of GetContentLength. | 120 // Allows tests to override the result of GetContentLength. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk); | 156 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk); |
| 157 | 157 |
| 158 // Sets the callback to be invoked when a new chunk is available to upload. | 158 // Sets the callback to be invoked when a new chunk is available to upload. |
| 159 void set_chunk_callback(ChunkCallback* callback); | 159 void set_chunk_callback(ChunkCallback* callback); |
| 160 | 160 |
| 161 // Initializes the object to send chunks of upload data over time rather | 161 // Initializes the object to send chunks of upload data over time rather |
| 162 // than all at once. | 162 // than all at once. |
| 163 void set_is_chunked(bool set) { is_chunked_ = set; } | 163 void set_is_chunked(bool set) { is_chunked_ = set; } |
| 164 bool is_chunked() const { return is_chunked_; } | 164 bool is_chunked() const { return is_chunked_; } |
| 165 | 165 |
| 166 // Returns the total size in bytes of the data to upload. | 166 // Gets the total size in bytes of the data to upload. Computing the |
| 167 uint64 GetContentLength(); | 167 // content length can result in performing file IO hence the operation is |
| 168 // done asynchronously. Runs the callback with the content length once the |
| 169 // computation is done. |
| 170 typedef base::Callback<void(uint64 content_length)> ContentLengthCallback; |
| 171 void GetContentLength(const ContentLengthCallback& callback); |
| 172 |
| 173 // Returns the total size in bytes of the data to upload, for testing. |
| 174 // This version may perform file IO on the current thread. This function |
| 175 // will fail if called on a thread where file IO is prohibited. Usually |
| 176 // used for testing, but Chrome Frame also uses this version. |
| 177 uint64 GetContentLengthSync(); |
| 168 | 178 |
| 169 // Returns true if the upload data is entirely in memory (i.e. the | 179 // Returns true if the upload data is entirely in memory (i.e. the |
| 170 // upload data is not chunked, and all elemnts are of TYPE_BYTES). | 180 // upload data is not chunked, and all elemnts are of TYPE_BYTES). |
| 171 bool IsInMemory() const; | 181 bool IsInMemory() const; |
| 172 | 182 |
| 173 std::vector<Element>* elements() { | 183 std::vector<Element>* elements() { |
| 174 return &elements_; | 184 return &elements_; |
| 175 } | 185 } |
| 176 | 186 |
| 177 void SetElements(const std::vector<Element>& elements); | 187 void SetElements(const std::vector<Element>& elements); |
| 178 | 188 |
| 179 void swap_elements(std::vector<Element>* elements) { | 189 void swap_elements(std::vector<Element>* elements) { |
| 180 elements_.swap(*elements); | 190 elements_.swap(*elements); |
| 181 } | 191 } |
| 182 | 192 |
| 183 // Identifies a particular upload instance, which is used by the cache to | 193 // Identifies a particular upload instance, which is used by the cache to |
| 184 // formulate a cache key. This value should be unique across browser | 194 // formulate a cache key. This value should be unique across browser |
| 185 // sessions. A value of 0 is used to indicate an unspecified identifier. | 195 // sessions. A value of 0 is used to indicate an unspecified identifier. |
| 186 void set_identifier(int64 id) { identifier_ = id; } | 196 void set_identifier(int64 id) { identifier_ = id; } |
| 187 int64 identifier() const { return identifier_; } | 197 int64 identifier() const { return identifier_; } |
| 188 | 198 |
| 189 private: | 199 private: |
| 200 // Helper function for GetContentLength(). |
| 201 void DoGetContentLength(uint64* content_length); |
| 202 |
| 190 friend class base::RefCounted<UploadData>; | 203 friend class base::RefCounted<UploadData>; |
| 191 | 204 |
| 192 ~UploadData(); | 205 ~UploadData(); |
| 193 | 206 |
| 194 std::vector<Element> elements_; | 207 std::vector<Element> elements_; |
| 195 int64 identifier_; | 208 int64 identifier_; |
| 196 ChunkCallback* chunk_callback_; | 209 ChunkCallback* chunk_callback_; |
| 197 bool is_chunked_; | 210 bool is_chunked_; |
| 198 | 211 |
| 199 DISALLOW_COPY_AND_ASSIGN(UploadData); | 212 DISALLOW_COPY_AND_ASSIGN(UploadData); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 220 | 233 |
| 221 inline bool operator!=(const UploadData::Element& a, | 234 inline bool operator!=(const UploadData::Element& a, |
| 222 const UploadData::Element& b) { | 235 const UploadData::Element& b) { |
| 223 return !(a == b); | 236 return !(a == b); |
| 224 } | 237 } |
| 225 #endif // defined(UNIT_TEST) | 238 #endif // defined(UNIT_TEST) |
| 226 | 239 |
| 227 } // namespace net | 240 } // namespace net |
| 228 | 241 |
| 229 #endif // NET_BASE_UPLOAD_DATA_H_ | 242 #endif // NET_BASE_UPLOAD_DATA_H_ |
| OLD | NEW |