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" | |
11 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
12 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
13 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
14 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
15 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
15 #include "sync/protocol/experiment_status.pb.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[] = | 22 const char kGCMChannelStatusRequestURL[] = |
23 "https://clients4.google.com/chrome-sync/command/"; | 23 "https://clients4.google.com/chrome-sync/command/"; |
24 const char kRequestContentType[] = "application/octet-stream"; | 24 const char kRequestContentType[] = "application/octet-stream"; |
25 const char kGCMChannelTag[] = "gcm_channel"; | 25 const char kGCMChannelTag[] = "gcm_channel"; |
(...skipping 22 matching lines...) Expand all Loading... | |
48 // static | 48 // static |
49 int GCMChannelStatusRequest::min_poll_interval_seconds() { | 49 int GCMChannelStatusRequest::min_poll_interval_seconds() { |
50 return kMinPollIntervalSeconds; | 50 return kMinPollIntervalSeconds; |
51 } | 51 } |
52 | 52 |
53 void GCMChannelStatusRequest::Start() { | 53 void GCMChannelStatusRequest::Start() { |
54 DCHECK(!url_fetcher_.get()); | 54 DCHECK(!url_fetcher_.get()); |
55 | 55 |
56 GURL request_url(kGCMChannelStatusRequestURL); | 56 GURL request_url(kGCMChannelStatusRequestURL); |
57 | 57 |
58 gcm_proto::ExperimentStatusRequest proto_data; | 58 sync_pb::ExperimentStatusRequest proto_data; |
59 proto_data.add_experiment_name(kGCMChannelTag); | 59 proto_data.add_experiment_name(kGCMChannelTag); |
60 std::string upload_data; | 60 std::string upload_data; |
61 DCHECK(proto_data.SerializeToString(&upload_data)); | 61 DCHECK(proto_data.SerializeToString(&upload_data)); |
62 | 62 |
63 url_fetcher_.reset( | 63 url_fetcher_.reset( |
64 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this)); | 64 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this)); |
65 url_fetcher_->SetRequestContext(request_context_getter_.get()); | 65 url_fetcher_->SetRequestContext(request_context_getter_.get()); |
66 url_fetcher_->SetUploadData(kRequestContentType, upload_data); | 66 url_fetcher_->SetUploadData(kRequestContentType, upload_data); |
67 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 67 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
68 net::LOAD_DO_NOT_SAVE_COOKIES); | 68 net::LOAD_DO_NOT_SAVE_COOKIES); |
(...skipping 20 matching lines...) Expand all Loading... | |
89 return false; | 89 return false; |
90 } | 90 } |
91 | 91 |
92 std::string response_string; | 92 std::string response_string; |
93 if (!source->GetResponseAsString(&response_string) || | 93 if (!source->GetResponseAsString(&response_string) || |
94 response_string.empty()) { | 94 response_string.empty()) { |
95 LOG(ERROR) << "GCM channel response failed to be retrieved."; | 95 LOG(ERROR) << "GCM channel response failed to be retrieved."; |
96 return false; | 96 return false; |
97 } | 97 } |
98 | 98 |
99 gcm_proto::ExperimentStatusResponse response_proto; | 99 sync_pb::ExperimentStatusResponse response_proto; |
100 if (!response_proto.ParseFromString(response_string)) { | 100 if (!response_proto.ParseFromString(response_string)) { |
101 LOG(ERROR) << "GCM channel response failed to be parse as proto."; | 101 LOG(ERROR) << "GCM channel response failed to be parse as proto."; |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 bool enabled = true; | 105 bool enabled = true; |
106 if (response_proto.has_gcm_channel() && | 106 for (int i = 0; i < response_proto.experiment_size(); ++i) { |
Nicolas Zea
2014/10/08 01:02:20
we're only ever going to get back the experiments
fgorski
2014/10/08 16:43:42
Done.
| |
107 response_proto.gcm_channel().has_enabled()) { | 107 if (response_proto.experiment(i).has_gcm_channel() && |
108 enabled = response_proto.gcm_channel().enabled(); | 108 response_proto.experiment(i).gcm_channel().has_enabled()) { |
109 enabled = response_proto.experiment(i).gcm_channel().enabled(); | |
110 break; | |
111 } | |
109 } | 112 } |
110 | 113 |
111 int poll_interval_seconds; | 114 int poll_interval_seconds; |
112 if (response_proto.has_poll_interval_seconds()) | 115 if (response_proto.has_poll_interval_seconds()) |
113 poll_interval_seconds = response_proto.poll_interval_seconds(); | 116 poll_interval_seconds = response_proto.poll_interval_seconds(); |
114 else | 117 else |
115 poll_interval_seconds = kDefaultPollIntervalSeconds; | 118 poll_interval_seconds = kDefaultPollIntervalSeconds; |
116 if (poll_interval_seconds < kMinPollIntervalSeconds) | 119 if (poll_interval_seconds < kMinPollIntervalSeconds) |
117 poll_interval_seconds = kMinPollIntervalSeconds; | 120 poll_interval_seconds = kMinPollIntervalSeconds; |
118 | 121 |
(...skipping 18 matching lines...) Expand all 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 |