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

Side by Side Diff: content/browser/background_fetch/background_fetch_registration_id.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_fetch/background_fetch_registration_id.h" 5 #include "content/browser/background_fetch/background_fetch_registration_id.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h"
9
7 #include "content/common/service_worker/service_worker_types.h" 10 #include "content/common/service_worker/service_worker_types.h"
8 11
9 namespace content { 12 namespace content {
10 13
14 namespace {
15
16 const char kSeparator = ':';
17
18 } // namespace
19
11 BackgroundFetchRegistrationId::BackgroundFetchRegistrationId() 20 BackgroundFetchRegistrationId::BackgroundFetchRegistrationId()
12 : service_worker_registration_id_(kInvalidServiceWorkerRegistrationId) {} 21 : service_worker_registration_id_(kInvalidServiceWorkerRegistrationId) {}
13 22
14 BackgroundFetchRegistrationId::BackgroundFetchRegistrationId( 23 BackgroundFetchRegistrationId::BackgroundFetchRegistrationId(
15 int64_t service_worker_registration_id, 24 int64_t service_worker_registration_id,
16 const url::Origin& origin, 25 const url::Origin& origin,
17 const std::string& tag) 26 const std::string& tag)
18 : service_worker_registration_id_(service_worker_registration_id), 27 : service_worker_registration_id_(service_worker_registration_id),
19 origin_(origin), 28 origin_(origin),
20 tag_(tag) {} 29 tag_(tag) {}
(...skipping 25 matching lines...) Expand all
46 const BackgroundFetchRegistrationId& other) const { 55 const BackgroundFetchRegistrationId& other) const {
47 return service_worker_registration_id_ < 56 return service_worker_registration_id_ <
48 other.service_worker_registration_id_ || 57 other.service_worker_registration_id_ ||
49 origin_ < other.origin_ || tag_ < other.tag_; 58 origin_ < other.origin_ || tag_ < other.tag_;
50 } 59 }
51 60
52 bool BackgroundFetchRegistrationId::is_null() const { 61 bool BackgroundFetchRegistrationId::is_null() const {
53 return service_worker_registration_id_ == kInvalidServiceWorkerRegistrationId; 62 return service_worker_registration_id_ == kInvalidServiceWorkerRegistrationId;
54 } 63 }
55 64
65 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.
66 std::vector<std::string> parts =
67 base::SplitString(str, std::string(1, kSeparator), base::TRIM_WHITESPACE,
68 base::SPLIT_WANT_ALL);
69 if ((parts.size() != 3) ||
70 (!base::StringToInt64(parts[0], &service_worker_registration_id_))) {
71 service_worker_registration_id_ = kInvalidServiceWorkerRegistrationId;
72 return;
73 }
74
75 origin_ = url::Origin(GURL(parts[1]));
76 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
77 }
78
79 std::string BackgroundFetchRegistrationId::ToString() const {
80 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
81 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.
82 }
83
56 } // namespace content 84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698