2014-02-05 21:35:45 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#ifndef CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
|
|
|
|
#define CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/upload_element.h"
|
2014-09-04 19:53:40 +02:00
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/supports_user_data.h"
|
|
|
|
#include "net/base/net_export.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
class Time;
|
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// A very concrete class representing the data to be uploaded as part of a
|
|
|
|
// URLRequest.
|
|
|
|
//
|
|
|
|
// Until there is a more abstract class for this, this one derives from
|
|
|
|
// SupportsUserData to allow users to stash random data by
|
|
|
|
// key and ensure its destruction when UploadData is finally deleted.
|
2017-05-17 11:29:28 +02:00
|
|
|
class UploadData : public base::RefCounted<UploadData>,
|
|
|
|
public base::SupportsUserData {
|
2014-02-05 21:35:45 +01:00
|
|
|
public:
|
|
|
|
UploadData();
|
|
|
|
|
|
|
|
void AppendBytes(const char* bytes, int bytes_len);
|
|
|
|
|
|
|
|
void AppendFileRange(const base::FilePath& file_path,
|
2017-05-17 11:29:28 +02:00
|
|
|
uint64_t offset,
|
|
|
|
uint64_t length,
|
2014-02-05 21:35:45 +01:00
|
|
|
const base::Time& expected_modification_time);
|
|
|
|
|
|
|
|
// Initializes the object to send chunks of upload data over time rather
|
|
|
|
// than all at once. Chunked data may only contain bytes, not files.
|
|
|
|
void set_is_chunked(bool set) { is_chunked_ = set; }
|
|
|
|
bool is_chunked() const { return is_chunked_; }
|
|
|
|
|
|
|
|
// set_last_chunk_appended() is only used for serialization.
|
|
|
|
void set_last_chunk_appended(bool set) { last_chunk_appended_ = set; }
|
|
|
|
bool last_chunk_appended() const { return last_chunk_appended_; }
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
using ElementsVector = std::vector<std::unique_ptr<UploadElement>>;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
const ElementsVector& elements() const { return elements_; }
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
ElementsVector* elements_mutable() { return &elements_; }
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void swap_elements(ElementsVector* elements) { elements_.swap(*elements); }
|
2014-02-05 21:35:45 +01:00
|
|
|
|
|
|
|
// Identifies a particular upload instance, which is used by the cache to
|
|
|
|
// formulate a cache key. This value should be unique across browser
|
|
|
|
// sessions. A value of 0 is used to indicate an unspecified identifier.
|
2016-01-06 20:20:54 +01:00
|
|
|
void set_identifier(int64_t id) { identifier_ = id; }
|
|
|
|
int64_t identifier() const { return identifier_; }
|
2014-02-05 21:35:45 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class base::RefCounted<UploadData>;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~UploadData() override;
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
ElementsVector elements_;
|
2016-01-06 20:20:54 +01:00
|
|
|
int64_t identifier_;
|
2014-02-05 21:35:45 +01:00
|
|
|
bool is_chunked_;
|
|
|
|
bool last_chunk_appended_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(UploadData);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#endif // CEF_LIBCEF_COMMON_NET_UPLOAD_DATA_H_
|