Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / domain_reliability / util.cc
index 25d5c72..6fc50c5 100644 (file)
@@ -7,7 +7,6 @@
 #include "base/callback.h"
 #include "base/logging.h"
 #include "base/memory/weak_ptr.h"
-#include "base/strings/stringprintf.h"
 #include "base/time/time.h"
 #include "base/timer/timer.h"
 #include "net/base/net_errors.h"
@@ -21,22 +20,18 @@ class ActualTimer : public MockableTime::Timer {
   // Initialize base timer with retain_user_info and is_repeating false.
   ActualTimer() : base_timer_(false, false) {}
 
-  virtual ~ActualTimer() {}
+  ~ActualTimer() override {}
 
   // MockableTime::Timer implementation:
-  virtual void Start(const tracked_objects::Location& posted_from,
-                     base::TimeDelta delay,
-                     const base::Closure& user_task) OVERRIDE {
+  void Start(const tracked_objects::Location& posted_from,
+             base::TimeDelta delay,
+             const base::Closure& user_task) override {
     base_timer_.Start(posted_from, delay, user_task);
   }
 
-  virtual void Stop() OVERRIDE {
-    base_timer_.Stop();
-  }
+  void Stop() override { base_timer_.Stop(); }
 
-  virtual bool IsRunning() OVERRIDE {
-    return base_timer_.IsRunning();
-  }
+  bool IsRunning() override { return base_timer_.IsRunning(); }
 
  private:
   base::Timer base_timer_;
@@ -47,6 +42,7 @@ const struct NetErrorMapping {
   const char* beacon_status;
 } net_error_map[] = {
   { net::OK, "ok" },
+  { net::ERR_ABORTED, "aborted" },
   { net::ERR_TIMED_OUT, "tcp.connection.timed_out" },
   { net::ERR_CONNECTION_CLOSED, "tcp.connection.closed" },
   { net::ERR_CONNECTION_RESET, "tcp.connection.reset" },
@@ -84,7 +80,7 @@ bool GetDomainReliabilityBeaconStatus(
     std::string* beacon_status_out) {
   if (net_error == net::OK) {
     if (http_response_code >= 400 && http_response_code < 600)
-      *beacon_status_out = base::StringPrintf("http.%d", http_response_code);
+      *beacon_status_out = "http.error";
     else
       *beacon_status_out = "ok";
     return true;
@@ -100,6 +96,30 @@ bool GetDomainReliabilityBeaconStatus(
   return false;
 }
 
+// TODO(ttuttle): Consider using NPN/ALPN instead, if there's a good way to
+//                differentiate HTTP and HTTPS.
+std::string GetDomainReliabilityProtocol(
+    net::HttpResponseInfo::ConnectionInfo connection_info,
+    bool ssl_info_populated) {
+  switch (connection_info) {
+    case net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN:
+      return "";
+    case net::HttpResponseInfo::CONNECTION_INFO_HTTP1:
+      return ssl_info_populated ? "HTTPS" : "HTTP";
+    case net::HttpResponseInfo::CONNECTION_INFO_DEPRECATED_SPDY2:
+    case net::HttpResponseInfo::CONNECTION_INFO_SPDY3:
+    case net::HttpResponseInfo::CONNECTION_INFO_SPDY4:
+      return "SPDY";
+    case net::HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3:
+      return "QUIC";
+    case net::HttpResponseInfo::NUM_OF_CONNECTION_INFOS:
+      NOTREACHED();
+      return "";
+  }
+  NOTREACHED();
+  return "";
+}
+
 MockableTime::Timer::~Timer() {}
 MockableTime::Timer::Timer() {}
 
@@ -116,4 +136,17 @@ scoped_ptr<MockableTime::Timer> ActualTime::CreateTimer() {
   return scoped_ptr<MockableTime::Timer>(new ActualTimer());
 }
 
+MockableTimeBackoffEntry::MockableTimeBackoffEntry(
+    const net::BackoffEntry::Policy* const policy,
+    MockableTime* time)
+    : net::BackoffEntry(policy),
+      time_(time) {
+}
+
+MockableTimeBackoffEntry::~MockableTimeBackoffEntry() {}
+
+base::TimeTicks MockableTimeBackoffEntry::ImplGetTimeNow() const {
+  return time_->NowTicks();
+}
+
 }  // namespace domain_reliability