electron/atom/browser/net/url_request_stream_job.h
Charles Kerr d663b4eaee
fix: fix gn cpplint warnings (#14583)
* chore: fix cpplint 'include_what_you_use' warnings

Typically by including <memory>, <utility> etc.

* chore: fix 'static/global string constant' warning

Use C style strings instead of std::string.

Style guide forbids non-trivial static / global variables. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

/home/charles/electron/electron-gn/src/electron/script/cpplint.js

* refactor: remove global string variables.

Fix 'global string variables are not permitted' linter warnings
by using the base::NoDestructor<> wrapper to make it explicit that
these variables are never destroyed.

The style guide's take on globals with nontrivial destructors:
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

* fix: initializer error introduced in last commit

* fix: remove WIP file that was included by accident

* fix: include order

* fix: include order

* fix: include order

* fix: include order, again
2018-09-12 19:25:56 -05:00

68 lines
2.3 KiB
C++

// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_NET_URL_REQUEST_STREAM_JOB_H_
#define ATOM_BROWSER_NET_URL_REQUEST_STREAM_JOB_H_
#include <deque>
#include <memory>
#include <string>
#include "atom/browser/api/event_subscriber.h"
#include "atom/browser/net/js_asker.h"
#include "base/memory/ref_counted_memory.h"
#include "native_mate/persistent_dictionary.h"
#include "net/base/io_buffer.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_context_getter.h"
#include "v8/include/v8.h"
namespace atom {
class URLRequestStreamJob : public JsAsker<net::URLRequestJob> {
public:
URLRequestStreamJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate);
~URLRequestStreamJob() override;
void OnData(mate::Arguments* args);
void OnEnd(mate::Arguments* args);
void OnError(mate::Arguments* args);
// URLRequestJob
void GetResponseInfo(net::HttpResponseInfo* info) override;
protected:
// URLRequestJob
int ReadRawData(net::IOBuffer* buf, int buf_size) override;
void DoneReading() override;
void DoneReadingRedirectResponse() override;
std::unique_ptr<net::SourceStream> SetUpSourceStream() override;
bool GetMimeType(std::string* mime_type) const override;
int GetResponseCode() const override;
private:
// JSAsker
void BeforeStartInUI(v8::Isolate*, v8::Local<v8::Value>) override;
void StartAsync(std::unique_ptr<base::Value> options) override;
void OnResponse(bool success, std::unique_ptr<base::Value> value);
// Callback after data is asynchronously read from the file into |buf|.
void CopyMoreData(scoped_refptr<net::IOBuffer> io_buf, int io_buf_size);
void CopyMoreDataDone(scoped_refptr<net::IOBuffer> io_buf, int read_count);
std::deque<char> buffer_;
bool ended_ = false;
bool errored_ = false;
scoped_refptr<net::IOBuffer> pending_io_buf_;
int pending_io_buf_size_ = 0;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
mate::EventSubscriber<URLRequestStreamJob>::SafePtr subscriber_;
base::WeakPtrFactory<URLRequestStreamJob> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestStreamJob);
};
} // namespace atom
#endif // ATOM_BROWSER_NET_URL_REQUEST_STREAM_JOB_H_