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

Side by Side Diff: content/renderer/push_messaging/push_messaging_client.cc

Issue 2712693002: Implement some follow-ups after mojofiction of Push-messaging. (Closed)
Patch Set: code rebase Created 3 years, 9 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
« no previous file with comments | « content/renderer/push_messaging/push_messaging_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/push_messaging/push_messaging_client.h" 5 #include "content/renderer/push_messaging/push_messaging_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void PushMessagingClient::DidGetManifest( 70 void PushMessagingClient::DidGetManifest(
71 blink::WebServiceWorkerRegistration* service_worker_registration, 71 blink::WebServiceWorkerRegistration* service_worker_registration,
72 const blink::WebPushSubscriptionOptions& options, 72 const blink::WebPushSubscriptionOptions& options,
73 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, 73 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
74 const GURL& manifest_url, 74 const GURL& manifest_url,
75 const Manifest& manifest, 75 const Manifest& manifest,
76 const ManifestDebugInfo&) { 76 const ManifestDebugInfo&) {
77 // Get the sender_info from the manifest since it wasn't provided by 77 // Get the sender_info from the manifest since it wasn't provided by
78 // the caller. 78 // the caller.
79 if (manifest.IsEmpty()) { 79 if (manifest.IsEmpty()) {
80 SubscribeCallback(std::move(callbacks), 80 DidSubscribe(std::move(callbacks),
81 PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING, 81 PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING,
82 base::nullopt, base::nullopt, base::nullopt, 82 base::nullopt, base::nullopt, base::nullopt, base::nullopt);
83 base::nullopt);
84 return; 83 return;
85 } 84 }
86 85
87 PushSubscriptionOptions content_options; 86 PushSubscriptionOptions content_options;
88 content_options.user_visible_only = options.userVisibleOnly; 87 content_options.user_visible_only = options.userVisibleOnly;
89 if (!manifest.gcm_sender_id.is_null()) { 88 if (!manifest.gcm_sender_id.is_null()) {
90 content_options.sender_info = 89 content_options.sender_info =
91 base::UTF16ToUTF8(manifest.gcm_sender_id.string()); 90 base::UTF16ToUTF8(manifest.gcm_sender_id.string());
92 } 91 }
93 92
94 DoSubscribe(service_worker_registration, content_options, 93 DoSubscribe(service_worker_registration, content_options,
95 std::move(callbacks)); 94 std::move(callbacks));
96 } 95 }
97 96
98 void PushMessagingClient::DoSubscribe( 97 void PushMessagingClient::DoSubscribe(
99 blink::WebServiceWorkerRegistration* service_worker_registration, 98 blink::WebServiceWorkerRegistration* service_worker_registration,
100 const PushSubscriptionOptions& options, 99 const PushSubscriptionOptions& options,
101 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { 100 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) {
102 int64_t service_worker_registration_id = 101 int64_t service_worker_registration_id =
103 static_cast<WebServiceWorkerRegistrationImpl*>( 102 static_cast<WebServiceWorkerRegistrationImpl*>(
104 service_worker_registration) 103 service_worker_registration)
105 ->registrationId(); 104 ->registrationId();
106 105
107 if (options.sender_info.empty()) { 106 if (options.sender_info.empty()) {
108 SubscribeCallback(std::move(callbacks), 107 DidSubscribe(std::move(callbacks), PUSH_REGISTRATION_STATUS_NO_SENDER_ID,
109 PUSH_REGISTRATION_STATUS_NO_SENDER_ID, base::nullopt, 108 base::nullopt, base::nullopt, base::nullopt, base::nullopt);
110 base::nullopt, base::nullopt, base::nullopt);
111 return; 109 return;
112 } 110 }
113 111
114 DCHECK(push_messaging_manager_); 112 DCHECK(push_messaging_manager_);
115 push_messaging_manager_->Subscribe( 113 push_messaging_manager_->Subscribe(
116 routing_id(), service_worker_registration_id, options, 114 routing_id(), service_worker_registration_id, options,
117 // Safe to use base::Unretained because |push_messaging_manager_ |is 115 // Safe to use base::Unretained because |push_messaging_manager_ |is
118 // owned by |this|. 116 // owned by |this|.
119 base::Bind(&PushMessagingClient::SubscribeCallback, 117 base::Bind(&PushMessagingClient::DidSubscribe, base::Unretained(this),
120 base::Unretained(this), base::Passed(&callbacks))); 118 base::Passed(&callbacks)));
121 } 119 }
122 120
123 void PushMessagingClient::SubscribeCallback( 121 void PushMessagingClient::DidSubscribe(
124 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, 122 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
125 content::PushRegistrationStatus status, 123 content::PushRegistrationStatus status,
126 const base::Optional<GURL>& endpoint, 124 const base::Optional<GURL>& endpoint,
127 const base::Optional<content::PushSubscriptionOptions>& options, 125 const base::Optional<content::PushSubscriptionOptions>& options,
128 const base::Optional<std::vector<uint8_t>>& p256dh, 126 const base::Optional<std::vector<uint8_t>>& p256dh,
129 const base::Optional<std::vector<uint8_t>>& auth) { 127 const base::Optional<std::vector<uint8_t>>& auth) {
130 DCHECK(callbacks); 128 DCHECK(callbacks);
131 129
132 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE || 130 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE ||
133 status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE) { 131 status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE) {
134 DCHECK(endpoint); 132 DCHECK(endpoint);
135 DCHECK(options); 133 DCHECK(options);
136 DCHECK(p256dh); 134 DCHECK(p256dh);
137 DCHECK(auth); 135 DCHECK(auth);
138 136
139 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>( 137 callbacks->onSuccess(base::MakeUnique<blink::WebPushSubscription>(
140 endpoint.value(), options.value().user_visible_only, 138 endpoint.value(), options.value().user_visible_only,
141 blink::WebString::fromLatin1(options.value().sender_info), 139 blink::WebString::fromLatin1(options.value().sender_info),
142 p256dh.value(), auth.value())); 140 p256dh.value(), auth.value()));
143 } else { 141 } else {
144 callbacks->onError(PushRegistrationStatusToWebPushError(status)); 142 callbacks->onError(PushRegistrationStatusToWebPushError(status));
145 } 143 }
146 } 144 }
147 145
148 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/push_messaging/push_messaging_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698