| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 40 if (delegate) | 40 if (delegate) |
| 41 delegates_[username] = delegate; | 41 delegates_[username] = delegate; |
| 42 else | 42 else |
| 43 delegates_.erase(username); | 43 delegates_.erase(username); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void GCMClientMock::CheckIn(const std::string& username) { | 46 void GCMClientMock::CheckIn(const std::string& username) { |
| 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 48 | 48 |
| 49 // Simulate the android_id and secret by some sort of hashing. | 49 // Simulate the android_id and secret by some sort of hashing. |
| 50 CheckInInfo checkin_info; | 50 CheckinInfo checkin_info; |
| 51 if (!simulate_server_error_) | 51 if (!simulate_server_error_) |
| 52 checkin_info = GetCheckInInfoFromUsername(username); | 52 checkin_info = GetCheckinInfoFromUsername(username); |
| 53 | 53 |
| 54 base::MessageLoop::current()->PostTask( | 54 base::MessageLoop::current()->PostTask( |
| 55 FROM_HERE, | 55 FROM_HERE, |
| 56 base::Bind(&GCMClientMock::CheckInFinished, | 56 base::Bind(&GCMClientMock::CheckInFinished, |
| 57 base::Unretained(this), | 57 base::Unretained(this), |
| 58 username, | 58 username, |
| 59 checkin_info)); | 59 checkin_info)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void GCMClientMock::Register(const std::string& username, | 62 void GCMClientMock::Register(const std::string& username, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (is_loading_) | 139 if (is_loading_) |
| 140 return; | 140 return; |
| 141 content::BrowserThread::PostTask( | 141 content::BrowserThread::PostTask( |
| 142 content::BrowserThread::IO, | 142 content::BrowserThread::IO, |
| 143 FROM_HERE, | 143 FROM_HERE, |
| 144 base::Bind(&GCMClientMock::LoadingCompleted, | 144 base::Bind(&GCMClientMock::LoadingCompleted, |
| 145 base::Unretained(this))); | 145 base::Unretained(this))); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // static | 148 // static |
| 149 GCMClient::CheckInInfo GCMClientMock::GetCheckInInfoFromUsername( | 149 GCMClient::CheckinInfo GCMClientMock::GetCheckinInfoFromUsername( |
| 150 const std::string& username) { | 150 const std::string& username) { |
| 151 CheckInInfo checkin_info; | 151 CheckinInfo checkin_info; |
| 152 checkin_info.android_id = HashToUInt64(username); | 152 checkin_info.android_id = HashToUInt64(username); |
| 153 checkin_info.secret = checkin_info.android_id / 10; | 153 checkin_info.secret = checkin_info.android_id / 10; |
| 154 return checkin_info; | 154 return checkin_info; |
| 155 } | 155 } |
| 156 | 156 |
| 157 // static | 157 // static |
| 158 std::string GCMClientMock::GetRegistrationIdFromSenderIds( | 158 std::string GCMClientMock::GetRegistrationIdFromSenderIds( |
| 159 const std::vector<std::string>& sender_ids) { | 159 const std::vector<std::string>& sender_ids) { |
| 160 // Simulate the registration_id by concaternating all sender IDs. | 160 // Simulate the registration_id by concaternating all sender IDs. |
| 161 // Set registration_id to empty to denote an error if sender_ids contains a | 161 // Set registration_id to empty to denote an error if sender_ids contains a |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 | 174 |
| 175 GCMClient::Delegate* GCMClientMock::GetDelegate( | 175 GCMClient::Delegate* GCMClientMock::GetDelegate( |
| 176 const std::string& username) const { | 176 const std::string& username) const { |
| 177 std::map<std::string, Delegate*>::const_iterator iter = | 177 std::map<std::string, Delegate*>::const_iterator iter = |
| 178 delegates_.find(username); | 178 delegates_.find(username); |
| 179 DCHECK(iter != delegates_.end()); | 179 DCHECK(iter != delegates_.end()); |
| 180 return iter->second; | 180 return iter->second; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void GCMClientMock::CheckInFinished(std::string username, | 183 void GCMClientMock::CheckInFinished(std::string username, |
| 184 CheckInInfo checkin_info) { | 184 CheckinInfo checkin_info) { |
| 185 GetDelegate(username)->OnCheckInFinished( | 185 GetDelegate(username)->OnCheckInFinished( |
| 186 checkin_info, checkin_info.IsValid() ? SUCCESS : SERVER_ERROR); | 186 checkin_info, checkin_info.IsValid() ? SUCCESS : SERVER_ERROR); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void GCMClientMock::RegisterFinished(std::string username, | 189 void GCMClientMock::RegisterFinished(std::string username, |
| 190 std::string app_id, | 190 std::string app_id, |
| 191 std::string registrion_id) { | 191 std::string registrion_id) { |
| 192 GetDelegate(username)->OnRegisterFinished( | 192 GetDelegate(username)->OnRegisterFinished( |
| 193 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); | 193 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); |
| 194 } | 194 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 void GCMClientMock::LoadingCompleted() { | 230 void GCMClientMock::LoadingCompleted() { |
| 231 for (std::map<std::string, Delegate*>::const_iterator iter = | 231 for (std::map<std::string, Delegate*>::const_iterator iter = |
| 232 delegates_.begin(); | 232 delegates_.begin(); |
| 233 iter != delegates_.end(); ++iter) { | 233 iter != delegates_.end(); ++iter) { |
| 234 iter->second->OnLoadingCompleted(); | 234 iter->second->OnLoadingCompleted(); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace gcm | 238 } // namespace gcm |
| OLD | NEW |