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

Side by Side Diff: chrome/browser/services/gcm/gcm_client_mock.cc

Issue 183923006: [GCM] API update to allow only a single sender in registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates based on CR. Changing how the senders/reg_ids are stored to avoid upgrade to multiple sedne… Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/services/gcm/gcm_client_mock.h" 5 #include "chrome/browser/services/gcm/gcm_client_mock.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 weak_ptr_factory_.GetWeakPtr())); 53 weak_ptr_factory_.GetWeakPtr()));
54 } 54 }
55 55
56 void GCMClientMock::CheckOut() { 56 void GCMClientMock::CheckOut() {
57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
58 status_ = CHECKED_OUT; 58 status_ = CHECKED_OUT;
59 } 59 }
60 60
61 void GCMClientMock::Register(const std::string& app_id, 61 void GCMClientMock::Register(const std::string& app_id,
62 const std::string& cert, 62 const std::string& cert,
63 const std::vector<std::string>& sender_ids) { 63 const std::string& sender_id) {
64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
65 65
66 std::string registration_id; 66 std::string registration_id;
67 if (error_simulation_ == ALWAYS_SUCCEED) 67 if (error_simulation_ == ALWAYS_SUCCEED)
68 registration_id = GetRegistrationIdFromSenderIds(sender_ids); 68 registration_id = GetRegistrationIdFromSenderId(sender_id);
69 69
70 base::MessageLoop::current()->PostTask( 70 base::MessageLoop::current()->PostTask(
71 FROM_HERE, 71 FROM_HERE,
72 base::Bind(&GCMClientMock::RegisterFinished, 72 base::Bind(&GCMClientMock::RegisterFinished,
73 weak_ptr_factory_.GetWeakPtr(), 73 weak_ptr_factory_.GetWeakPtr(),
74 app_id, 74 app_id,
75 registration_id)); 75 registration_id));
76 } 76 }
77 77
78 void GCMClientMock::Unregister(const std::string& app_id) { 78 void GCMClientMock::Unregister(const std::string& app_id) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 content::BrowserThread::PostTask( 119 content::BrowserThread::PostTask(
120 content::BrowserThread::IO, 120 content::BrowserThread::IO,
121 FROM_HERE, 121 FROM_HERE,
122 base::Bind(&GCMClientMock::MessagesDeleted, 122 base::Bind(&GCMClientMock::MessagesDeleted,
123 weak_ptr_factory_.GetWeakPtr(), 123 weak_ptr_factory_.GetWeakPtr(),
124 app_id)); 124 app_id));
125 } 125 }
126 126
127 // static 127 // static
128 std::string GCMClientMock::GetRegistrationIdFromSenderIds( 128 std::string GCMClientMock::GetRegistrationIdFromSenderId(
129 const std::vector<std::string>& sender_ids) { 129 const std::string& sender_id) {
130 // GCMProfileService normalizes the sender IDs by making them sorted. 130 // Simulate the registration_id by appending reg_id to the sender ID.
131 std::vector<std::string> normalized_sender_ids = sender_ids; 131 // Set registration_id to empty to denote an error if sender_id contains a
132 std::sort(normalized_sender_ids.begin(), normalized_sender_ids.end());
133
134 // Simulate the registration_id by concaternating all sender IDs.
135 // Set registration_id to empty to denote an error if sender_ids contains a
136 // hint. 132 // hint.
137 std::string registration_id; 133 if (sender_id.find("error") == std::string::npos)
138 if (sender_ids.size() != 1 || 134 return sender_id + "_reg_id";
139 sender_ids[0].find("error") == std::string::npos) { 135 return std::string();
140 for (size_t i = 0; i < normalized_sender_ids.size(); ++i) {
141 if (i > 0)
142 registration_id += ",";
143 registration_id += normalized_sender_ids[i];
144 }
145 }
146 return registration_id;
147 } 136 }
148 137
149 void GCMClientMock::CheckinFinished() { 138 void GCMClientMock::CheckinFinished() {
150 delegate_->OnGCMReady(); 139 delegate_->OnGCMReady();
151 } 140 }
152 141
153 void GCMClientMock::RegisterFinished(const std::string& app_id, 142 void GCMClientMock::RegisterFinished(const std::string& app_id,
154 const std::string& registrion_id) { 143 const std::string& registrion_id) {
155 delegate_->OnRegisterFinished( 144 delegate_->OnRegisterFinished(
156 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); 145 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS);
(...skipping 26 matching lines...) Expand all
183 delegate_->OnMessagesDeleted(app_id); 172 delegate_->OnMessagesDeleted(app_id);
184 } 173 }
185 174
186 void GCMClientMock::MessageSendError(const std::string& app_id, 175 void GCMClientMock::MessageSendError(const std::string& app_id,
187 const std::string& message_id) { 176 const std::string& message_id) {
188 if (delegate_) 177 if (delegate_)
189 delegate_->OnMessageSendError(app_id, message_id, NETWORK_ERROR); 178 delegate_->OnMessageSendError(app_id, message_id, NETWORK_ERROR);
190 } 179 }
191 180
192 } // namespace gcm 181 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698