| 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_channel_status_request.h" | 5 #include "components/gcm_driver/gcm_channel_status_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 "components/gcm_driver/gcm_backoff_policy.h" | 9 #include "components/gcm_driver/gcm_backoff_policy.h" |
| 10 #include "components/gcm_driver/proto/gcm_channel_status.pb.h" | 10 #include "components/gcm_driver/proto/gcm_channel_status.pb.h" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 14 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace gcm { | 18 namespace gcm { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kGCMChannelStatusRequestURL[] = | |
| 23 "https://clients4.google.com/chrome-sync/command/"; | |
| 24 const char kRequestContentType[] = "application/octet-stream"; | 22 const char kRequestContentType[] = "application/octet-stream"; |
| 25 const char kGCMChannelTag[] = "gcm_channel"; | 23 const char kGCMChannelTag[] = "gcm_channel"; |
| 26 const int kDefaultPollIntervalSeconds = 60 * 60; // 60 minutes. | 24 const int kDefaultPollIntervalSeconds = 60 * 60; // 60 minutes. |
| 27 const int kMinPollIntervalSeconds = 30 * 60; // 30 minutes. | 25 const int kMinPollIntervalSeconds = 30 * 60; // 30 minutes. |
| 28 | 26 |
| 29 } // namespace | 27 } // namespace |
| 30 | 28 |
| 31 GCMChannelStatusRequest::GCMChannelStatusRequest( | 29 GCMChannelStatusRequest::GCMChannelStatusRequest( |
| 32 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 30 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 31 const std::string& channel_status_request_url, |
| 32 const std::string& user_agent, |
| 33 const GCMChannelStatusRequestCallback& callback) | 33 const GCMChannelStatusRequestCallback& callback) |
| 34 : request_context_getter_(request_context_getter), | 34 : request_context_getter_(request_context_getter), |
| 35 channel_status_request_url_(channel_status_request_url), |
| 36 user_agent_(user_agent), |
| 35 callback_(callback), | 37 callback_(callback), |
| 36 backoff_entry_(&(GetGCMBackoffPolicy())), | 38 backoff_entry_(&(GetGCMBackoffPolicy())), |
| 37 weak_ptr_factory_(this) { | 39 weak_ptr_factory_(this) { |
| 38 } | 40 } |
| 39 | 41 |
| 40 GCMChannelStatusRequest::~GCMChannelStatusRequest() { | 42 GCMChannelStatusRequest::~GCMChannelStatusRequest() { |
| 41 } | 43 } |
| 42 | 44 |
| 43 // static | 45 // static |
| 44 int GCMChannelStatusRequest::default_poll_interval_seconds() { | 46 int GCMChannelStatusRequest::default_poll_interval_seconds() { |
| 45 return kDefaultPollIntervalSeconds; | 47 return kDefaultPollIntervalSeconds; |
| 46 } | 48 } |
| 47 | 49 |
| 48 // static | 50 // static |
| 49 int GCMChannelStatusRequest::min_poll_interval_seconds() { | 51 int GCMChannelStatusRequest::min_poll_interval_seconds() { |
| 50 return kMinPollIntervalSeconds; | 52 return kMinPollIntervalSeconds; |
| 51 } | 53 } |
| 52 | 54 |
| 53 void GCMChannelStatusRequest::Start() { | 55 void GCMChannelStatusRequest::Start() { |
| 54 DCHECK(!url_fetcher_.get()); | 56 DCHECK(!url_fetcher_.get()); |
| 55 | 57 |
| 56 GURL request_url(kGCMChannelStatusRequestURL); | 58 GURL request_url(channel_status_request_url_); |
| 57 | 59 |
| 58 gcm_proto::ExperimentStatusRequest proto_data; | 60 gcm_proto::ExperimentStatusRequest proto_data; |
| 59 proto_data.add_experiment_name(kGCMChannelTag); | 61 proto_data.add_experiment_name(kGCMChannelTag); |
| 60 std::string upload_data; | 62 std::string upload_data; |
| 61 DCHECK(proto_data.SerializeToString(&upload_data)); | 63 DCHECK(proto_data.SerializeToString(&upload_data)); |
| 62 | 64 |
| 63 url_fetcher_.reset( | 65 url_fetcher_.reset( |
| 64 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this)); | 66 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this)); |
| 65 url_fetcher_->SetRequestContext(request_context_getter_.get()); | 67 url_fetcher_->SetRequestContext(request_context_getter_.get()); |
| 68 url_fetcher_->AddExtraRequestHeader("User-Agent: " + user_agent_); |
| 66 url_fetcher_->SetUploadData(kRequestContentType, upload_data); | 69 url_fetcher_->SetUploadData(kRequestContentType, upload_data); |
| 67 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 70 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 68 net::LOAD_DO_NOT_SAVE_COOKIES); | 71 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 69 url_fetcher_->Start(); | 72 url_fetcher_->Start(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void GCMChannelStatusRequest::OnURLFetchComplete( | 75 void GCMChannelStatusRequest::OnURLFetchComplete( |
| 73 const net::URLFetcher* source) { | 76 const net::URLFetcher* source) { |
| 74 if (ParseResponse(source)) | 77 if (ParseResponse(source)) |
| 75 return; | 78 return; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 weak_ptr_factory_.GetWeakPtr(), | 140 weak_ptr_factory_.GetWeakPtr(), |
| 138 false), | 141 false), |
| 139 backoff_entry_.GetTimeUntilRelease()); | 142 backoff_entry_.GetTimeUntilRelease()); |
| 140 return; | 143 return; |
| 141 } | 144 } |
| 142 | 145 |
| 143 Start(); | 146 Start(); |
| 144 } | 147 } |
| 145 | 148 |
| 146 } // namespace gcm | 149 } // namespace gcm |
| OLD | NEW |