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 "google_apis/gcm/engine/checkin_request.h" | 5 #include "google_apis/gcm/engine/checkin_request.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "google_apis/gcm/protocol/checkin.pb.h" | 10 #include "google_apis/gcm/protocol/checkin.pb.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 CheckinRequest::CheckinRequest( | 49 CheckinRequest::CheckinRequest( |
50 const CheckinRequestCallback& callback, | 50 const CheckinRequestCallback& callback, |
51 const net::BackoffEntry::Policy& backoff_policy, | 51 const net::BackoffEntry::Policy& backoff_policy, |
52 const checkin_proto::ChromeBuildProto& chrome_build_proto, | 52 const checkin_proto::ChromeBuildProto& chrome_build_proto, |
53 uint64 android_id, | 53 uint64 android_id, |
54 uint64 security_token, | 54 uint64 security_token, |
| 55 const std::vector<std::string>& account_ids, |
55 net::URLRequestContextGetter* request_context_getter) | 56 net::URLRequestContextGetter* request_context_getter) |
56 : request_context_getter_(request_context_getter), | 57 : request_context_getter_(request_context_getter), |
57 callback_(callback), | 58 callback_(callback), |
58 backoff_entry_(&backoff_policy), | 59 backoff_entry_(&backoff_policy), |
59 chrome_build_proto_(chrome_build_proto), | 60 chrome_build_proto_(chrome_build_proto), |
60 android_id_(android_id), | 61 android_id_(android_id), |
61 security_token_(security_token), | 62 security_token_(security_token), |
| 63 account_ids_(account_ids), |
62 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
63 } | 65 } |
64 | 66 |
65 CheckinRequest::~CheckinRequest() {} | 67 CheckinRequest::~CheckinRequest() {} |
66 | 68 |
67 void CheckinRequest::Start() { | 69 void CheckinRequest::Start() { |
68 DCHECK(!url_fetcher_.get()); | 70 DCHECK(!url_fetcher_.get()); |
69 | 71 |
70 checkin_proto::AndroidCheckinRequest request; | 72 checkin_proto::AndroidCheckinRequest request; |
71 request.set_id(android_id_); | 73 request.set_id(android_id_); |
72 request.set_security_token(security_token_); | 74 request.set_security_token(security_token_); |
73 request.set_user_serial_number(kDefaultUserSerialNumber); | 75 request.set_user_serial_number(kDefaultUserSerialNumber); |
74 request.set_version(kRequestVersionValue); | 76 request.set_version(kRequestVersionValue); |
75 | 77 |
76 checkin_proto::AndroidCheckinProto* checkin = request.mutable_checkin(); | 78 checkin_proto::AndroidCheckinProto* checkin = request.mutable_checkin(); |
77 checkin->mutable_chrome_build()->CopyFrom(chrome_build_proto_); | 79 checkin->mutable_chrome_build()->CopyFrom(chrome_build_proto_); |
78 #if defined(CHROME_OS) | 80 #if defined(CHROME_OS) |
79 checkin->set_type(checkin_proto::DEVICE_CHROME_OS); | 81 checkin->set_type(checkin_proto::DEVICE_CHROME_OS); |
80 #else | 82 #else |
81 checkin->set_type(checkin_proto::DEVICE_CHROME_BROWSER); | 83 checkin->set_type(checkin_proto::DEVICE_CHROME_BROWSER); |
82 #endif | 84 #endif |
83 | 85 |
| 86 for (std::vector<std::string>::const_iterator iter = account_ids_.begin(); |
| 87 iter != account_ids_.end(); |
| 88 ++iter) { |
| 89 request.add_account_cookie("[" + *iter + "]"); |
| 90 } |
| 91 |
84 std::string upload_data; | 92 std::string upload_data; |
85 CHECK(request.SerializeToString(&upload_data)); | 93 CHECK(request.SerializeToString(&upload_data)); |
86 | 94 |
87 url_fetcher_.reset( | 95 url_fetcher_.reset( |
88 net::URLFetcher::Create(GURL(kCheckinURL), net::URLFetcher::POST, this)); | 96 net::URLFetcher::Create(GURL(kCheckinURL), net::URLFetcher::POST, this)); |
89 url_fetcher_->SetRequestContext(request_context_getter_); | 97 url_fetcher_->SetRequestContext(request_context_getter_); |
90 url_fetcher_->SetUploadData(kRequestContentType, upload_data); | 98 url_fetcher_->SetUploadData(kRequestContentType, upload_data); |
91 url_fetcher_->Start(); | 99 url_fetcher_->Start(); |
92 } | 100 } |
93 | 101 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN); | 164 RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN); |
157 RetryWithBackoff(true); | 165 RetryWithBackoff(true); |
158 return; | 166 return; |
159 } | 167 } |
160 | 168 |
161 RecordCheckinStatusToUMA(SUCCESS); | 169 RecordCheckinStatusToUMA(SUCCESS); |
162 callback_.Run(response_proto.android_id(), response_proto.security_token()); | 170 callback_.Run(response_proto.android_id(), response_proto.security_token()); |
163 } | 171 } |
164 | 172 |
165 } // namespace gcm | 173 } // namespace gcm |
OLD | NEW |