electron/atom/browser/net/atom_url_request.h

95 lines
3.1 KiB
C
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_
#define ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_
#include "base/memory/ref_counted.h"
#include "net/url_request/url_request.h"
2016-09-26 12:03:49 +00:00
#include "net/base/chunked_upload_data_stream.h"
namespace net {
class IOBuffer;
class IOBufferWithSize;
class DrainableIOBuffer;
2016-09-26 12:03:49 +00:00
};
namespace atom {
class AtomBrowserContext;
namespace api {
2016-09-26 12:03:49 +00:00
class URLRequest;
}
class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>,
public net::URLRequest::Delegate {
public:
2016-09-21 15:35:03 +00:00
static scoped_refptr<AtomURLRequest> Create(
AtomBrowserContext* browser_context,
2016-09-21 15:35:03 +00:00
const std::string& method,
const std::string& url,
base::WeakPtr<api::URLRequest> delegate);
bool Write(scoped_refptr<const net::IOBufferWithSize> buffer,
2016-09-26 12:59:53 +00:00
bool is_last);
void SetChunkedUpload(bool is_chunked_upload);
2016-09-21 15:35:03 +00:00
void Abort() const;
void SetExtraHeader(const std::string& name, const std::string& value) const;
void RemoveExtraHeader(const std::string& name) const;
2016-09-21 15:35:03 +00:00
void PassLoginInformation(const base::string16& username,
const base::string16& password) const;
scoped_refptr<const net::HttpResponseHeaders> GetResponseHeaders() const;
protected:
// Overrides of net::URLRequest::Delegate
2016-09-21 15:35:03 +00:00
virtual void OnAuthRequired(net::URLRequest* request,
net::AuthChallengeInfo* auth_info) override;
virtual void OnResponseStarted(net::URLRequest* request) override;
2016-09-21 15:35:03 +00:00
virtual void OnReadCompleted(net::URLRequest* request,
int bytes_read) override;
private:
friend class base::RefCountedThreadSafe<AtomURLRequest>;
2016-09-26 12:59:53 +00:00
void DoWriteBuffer(scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last);
void DoAbort() const;
2016-09-21 15:35:03 +00:00
void DoSetAuth(const base::string16& username,
const base::string16& password) const;
void DoCancelAuth() const;
void ReadResponse();
bool CopyAndPostBuffer(int bytes_read);
2016-09-21 15:35:03 +00:00
void InformDelegateAuthenticationRequired(
scoped_refptr<net::AuthChallengeInfo> auth_info) const;
void InformDelegateResponseStarted() const;
void InformDelegateResponseData(
scoped_refptr<net::IOBufferWithSize> data) const;
void InformDelegateResponseCompleted() const;
void InformDelegateErrorOccured(const std::string& error) const;
AtomURLRequest(base::WeakPtr<api::URLRequest> delegate);
virtual ~AtomURLRequest();
base::WeakPtr<api::URLRequest> delegate_;
2016-09-21 15:35:03 +00:00
std::unique_ptr<net::URLRequest> request_;
2016-09-26 12:03:49 +00:00
bool is_chunked_upload_;
std::unique_ptr<net::ChunkedUploadDataStream> chunked_stream_;
std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_stream_writer_;
std::vector<std::unique_ptr<net::UploadElementReader>>upload_element_readers_;
scoped_refptr<net::IOBuffer> response_read_buffer_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
DISALLOW_COPY_AND_ASSIGN(AtomURLRequest);
};
} // namespace atom
#endif // ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_