| 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/registration_request.h" | 5 #include "google_apis/gcm/engine/registration_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 "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 12 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 14 #include "net/base/load_flags.h" |
| 14 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
| 15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 18 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace gcm { | 22 namespace gcm { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DCHECK(!callback_.is_null()); | 122 DCHECK(!callback_.is_null()); |
| 122 DCHECK(request_info_.android_id != 0UL); | 123 DCHECK(request_info_.android_id != 0UL); |
| 123 DCHECK(request_info_.security_token != 0UL); | 124 DCHECK(request_info_.security_token != 0UL); |
| 124 DCHECK(0 < request_info_.sender_ids.size() && | 125 DCHECK(0 < request_info_.sender_ids.size() && |
| 125 request_info_.sender_ids.size() <= kMaxSenders); | 126 request_info_.sender_ids.size() <= kMaxSenders); |
| 126 | 127 |
| 127 DCHECK(!url_fetcher_.get()); | 128 DCHECK(!url_fetcher_.get()); |
| 128 url_fetcher_.reset(net::URLFetcher::Create( | 129 url_fetcher_.reset(net::URLFetcher::Create( |
| 129 registration_url_, net::URLFetcher::POST, this)); | 130 registration_url_, net::URLFetcher::POST, this)); |
| 130 url_fetcher_->SetRequestContext(request_context_getter_); | 131 url_fetcher_->SetRequestContext(request_context_getter_); |
| 132 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 133 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 131 | 134 |
| 132 std::string android_id = base::Uint64ToString(request_info_.android_id); | 135 std::string android_id = base::Uint64ToString(request_info_.android_id); |
| 133 std::string auth_header = | 136 std::string auth_header = |
| 134 std::string(net::HttpRequestHeaders::kAuthorization) + ": " + | 137 std::string(net::HttpRequestHeaders::kAuthorization) + ": " + |
| 135 kLoginHeader + " " + android_id + ":" + | 138 kLoginHeader + " " + android_id + ":" + |
| 136 base::Uint64ToString(request_info_.security_token); | 139 base::Uint64ToString(request_info_.security_token); |
| 137 url_fetcher_->SetExtraRequestHeaders(auth_header); | 140 url_fetcher_->SetExtraRequestHeaders(auth_header); |
| 138 | 141 |
| 139 std::string body; | 142 std::string body; |
| 140 BuildFormEncoding(kAppIdKey, request_info_.app_id, &body); | 143 BuildFormEncoding(kAppIdKey, request_info_.app_id, &body); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (status == SUCCESS) { | 261 if (status == SUCCESS) { |
| 259 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRetryCount", | 262 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRetryCount", |
| 260 backoff_entry_.failure_count()); | 263 backoff_entry_.failure_count()); |
| 261 UMA_HISTOGRAM_TIMES("GCM.RegistrationCompleteTime", | 264 UMA_HISTOGRAM_TIMES("GCM.RegistrationCompleteTime", |
| 262 base::TimeTicks::Now() - request_start_time_); | 265 base::TimeTicks::Now() - request_start_time_); |
| 263 } | 266 } |
| 264 callback_.Run(status, token); | 267 callback_.Run(status, token); |
| 265 } | 268 } |
| 266 | 269 |
| 267 } // namespace gcm | 270 } // namespace gcm |
| OLD | NEW |