| Index: content/public/browser/push_messaging_application_id.cc
|
| diff --git a/content/public/browser/push_messaging_application_id.cc b/content/public/browser/push_messaging_application_id.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fea20d92e59bf998497f1050bf7e01c4620fd9e4
|
| --- /dev/null
|
| +++ b/content/public/browser/push_messaging_application_id.cc
|
| @@ -0,0 +1,47 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/public/browser/push_messaging_application_id.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_split.h"
|
| +
|
| +namespace {
|
| +const char kSeparator = '#'; // Ok as only the origin of the url is used.
|
| +const char kPrefix[] = "push";
|
| +} // namespace
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +PushMessagingApplicationId PushMessagingApplicationId::Parse(
|
| + const std::string& id) {
|
| + std::vector<std::string> parts;
|
| + base::SplitString(id, kSeparator, &parts);
|
| +
|
| + if (parts.size() != 3 || parts[0] != kPrefix)
|
| + return PushMessagingApplicationId();
|
| +
|
| + GURL origin = GURL(parts[1]);
|
| + if (!origin.is_valid() || origin.GetOrigin() != origin)
|
| + return PushMessagingApplicationId();
|
| +
|
| + int64 worker_registration_id;
|
| + if (!base::StringToInt64(parts[2], &worker_registration_id))
|
| + return PushMessagingApplicationId();
|
| +
|
| + return PushMessagingApplicationId(origin, worker_registration_id);
|
| +}
|
| +
|
| +// static
|
| +bool PushMessagingApplicationId::IsValid(const std::string& id) {
|
| + return PushMessagingApplicationId::Parse(id).is_valid();
|
| +}
|
| +
|
| +std::string PushMessagingApplicationId::ToString() {
|
| + return (std::string(kPrefix) + kSeparator + origin.spec() + kSeparator + base::Int64ToString(worker_registration_id));
|
| +}
|
| +
|
| +} // namespace content
|
|
|