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

Side by Side Diff: components/gcm_driver/gcm_driver.cc

Issue 914693002: Push API: Fix unsubscribing from GCM on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fix Created 5 years, 10 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 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 "components/gcm_driver/gcm_driver.h" 5 #include "components/gcm_driver/gcm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 normalized_sender_ids, 63 normalized_sender_ids,
64 unregister_iter->second); 64 unregister_iter->second);
65 return; 65 return;
66 } 66 }
67 67
68 RegisterImpl(app_id, normalized_sender_ids); 68 RegisterImpl(app_id, normalized_sender_ids);
69 } 69 }
70 70
71 void GCMDriver::Unregister(const std::string& app_id, 71 void GCMDriver::Unregister(const std::string& app_id,
72 const UnregisterCallback& callback) { 72 const UnregisterCallback& callback) {
73 UnregisterInternal(app_id, nullptr /* maybe_sender_id */, callback);
74 }
75
76 void GCMDriver::UnregisterWithSenderId(
77 const std::string& app_id,
78 const std::string& sender_id,
79 const UnregisterCallback& callback) {
80 DCHECK(!sender_id.empty());
81 UnregisterInternal(app_id, &sender_id, callback);
82 }
83
84 void GCMDriver::UnregisterInternal(const std::string& app_id,
85 const std::string* maybe_sender_id,
86 const UnregisterCallback& callback) {
73 DCHECK(!app_id.empty()); 87 DCHECK(!app_id.empty());
74 DCHECK(!callback.is_null()); 88 DCHECK(!callback.is_null());
75 89
76 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 90 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
77 if (result != GCMClient::SUCCESS) { 91 if (result != GCMClient::SUCCESS) {
78 callback.Run(result); 92 callback.Run(result);
79 return; 93 return;
80 } 94 }
81 95
82 // If previous un/register operation is still in progress, bail out. 96 // If previous un/register operation is still in progress, bail out.
83 if (register_callbacks_.find(app_id) != register_callbacks_.end() || 97 if (register_callbacks_.find(app_id) != register_callbacks_.end() ||
84 unregister_callbacks_.find(app_id) != unregister_callbacks_.end()) { 98 unregister_callbacks_.find(app_id) != unregister_callbacks_.end()) {
85 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); 99 callback.Run(GCMClient::ASYNC_OPERATION_PENDING);
86 return; 100 return;
87 } 101 }
88 102
103
Peter Beverloo 2015/02/17 18:49:36 micro nit: extra blank line
johnme 2015/02/17 21:24:07 Done.
89 unregister_callbacks_[app_id] = callback; 104 unregister_callbacks_[app_id] = callback;
90 105
91 UnregisterImpl(app_id); 106 UnregisterImpl(app_id, maybe_sender_id);
92 } 107 }
93 108
94 void GCMDriver::Send(const std::string& app_id, 109 void GCMDriver::Send(const std::string& app_id,
95 const std::string& receiver_id, 110 const std::string& receiver_id,
96 const GCMClient::OutgoingMessage& message, 111 const GCMClient::OutgoingMessage& message,
97 const SendCallback& callback) { 112 const SendCallback& callback) {
98 DCHECK(!app_id.empty()); 113 DCHECK(!app_id.empty());
99 DCHECK(!receiver_id.empty()); 114 DCHECK(!receiver_id.empty());
100 DCHECK(!callback.is_null()); 115 DCHECK(!callback.is_null());
101 116
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 GCMClient::Result result) { 231 GCMClient::Result result) {
217 // Invoke the original unregister callback. 232 // Invoke the original unregister callback.
218 unregister_callback.Run(result); 233 unregister_callback.Run(result);
219 234
220 // Trigger the pending registration. 235 // Trigger the pending registration.
221 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); 236 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end());
222 RegisterImpl(app_id, normalized_sender_ids); 237 RegisterImpl(app_id, normalized_sender_ids);
223 } 238 }
224 239
225 } // namespace gcm 240 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698