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

Unified Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc

Issue 775773002: Add data reduction proxy debug info to net-internals#bandwidth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/common/data_reduction_proxy_event_store.cc
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
index 3e164a67a1b547690c340039ed6139b151922fc4..1d1cc72afadbe0dad885b119c346bc4f74bb54b8 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
@@ -12,7 +12,9 @@
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
+#include "net/base/host_port_pair.h"
#include "net/base/net_log.h"
+#include "url/gurl.h"
namespace {
@@ -32,10 +34,30 @@ scoped_ptr<base::Value> BuildDataReductionProxyEvent(
return entry_value;
}
-std::string GetExpirationTicks(int bypass_seconds) {
+int64 GetExpirationTicks(int bypass_seconds) {
base::TimeTicks ticks_now = base::TimeTicks::Now();
- return net::NetLog::TickCountToString(
- ticks_now + base::TimeDelta::FromSeconds(bypass_seconds));
+ base::TimeTicks expiration_ticks = ticks_now +
+ base::TimeDelta::FromSeconds(bypass_seconds);
+ return (expiration_ticks - base::TimeTicks()).InMilliseconds();
+}
+
+// Builds a string which resembles ProxyServer::ToURI()
+std::string GetNormalizedProxyString(const std::string& proxy_origin) {
+ GURL proxy_url(proxy_origin);
+ if (proxy_url.is_valid())
+ {
mmenke 2014/12/09 21:58:53 if (...) {
jeremyim 2014/12/09 23:14:28 Done.
+ net::HostPortPair proxy_host_port_pair =
+ net::HostPortPair::FromURL(proxy_url);
+ if (proxy_url.SchemeIs(url::kHttpScheme))
+ return proxy_host_port_pair.ToString();
+
+ return std::string(proxy_url.scheme()) + url::kStandardSchemeSeparator +
+ proxy_host_port_pair.ToString();
+ }
+ else
+ {
mmenke 2014/12/09 21:58:53 } else {
jeremyim 2014/12/09 23:14:28 Done.
+ return std::string();
+ }
}
// The following callbacks create a base::Value which contains information
@@ -52,9 +74,9 @@ base::Value* EnableDataReductionProxyCallback(
dict->SetBoolean("enabled", true);
dict->SetBoolean("primary_restricted", primary_restricted);
dict->SetBoolean("fallback_restricted", fallback_restricted);
- dict->SetString("primary_origin", primary_origin);
- dict->SetString("fallback_origin", fallback_origin);
- dict->SetString("ssl_origin", ssl_origin);
+ dict->SetString("primary_origin", GetNormalizedProxyString(primary_origin));
+ dict->SetString("fallback_origin", GetNormalizedProxyString(fallback_origin));
+ dict->SetString("ssl_origin", GetNormalizedProxyString(ssl_origin));
return dict;
}
@@ -67,30 +89,30 @@ base::Value* DisableDataReductionProxyCallback(
base::Value* UrlBypassActionCallback(const std::string& action,
const GURL& url,
- const base::TimeDelta& bypass_duration,
+ int bypass_seconds,
+ int64 expiration_ticks,
net::NetLog::LogLevel /* log_level */) {
base::DictionaryValue* dict = new base::DictionaryValue();
- int bypass_seconds = bypass_duration.InSeconds();
dict->SetString("action", action);
dict->SetString("url", url.spec());
dict->SetString("bypass_duration_seconds",
base::Int64ToString(bypass_seconds));
- dict->SetString("expiration", GetExpirationTicks(bypass_seconds));
+ dict->SetString("expiration", base::Int64ToString(expiration_ticks));
return dict;
}
base::Value* UrlBypassTypeCallback(
data_reduction_proxy::DataReductionProxyBypassType bypass_type,
const GURL& url,
- const base::TimeDelta& bypass_duration,
+ int bypass_seconds,
+ int64 expiration_ticks,
net::NetLog::LogLevel /* log_level */) {
base::DictionaryValue* dict = new base::DictionaryValue();
- int bypass_seconds = bypass_duration.InSeconds();
dict->SetInteger("bypass_type", bypass_type);
dict->SetString("url", url.spec());
dict->SetString("bypass_duration_seconds",
base::Int64ToString(bypass_seconds));
- dict->SetString("expiration", GetExpirationTicks(bypass_seconds));
+ dict->SetString("expiration", base::Int64ToString(expiration_ticks));
return dict;
}
@@ -99,9 +121,11 @@ base::Value* UrlBypassTypeCallback(
namespace data_reduction_proxy {
DataReductionProxyEventStore::DataReductionProxyEventStore(
- const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner)
- : network_task_runner_(network_task_runner) {
-}
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
+ : ui_task_runner_(ui_task_runner),
+ enabled_(false),
+ canary_state_(CANARY_UNKNOWN),
+ expiration_ticks_(0) { }
DataReductionProxyEventStore::~DataReductionProxyEventStore() {
STLDeleteElements(&stored_events_);
@@ -119,18 +143,20 @@ void DataReductionProxyEventStore::AddProxyEnabledEvent(
base::Bind(&EnableDataReductionProxyCallback, primary_restricted,
fallback_restricted, primary_origin, fallback_origin,
ssl_origin);
- PostGlobalNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED,
- parameters_callback);
+ PostEnabledEvent(net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED,
+ true,
+ parameters_callback);
}
void DataReductionProxyEventStore::AddProxyDisabledEvent(
net::NetLog* net_log) {
const net::NetLog::ParametersCallback& parameters_callback =
base::Bind(&DisableDataReductionProxyCallback);
- PostGlobalNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED,
- parameters_callback);
+ PostEnabledEvent(net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_ENABLED,
+ false,
+ parameters_callback);
}
void DataReductionProxyEventStore::AddBypassActionEvent(
@@ -138,12 +164,17 @@ void DataReductionProxyEventStore::AddBypassActionEvent(
const std::string& bypass_action,
const GURL& url,
const base::TimeDelta& bypass_duration) {
+ int bypass_seconds = bypass_duration.InSeconds();
+ int64 expiration_ticks = GetExpirationTicks(bypass_seconds);
const net::NetLog::ParametersCallback& parameters_callback =
- base::Bind(&UrlBypassActionCallback, bypass_action, url, bypass_duration);
- PostBoundNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED,
- net::NetLog::PHASE_NONE,
- parameters_callback);
+ base::Bind(&UrlBypassActionCallback, bypass_action, url, bypass_seconds,
+ expiration_ticks);
+ PostBoundNetLogBypassEvent(
+ net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED,
+ net::NetLog::PHASE_NONE,
+ expiration_ticks,
+ parameters_callback);
}
void DataReductionProxyEventStore::AddBypassTypeEvent(
@@ -151,12 +182,17 @@ void DataReductionProxyEventStore::AddBypassTypeEvent(
DataReductionProxyBypassType bypass_type,
const GURL& url,
const base::TimeDelta& bypass_duration) {
+ int bypass_seconds = bypass_duration.InSeconds();
+ int64 expiration_ticks = GetExpirationTicks(bypass_seconds);
const net::NetLog::ParametersCallback& parameters_callback =
- base::Bind(&UrlBypassTypeCallback, bypass_type, url, bypass_duration);
- PostBoundNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED,
- net::NetLog::PHASE_NONE,
- parameters_callback);
+ base::Bind(&UrlBypassTypeCallback, bypass_type, url, bypass_seconds,
+ expiration_ticks);
+ PostBoundNetLogBypassEvent(
+ net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_BYPASS_REQUESTED,
+ net::NetLog::PHASE_NONE,
+ expiration_ticks,
+ parameters_callback);
}
void DataReductionProxyEventStore::BeginCanaryRequest(
@@ -165,10 +201,12 @@ void DataReductionProxyEventStore::BeginCanaryRequest(
// This callback must be invoked synchronously
const net::NetLog::ParametersCallback& parameters_callback =
net::NetLog::StringCallback("url", &url.spec());
- PostBoundNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST,
- net::NetLog::PHASE_BEGIN,
- parameters_callback);
+ PostBoundNetLogCanaryEvent(
+ net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST,
+ net::NetLog::PHASE_BEGIN,
+ CANARY_PENDING,
+ parameters_callback);
}
void DataReductionProxyEventStore::EndCanaryRequest(
@@ -176,51 +214,130 @@ void DataReductionProxyEventStore::EndCanaryRequest(
int net_error) {
const net::NetLog::ParametersCallback& parameters_callback =
net::NetLog::IntegerCallback("net_error", net_error);
- PostBoundNetLogEvent(net_log,
- net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST,
- net::NetLog::PHASE_END,
- parameters_callback);
+ PostBoundNetLogCanaryEvent(
+ net_log,
+ net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST,
+ net::NetLog::PHASE_END,
+ net_error == 0 ? CANARY_SUCCESS : CANARY_FAILED,
+ parameters_callback);
}
-void DataReductionProxyEventStore::PostGlobalNetLogEvent(
+void DataReductionProxyEventStore::PostEnabledEvent(
net::NetLog* net_log,
net::NetLog::EventType type,
+ bool enabled,
const net::NetLog::ParametersCallback& callback) {
scoped_ptr<base::Value> event = BuildDataReductionProxyEvent(
type, net::NetLog::Source(), net::NetLog::PHASE_NONE, callback);
if (event.get()) {
- network_task_runner_->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&DataReductionProxyEventStore::AddEventOnIOThread,
+ base::Bind(&DataReductionProxyEventStore::AddEnabledEventOnUIThread,
base::Unretained(this),
- base::Passed(&event)));
+ base::Passed(&event),
+ enabled));
}
if (net_log)
net_log->AddGlobalEntry(type, callback);
}
-void DataReductionProxyEventStore::PostBoundNetLogEvent(
+void DataReductionProxyEventStore::PostBoundNetLogBypassEvent(
const net::BoundNetLog& net_log,
net::NetLog::EventType type,
net::NetLog::EventPhase phase,
+ int64 expiration_ticks,
const net::NetLog::ParametersCallback& callback) {
scoped_ptr<base::Value> event = BuildDataReductionProxyEvent(
type, net_log.source(), phase, callback);
if (event.get()) {
- network_task_runner_->PostTask(
+ ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&DataReductionProxyEventStore::AddEventOnIOThread,
- base::Unretained(this),
- base::Passed(&event)));
+ base::Bind(
+ &DataReductionProxyEventStore::AddAndSetLastBypassEventOnUIThread,
+ base::Unretained(this),
+ base::Passed(&event),
+ expiration_ticks));
}
net_log.AddEntry(type, phase, callback);
}
-void DataReductionProxyEventStore::AddEventOnIOThread(
+void DataReductionProxyEventStore::PostBoundNetLogCanaryEvent(
+ const net::BoundNetLog& net_log,
+ net::NetLog::EventType type,
+ net::NetLog::EventPhase phase,
+ DataReductionProxyCanaryState state,
+ const net::NetLog::ParametersCallback& callback) {
+ scoped_ptr<base::Value> event =
+ BuildDataReductionProxyEvent(type, net_log.source(), phase, callback);
+ if (event.get()) {
+ ui_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &DataReductionProxyEventStore::AddEventAndCanaryStateOnUIThread,
+ base::Unretained(this),
+ base::Passed(&event),
+ state));
+ }
+
+ net_log.AddEntry(type, phase, callback);
+}
+
+base::Value* DataReductionProxyEventStore::GetSummaryValue () const {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+
+ base::DictionaryValue* data_reduction_proxy_values =
+ new base::DictionaryValue();
+ data_reduction_proxy_values->SetBoolean("enabled", enabled_);
+
+ base::Value* current_configuration = current_configuration_.get();
+ if (current_configuration != nullptr) {
+ data_reduction_proxy_values->Set("proxy_config",
+ current_configuration->DeepCopy());
+ }
+
+ switch (canary_state_) {
+ case CANARY_PENDING:
+ data_reduction_proxy_values->SetString("canary", "Pending");
+ break;
+ case CANARY_SUCCESS:
+ data_reduction_proxy_values->SetString("canary", "Success");
+ break;
+ case CANARY_FAILED:
+ data_reduction_proxy_values->SetString("canary", "Failed");
+ break;
+ case CANARY_UNKNOWN:
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ base::Value* last_bypass_event = last_bypass_event_.get();
+ if (last_bypass_event != nullptr) {
+ int current_time_ticks_ms =
+ (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
+ if (expiration_ticks_ > current_time_ticks_ms) {
+ data_reduction_proxy_values->Set("last_bypass",
+ last_bypass_event->DeepCopy());
+ }
+ }
+
+ base::ListValue* eventsList = new base::ListValue();
+ for (size_t i = 0; i < stored_events_.size(); i++) {
+ base::Value* event = stored_events_[i];
+ eventsList->Append(event->DeepCopy());
+ }
+
+ data_reduction_proxy_values->Set("events", eventsList);
+
+ return data_reduction_proxy_values;
+}
+
+void DataReductionProxyEventStore::AddEventOnUIThread(
scoped_ptr<base::Value> entry) {
- DCHECK(network_task_runner_->BelongsToCurrentThread());
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
if (stored_events_.size() == kMaxEventsToStore) {
base::Value* head = stored_events_.front();
stored_events_.pop_front();
@@ -230,4 +347,33 @@ void DataReductionProxyEventStore::AddEventOnIOThread(
stored_events_.push_back(entry.release());
}
+void DataReductionProxyEventStore::AddEnabledEventOnUIThread(
+ scoped_ptr<base::Value> entry,
+ bool enabled) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ enabled_ = enabled;
+ if (enabled)
+ current_configuration_.reset(entry->DeepCopy());
+ else
+ current_configuration_.reset();
+ AddEventOnUIThread(entry.Pass());
+}
+
+void DataReductionProxyEventStore::AddEventAndCanaryStateOnUIThread(
+ scoped_ptr<base::Value> entry,
+ DataReductionProxyCanaryState state) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ canary_state_ = state;
+ AddEventOnUIThread(entry.Pass());
+}
+
+void DataReductionProxyEventStore::AddAndSetLastBypassEventOnUIThread(
+ scoped_ptr<base::Value> entry,
+ int64 expiration_ticks) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ last_bypass_event_.reset(entry->DeepCopy());
+ expiration_ticks_ = expiration_ticks;
+ AddEventOnUIThread(entry.Pass());
+}
+
} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698