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

Unified Diff: net/http/http_server_properties.cc

Issue 2932953002: Persist broken and recently-broken alt-svcs to prefs in HttpServerPropertiesManager (Closed)
Patch Set: Added a DCHECK Created 3 years, 6 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: net/http/http_server_properties.cc
diff --git a/net/http/http_server_properties.cc b/net/http/http_server_properties.cc
index 386a00d0fe3e53c356865c2ce47088f3e245e1b0..3d594176e68656bb1f7ed74ca12322bdf52a4513 100644
--- a/net/http/http_server_properties.cc
+++ b/net/http/http_server_properties.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "net/socket/ssl_client_socket.h"
#include "net/ssl/ssl_config.h"
@@ -83,6 +84,29 @@ std::string AlternativeService::ToString() const {
host.c_str(), port);
}
+bool AlternativeService::FromString(const std::string& str,
+ AlternativeService* alternative_service) {
+ size_t space_pos = str.find(' ');
+ if (space_pos == std::string::npos)
+ return false;
+ size_t colon_pos = str.find(':');
+ if (colon_pos == std::string::npos)
+ return false;
+
+ alternative_service->protocol = NextProtoFromString(str.substr(0, space_pos));
+ alternative_service->host =
+ str.substr(space_pos + 1, colon_pos - space_pos - 1);
+
+ unsigned port_uint;
+ if (!base::StringToUint(str.substr(colon_pos + 1), &port_uint))
+ return false;
+ if (port_uint > std::numeric_limits<uint16_t>::max())
+ return false;
+ alternative_service->port = (uint16_t)port_uint;
+
+ return true;
+}
Ryan Hamilton 2017/06/12 18:57:32 Tests?
wangyix1 2017/06/14 00:01:25 Where should the test for this go? There doesn't s
+
std::string AlternativeServiceInfo::ToString() const {
base::Time::Exploded exploded;
expiration.LocalExplode(&exploded);

Powered by Google App Engine
This is Rietveld 408576698