Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc

Issue 1024553009: Add the ability to use DataReductionProxyParams from DataReductionProxyConfigServiceClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client_control_local
Patch Set: Forgot implementation of DataReductionProxyMutableConfigValues::IsDataReductionProxy in downstream … Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
index 39a9481bc782694f431a6400fc82c34519b5d0f1..77a058ab643325d9da0d593f1249cc2619552873 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
@@ -4,27 +4,159 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h"
+#include <vector>
sclittle 2015/03/24 21:34:55 also include string
jeremyim 2015/03/24 23:20:28 Done.
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/json/json_writer.h"
+#include "base/location.h"
#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
+#include "base/time/time.h"
#include "base/values.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/proto/client_config.pb.h"
+#include "net/base/host_port_pair.h"
+#include "net/proxy/proxy_server.h"
namespace data_reduction_proxy {
+namespace {
+
+const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
bengr 2015/03/24 21:37:41 Add a comment. Does this mean if you can't fetch a
jeremyim 2015/03/24 23:20:28 Done. maximum_backoff_ms is the maximum permitted
+ // num_errors_to_ignore
bengr 2015/03/24 21:37:40 Might be more readable if you put the comments to
jeremyim 2015/03/24 23:20:28 Done.
+ 0,
+ // initial_delay_ms
+ 10 * 1000,
+ // multiply_factor
+ 2,
+ // jitter_factor,
+ 0.10,
+ // maximum_backoff_ms
+ 30 * 60 * 1000,
+ // entry_lifetime_ms
+ -1,
+ // always_use_initial_delay
+ true,
+};
+
+} // namespace
+
+const net::BackoffEntry::Policy& GetBackoffPolicy() {
+ return kDefaultBackoffPolicy;
+}
+
DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
- DataReductionProxyParams* params,
- DataReductionProxyRequestOptions* request_options)
- : params_(params),
- request_options_(request_options) {
- DCHECK(params);
+ scoped_ptr<DataReductionProxyParams> params,
+ const net::BackoffEntry::Policy& backoff_policy,
+ DataReductionProxyRequestOptions* request_options,
+ DataReductionProxyMutableConfigValues* config_values,
+ DataReductionProxyConfig* config,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ : params_(params.Pass()),
+ request_options_(request_options),
+ config_values_(config_values),
+ config_(config),
+ io_task_runner_(io_task_runner),
+ backoff_entry_(&backoff_policy) {
DCHECK(request_options);
+ DCHECK(config_values);
+ DCHECK(config);
+ DCHECK(io_task_runner.get());
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&DataReductionProxyConfigServiceClient::RetrieveConfig,
+ base::Unretained(this)));
}
DataReductionProxyConfigServiceClient::
~DataReductionProxyConfigServiceClient() {
}
+void DataReductionProxyConfigServiceClient::RetrieveConfig() {
bengr 2015/03/24 21:37:40 I'd expect RetrieveConfig to be asynchronous, or p
jeremyim 2015/03/24 23:20:27 Acknowledged. This makes more sense in the next C
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+
+ std::string static_response = ConstructStaticResponse();
+ ClientConfig config;
+ bool succeeded = false;
+ if (config_parser::ParseClientConfig(static_response, &config)) {
+ if (config.has_proxy_config()) {
+ net::ProxyServer origin;
+ net::ProxyServer fallback_origin;
+ if (config.proxy_config().http_proxy_servers_size() > 0) {
bengr 2015/03/24 21:37:41 You could probably factor out the stuff that deter
jeremyim 2015/03/24 23:20:28 Done.
+ const ProxyServer& server = config.proxy_config().http_proxy_servers(0);
+ if (server.scheme() != ProxyServer_ProxyScheme_UNSPECIFIED) {
+ origin = net::ProxyServer(
+ config_parser::SchemeFromProxyScheme(server.scheme()),
+ net::HostPortPair(server.host(), server.port()));
+ }
+
+ if (config.proxy_config().http_proxy_servers_size() > 1) {
+ const ProxyServer& fallback =
sclittle 2015/03/24 21:34:55 It's confusing to have both ProxyServer and net::P
jeremyim 2015/03/24 23:20:28 Done.
+ config.proxy_config().http_proxy_servers(1);
+ if (fallback.scheme() != ProxyServer_ProxyScheme_UNSPECIFIED) {
+ fallback_origin = net::ProxyServer(
+ config_parser::SchemeFromProxyScheme(fallback.scheme()),
+ net::HostPortPair(fallback.host(), fallback.port()));
+ }
+ }
+
+ std::string session;
+ std::string credentials;
+ if (DataReductionProxyRequestOptions::ParseLocalSessionKey(
+ config.session_key(), &session, &credentials)) {
+ request_options_->SetCredentials(session, credentials);
+ config_values_->UpdateValues(origin, fallback_origin);
+ config_->ReloadConfig();
+ succeeded = true;
+ }
+ }
+ }
+ }
+
+ base::TimeDelta next_config_refresh_time;
+ if (succeeded) {
+ GetBackoffEntry()->InformOfRequest(true);
+ base::TimeDelta minimum_refresh_time =
+ GetBackoffEntry()->GetTimeUntilRelease();
+ base::Time expiration_time =
+ config_parser::TimestampToTime(config.expire_time());
+ next_config_refresh_time = (expiration_time - Now());
+ if (next_config_refresh_time < minimum_refresh_time)
+ next_config_refresh_time = minimum_refresh_time;
+ } else {
+ GetBackoffEntry()->InformOfRequest(false);
+ next_config_refresh_time = GetBackoffEntry()->GetTimeUntilRelease();
+ }
+
+ SetConfigRefreshTimer(next_config_refresh_time);
bengr 2015/03/24 21:37:41 Perhaps factor out everything that determines next
jeremyim 2015/03/24 23:20:28 Done.
+}
+
+const net::BackoffEntry*
+DataReductionProxyConfigServiceClient::GetBackoffEntry() const {
+ return &backoff_entry_;
+}
+
+net::BackoffEntry* DataReductionProxyConfigServiceClient::GetBackoffEntry() {
+ return &backoff_entry_;
+}
+
+void DataReductionProxyConfigServiceClient::SetConfigRefreshTimer(
+ const base::TimeDelta& delay) {
+ config_refresh_timer_.Stop();
+ config_refresh_timer_.Start(
+ FROM_HERE, delay, this,
+ &DataReductionProxyConfigServiceClient::RetrieveConfig);
+}
+
+base::Time DataReductionProxyConfigServiceClient::Now() const {
+ return base::Time::Now();
+}
+
std::string
DataReductionProxyConfigServiceClient::ConstructStaticResponse() const {
std::string response;

Powered by Google App Engine
This is Rietveld 408576698