Move encrypted media content browser tests into browser tests.
[chromium-blink-merge.git] / net / base / upload_data.h
blobb782ab4e4ded7e87b21e484e111dc2e794f2fbe5
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.
5 #ifndef NET_BASE_UPLOAD_DATA_H_
6 #define NET_BASE_UPLOAD_DATA_H_
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"
15 namespace base {
16 class FilePath;
17 class Time;
18 } // namespace base
20 namespace net {
22 //-----------------------------------------------------------------------------
23 // A very concrete class representing the data to be uploaded as part of a
24 // URLRequest.
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();
35 void AppendBytes(const char* bytes, int bytes_len);
37 void AppendFileRange(const base::FilePath& file_path,
38 uint64 offset, uint64 length,
39 const base::Time& expected_modification_time);
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_; }
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_; }
50 const ScopedVector<UploadElement>& elements() const {
51 return elements_;
54 ScopedVector<UploadElement>* elements_mutable() {
55 return &elements_;
58 void swap_elements(ScopedVector<UploadElement>* elements) {
59 elements_.swap(*elements);
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_; }
68 private:
69 friend class base::RefCounted<UploadData>;
71 virtual ~UploadData();
73 ScopedVector<UploadElement> elements_;
74 int64 identifier_;
75 bool is_chunked_;
76 bool last_chunk_appended_;
78 DISALLOW_COPY_AND_ASSIGN(UploadData);
81 } // namespace net
83 #endif // NET_BASE_UPLOAD_DATA_H_