Index: content/browser/background_fetch/background_fetch_registration_id.cc |
diff --git a/content/browser/background_fetch/background_fetch_registration_id.cc b/content/browser/background_fetch/background_fetch_registration_id.cc |
index 18156b0d4ea03193ead71dcfbeca3efedf17b477..fc4a50c6315593230005d3a6309379050d07edf3 100644 |
--- a/content/browser/background_fetch/background_fetch_registration_id.cc |
+++ b/content/browser/background_fetch/background_fetch_registration_id.cc |
@@ -4,10 +4,19 @@ |
#include "content/browser/background_fetch/background_fetch_registration_id.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/strings/string_split.h" |
+ |
#include "content/common/service_worker/service_worker_types.h" |
namespace content { |
+namespace { |
+ |
+const char kSeparator = ':'; |
+ |
+} // namespace |
+ |
BackgroundFetchRegistrationId::BackgroundFetchRegistrationId() |
: service_worker_registration_id_(kInvalidServiceWorkerRegistrationId) {} |
@@ -53,4 +62,23 @@ bool BackgroundFetchRegistrationId::is_null() const { |
return service_worker_registration_id_ == kInvalidServiceWorkerRegistrationId; |
} |
+void BackgroundFetchRegistrationId::FromString(const std::string& str) { |
Peter Beverloo
2017/03/29 14:32:12
nit: src -> serialized_registration_id?
harkness
2017/03/30 12:42:36
Done.
|
+ std::vector<std::string> parts = |
+ base::SplitString(str, std::string(1, kSeparator), base::TRIM_WHITESPACE, |
+ base::SPLIT_WANT_ALL); |
+ if ((parts.size() != 3) || |
+ (!base::StringToInt64(parts[0], &service_worker_registration_id_))) { |
+ service_worker_registration_id_ = kInvalidServiceWorkerRegistrationId; |
+ return; |
+ } |
+ |
+ origin_ = url::Origin(GURL(parts[1])); |
+ tag_ = parts[2]; |
Peter Beverloo
2017/03/29 14:32:12
I think we'll want to do much more error checking
harkness
2017/03/30 12:42:35
Some error checking added. What else would you sug
|
+} |
+ |
+std::string BackgroundFetchRegistrationId::ToString() const { |
+ return base::Int64ToString(service_worker_registration_id_) + kSeparator + |
Peter Beverloo
2017/03/29 14:32:12
DCHECK(!is_null());
harkness
2017/03/30 12:42:36
Do we really need to do error checking for the ser
|
+ origin_.Serialize() + kSeparator + tag_; |
Peter Beverloo
2017/03/29 14:32:12
This probably will be more efficient using base::S
harkness
2017/03/30 12:42:36
Done.
|
+} |
+ |
} // namespace content |