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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// Copyright 2015 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.
#ifndef COMPONENTS_CRONET_ANDROID_CRONET_DATA_REDUCTION_PROXY_H_
#define COMPONENTS_CRONET_ANDROID_CRONET_DATA_REDUCTION_PROXY_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
class PrefService;
namespace base {
class SingleThreadTaskRunner;
}
namespace data_reduction_proxy {
class DataReductionProxyIOData;
class DataReductionProxySettings;
}
namespace net {
class NetLog;
class NetworkDelegate;
class ProxyDelegate;
class URLRequestContext;
class URLRequestContextGetter;
class URLRequestInterceptor;
}
namespace cronet {
// Wrapper and configurator of Data Reduction Proxy objects for Cronet. It
// configures the Data Reduction Proxy to run both its UI and IO classes on
// Cronet's network thread.
class CronetDataReductionProxy {
public:
// Construct Data Reduction Proxy Settings and IOData objects and set
// the authentication key. The |task_runner| should be suitable for running
// tasks on the network thread. The primary proxy, fallback proxy, and secure
// proxy check url can override defaults. All or none must be specified.
CronetDataReductionProxy(
const std::string& key,
const std::string& primary_proxy,
const std::string& fallback_proxy,
const std::string& secure_proxy_check_url,
const std::string& user_agent,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
net::NetLog* net_log);
~CronetDataReductionProxy();
// Constructs a network delegate suitable for adding Data Reduction Proxy
// request headers.
std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate(
std::unique_ptr<net::NetworkDelegate> wrapped_network_delegate);
// Constructs a proxy delegate suitable for adding Data Reduction Proxy
// proxy resolution.
std::unique_ptr<net::ProxyDelegate> CreateProxyDelegate();
// Constructs a URLRequestInterceptor suitable for carrying out the Data
// Reduction Proxy's bypass protocol.
std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor();
// Constructs a bridge between the Settings and IOData objects, sets up a
// context for secure proxy check requests, and enables the proxy, if
// |enable| is true.
void Init(bool enable, net::URLRequestContext* context);
private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
std::unique_ptr<PrefService> prefs_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
std::unique_ptr<data_reduction_proxy::DataReductionProxySettings> settings_;
std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> io_data_;
DISALLOW_COPY_AND_ASSIGN(CronetDataReductionProxy);
};
} // namespace cronet
#endif // COMPONENTS_CRONET_ANDROID_CRONET_DATA_REDUCTION_PROXY_H_
|