• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
6 #define CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "libcef/common/net/upload_element.h"
14 
15 #include "base/memory/ref_counted.h"
16 #include "base/supports_user_data.h"
17 #include "net/base/net_export.h"
18 
19 namespace base {
20 class FilePath;
21 class Time;
22 }  // namespace base
23 
24 namespace net {
25 
26 //-----------------------------------------------------------------------------
27 // A very concrete class representing the data to be uploaded as part of a
28 // URLRequest.
29 //
30 // Until there is a more abstract class for this, this one derives from
31 // SupportsUserData to allow users to stash random data by
32 // key and ensure its destruction when UploadData is finally deleted.
33 class UploadData : public base::RefCounted<UploadData>,
34                    public base::SupportsUserData {
35  public:
36   UploadData();
37 
38   void AppendBytes(const char* bytes, int bytes_len);
39 
40   void AppendFileRange(const base::FilePath& file_path,
41                        uint64_t offset,
42                        uint64_t length,
43                        const base::Time& expected_modification_time);
44 
45   // Initializes the object to send chunks of upload data over time rather
46   // than all at once. Chunked data may only contain bytes, not files.
set_is_chunked(bool set)47   void set_is_chunked(bool set) { is_chunked_ = set; }
is_chunked()48   bool is_chunked() const { return is_chunked_; }
49 
50   // set_last_chunk_appended() is only used for serialization.
set_last_chunk_appended(bool set)51   void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; }
last_chunk_appended()52   bool last_chunk_appended() const { return last_chunk_appended_; }
53 
54   using ElementsVector = std::vector<std::unique_ptr<UploadElement>>;
55 
elements()56   const ElementsVector& elements() const { return elements_; }
57 
elements_mutable()58   ElementsVector* elements_mutable() { return &elements_; }
59 
swap_elements(ElementsVector * elements)60   void swap_elements(ElementsVector* elements) { elements_.swap(*elements); }
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.
set_identifier(int64_t id)65   void set_identifier(int64_t id) { identifier_ = id; }
identifier()66   int64_t identifier() const { return identifier_; }
67 
68  private:
69   friend class base::RefCounted<UploadData>;
70 
71   ~UploadData() override;
72 
73   ElementsVector elements_;
74   int64_t 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  // CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
84