url_request_proxy.h
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef ETRADECLIENT_BROWSER_URL_REQUEST_PROXY_H_INCLUDED
#define ETRADECLIENT_BROWSER_URL_REQUEST_PROXY_H_INCLUDED
#include <mutex>
#include <condition_variable>
#include <string>
#include <memory>
#include "include/internal/cef_ptr.h"
#include "include/cef_urlrequest.h"
class URLRequest; // Forward declaration.
class URLRequestProxy
{
class URLRequestProxyImpl : public CefBaseRefCounted
{
public:
URLRequestProxyImpl::URLRequestProxyImpl(std::mutex& mtx, std::condition_variable& cv);
void Get(const std::string& request_url, int flags);
void Post(const std::string& request_url, const std::string& request_param, int flags);
void Cancel();
bool GotResponse() const;
bool Result() const;
const std::string& ResponseString() const;
private:
void SendRequest(CefRefPtr<CefRequest> request);
void HandleResponse(CefURLRequest::ErrorCode error_code, const std::string& response_str);
private:
std::unique_ptr<URLRequest> m_url_request;
std::mutex& m_mtx;
std::condition_variable& m_cv;
bool m_req_sent;
bool m_res;
std::string m_response_str; // Result string of request.
IMPLEMENT_REFCOUNTING(URLRequestProxyImpl);
DISALLOW_COPY_AND_ASSIGN(URLRequestProxyImpl);
};
public:
URLRequestProxy();
bool Get(const std::string& request_url, int flags);
bool Post(const std::string& request_url, const std::string& request_param, int flags);
const std::string& ResponseString() const;
private:
std::mutex m_mtx;
std::condition_variable m_cv;
CefRefPtr<URLRequestProxyImpl> m_pimpl;
};
#endif // ETRADECLIENT_BROWSER_URL_REQUEST_PROXY_H_INCLUDED