OLD | NEW |
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_account_mapper.h" | 5 #include "components/gcm_driver/gcm_account_mapper.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/time/clock.h" | 11 #include "base/time/clock.h" |
12 #include "base/time/default_clock.h" | 12 #include "base/time/default_clock.h" |
13 #include "components/gcm_driver/gcm_driver_desktop.h" | 13 #include "components/gcm_driver/gcm_driver_desktop.h" |
| 14 #include "components/gcm_driver/gcm_message_status.h" |
14 #include "google_apis/gcm/engine/gcm_store.h" | 15 #include "google_apis/gcm/engine/gcm_store.h" |
15 | 16 |
16 namespace gcm { | 17 namespace gcm { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kGCMAccountMapperSenderId[] = "745476177629"; | 21 const char kGCMAccountMapperSenderId[] = "745476177629"; |
21 const char kGCMAccountMapperSendTo[] = "google.com"; | 22 const char kGCMAccountMapperSendTo[] = "google.com"; |
22 const int kGCMAddMappingMessageTTL = 30 * 60; // 0.5 hours in seconds. | 23 const int kGCMAddMappingMessageTTL = 30 * 60; // 0.5 hours in seconds. |
23 const int kGCMRemoveMappingMessageTTL = 24 * 60 * 60; // 1 day in seconds. | 24 const int kGCMRemoveMappingMessageTTL = 24 * 60 * 60; // 1 day in seconds. |
24 const int kGCMUpdateIntervalHours = 24; | 25 const int kGCMUpdateIntervalHours = 24; |
25 // Because adding an account mapping dependents on a fresh OAuth2 token, we | 26 // Because adding an account mapping dependents on a fresh OAuth2 token, we |
26 // allow the update to happen earlier than update due time, if it is within | 27 // allow the update to happen earlier than update due time, if it is within |
27 // the early start time to take advantage of that token. | 28 // the early start time to take advantage of that token. |
28 const int kGCMUpdateEarlyStartHours = 6; | 29 const int kGCMUpdateEarlyStartHours = 6; |
29 const char kRegistrationIdMessgaeKey[] = "id"; | 30 const char kRegistrationIdMessgaeKey[] = "id"; |
30 const char kTokenMessageKey[] = "t"; | 31 const char kTokenMessageKey[] = "t"; |
31 const char kAccountMessageKey[] = "a"; | 32 const char kAccountMessageKey[] = "a"; |
32 const char kRemoveAccountKey[] = "r"; | 33 const char kRemoveAccountKey[] = "r"; |
33 const char kRemoveAccountValue[] = "1"; | 34 const char kRemoveAccountValue[] = "1"; |
34 // Use to handle send to Gaia ID scenario: | 35 // Use to handle send to Gaia ID scenario: |
35 const char kGCMSendToGaiaIdAppIdKey[] = "gcmb"; | 36 const char kGCMSendToGaiaIdAppIdKey[] = "gcmb"; |
36 | 37 |
37 | 38 |
38 std::string GenerateMessageID() { | 39 std::string GenerateMessageID() { |
39 return base::GenerateGUID(); | 40 return base::GenerateGUID(); |
40 } | 41 } |
41 | 42 |
| 43 void NullReceiptCallback(GCMMessageStatus status) {} |
| 44 |
42 } // namespace | 45 } // namespace |
43 | 46 |
44 const char kGCMAccountMapperAppId[] = "com.google.android.gms"; | 47 const char kGCMAccountMapperAppId[] = "com.google.android.gms"; |
45 | 48 |
46 GCMAccountMapper::GCMAccountMapper(GCMDriver* gcm_driver) | 49 GCMAccountMapper::GCMAccountMapper(GCMDriver* gcm_driver) |
47 : gcm_driver_(gcm_driver), | 50 : gcm_driver_(gcm_driver), |
48 clock_(new base::DefaultClock), | 51 clock_(new base::DefaultClock), |
49 initialized_(false), | 52 initialized_(false), |
50 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
51 } | 54 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 177 |
175 std::string embedded_app_id = it->second; | 178 std::string embedded_app_id = it->second; |
176 if (embedded_app_id.empty()) { | 179 if (embedded_app_id.empty()) { |
177 DVLOG(1) << "Send to Gaia ID failure: Embedded app ID is empty."; | 180 DVLOG(1) << "Send to Gaia ID failure: Embedded app ID is empty."; |
178 return; | 181 return; |
179 } | 182 } |
180 | 183 |
181 // Ensuring the message does not carry the embedded app ID. | 184 // Ensuring the message does not carry the embedded app ID. |
182 IncomingMessage new_message = message; | 185 IncomingMessage new_message = message; |
183 new_message.data.erase(new_message.data.find(kGCMSendToGaiaIdAppIdKey)); | 186 new_message.data.erase(new_message.data.find(kGCMSendToGaiaIdAppIdKey)); |
184 dispatch_message_callback_.Run(embedded_app_id, new_message); | 187 // TODO(harkness): Update this to use a real callback once callbacks are |
| 188 // plumbed to all GCMAppHandlers. |
| 189 dispatch_message_callback_.Run(embedded_app_id, new_message, |
| 190 base::Bind(&NullReceiptCallback)); |
185 } | 191 } |
186 | 192 |
187 void GCMAccountMapper::OnMessagesDeleted(const std::string& app_id) { | 193 void GCMAccountMapper::OnMessagesDeleted(const std::string& app_id) { |
188 // Account message does not expect messages right now. | 194 // Account message does not expect messages right now. |
189 } | 195 } |
190 | 196 |
191 void GCMAccountMapper::OnSendError( | 197 void GCMAccountMapper::OnSendError( |
192 const std::string& app_id, | 198 const std::string& app_id, |
193 const GCMClient::SendErrorDetails& send_error_details) { | 199 const GCMClient::SendErrorDetails& send_error_details) { |
194 DCHECK_EQ(app_id, kGCMAccountMapperAppId); | 200 DCHECK_EQ(app_id, kGCMAccountMapperAppId); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 396 } |
391 | 397 |
392 return accounts_.end(); | 398 return accounts_.end(); |
393 } | 399 } |
394 | 400 |
395 void GCMAccountMapper::SetClockForTesting(std::unique_ptr<base::Clock> clock) { | 401 void GCMAccountMapper::SetClockForTesting(std::unique_ptr<base::Clock> clock) { |
396 clock_ = std::move(clock); | 402 clock_ = std::move(clock); |
397 } | 403 } |
398 | 404 |
399 } // namespace gcm | 405 } // namespace gcm |
OLD | NEW |