OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_UPLOAD_DATA_H_ | |
6 #define NET_BASE_UPLOAD_DATA_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_vector.h" | |
11 #include "base/supports_user_data.h" | |
12 #include "net/base/net_export.h" | |
13 #include "net/base/upload_element.h" | |
14 | |
15 namespace base { | |
16 class FilePath; | |
17 class Time; | |
18 } // namespace base | |
19 | |
20 namespace net { | |
21 | |
22 //----------------------------------------------------------------------------- | |
23 // A very concrete class representing the data to be uploaded as part of a | |
24 // URLRequest. | |
25 // | |
26 // Until there is a more abstract class for this, this one derives from | |
27 // SupportsUserData to allow users to stash random data by | |
28 // key and ensure its destruction when UploadData is finally deleted. | |
29 class NET_EXPORT UploadData | |
30 : public base::RefCounted<UploadData>, | |
31 public base::SupportsUserData { | |
32 public: | |
33 UploadData(); | |
34 | |
35 void AppendBytes(const char* bytes, int bytes_len); | |
36 | |
37 void AppendFileRange(const base::FilePath& file_path, | |
38 uint64 offset, uint64 length, | |
39 const base::Time& expected_modification_time); | |
40 | |
41 // Initializes the object to send chunks of upload data over time rather | |
42 // than all at once. Chunked data may only contain bytes, not files. | |
43 void set_is_chunked(bool set) { is_chunked_ = set; } | |
44 bool is_chunked() const { return is_chunked_; } | |
45 | |
46 // set_last_chunk_appended() is only used for serialization. | |
47 void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; } | |
48 bool last_chunk_appended() const { return last_chunk_appended_; } | |
49 | |
50 const ScopedVector<UploadElement>& elements() const { | |
51 return elements_; | |
52 } | |
53 | |
54 ScopedVector<UploadElement>* elements_mutable() { | |
55 return &elements_; | |
56 } | |
57 | |
58 void swap_elements(ScopedVector<UploadElement>* elements) { | |
59 elements_.swap(*elements); | |
60 } | |
61 | |
62 // Identifies a particular upload instance, which is used by the cache to | |
63 // formulate a cache key. This value should be unique across browser | |
64 // sessions. A value of 0 is used to indicate an unspecified identifier. | |
65 void set_identifier(int64 id) { identifier_ = id; } | |
66 int64 identifier() const { return identifier_; } | |
67 | |
68 private: | |
69 friend class base::RefCounted<UploadData>; | |
70 | |
71 virtual ~UploadData(); | |
72 | |
73 ScopedVector<UploadElement> elements_; | |
74 int64 identifier_; | |
75 bool is_chunked_; | |
76 bool last_chunk_appended_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(UploadData); | |
79 }; | |
80 | |
81 } // namespace net | |
82 | |
83 #endif // NET_BASE_UPLOAD_DATA_H_ | |
OLD | NEW |