Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: components/gcm_driver/gcm_channel_status_request.cc

Issue 658223003: Merge to M39: [GCM] Updating GCM Status Syncer to the new Experiment Status pb (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kRequestContentType[] = "application/octet-stream"; 22 const char kRequestContentType[] = "application/octet-stream";
23 const char kGCMChannelTag[] = "gcm_channel"; 23 const char kGCMChannelTag[] = "gcm_channel";
24 const int kDefaultPollIntervalSeconds = 60 * 60; // 60 minutes. 24 const int kDefaultPollIntervalSeconds = 60 * 60; // 60 minutes.
25 const int kMinPollIntervalSeconds = 30 * 60; // 30 minutes. 25 const int kMinPollIntervalSeconds = 30 * 60; // 30 minutes.
(...skipping 24 matching lines...) Expand all
50 // static 50 // static
51 int GCMChannelStatusRequest::min_poll_interval_seconds() { 51 int GCMChannelStatusRequest::min_poll_interval_seconds() {
52 return kMinPollIntervalSeconds; 52 return kMinPollIntervalSeconds;
53 } 53 }
54 54
55 void GCMChannelStatusRequest::Start() { 55 void GCMChannelStatusRequest::Start() {
56 DCHECK(!url_fetcher_.get()); 56 DCHECK(!url_fetcher_.get());
57 57
58 GURL request_url(channel_status_request_url_); 58 GURL request_url(channel_status_request_url_);
59 59
60 gcm_proto::ExperimentStatusRequest proto_data; 60 sync_pb::ExperimentStatusRequest proto_data;
61 proto_data.add_experiment_name(kGCMChannelTag); 61 proto_data.add_experiment_name(kGCMChannelTag);
62 std::string upload_data; 62 std::string upload_data;
63 DCHECK(proto_data.SerializeToString(&upload_data)); 63 DCHECK(proto_data.SerializeToString(&upload_data));
64 64
65 url_fetcher_.reset( 65 url_fetcher_.reset(
66 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this)); 66 net::URLFetcher::Create(request_url, net::URLFetcher::POST, this));
67 url_fetcher_->SetRequestContext(request_context_getter_.get()); 67 url_fetcher_->SetRequestContext(request_context_getter_.get());
68 url_fetcher_->AddExtraRequestHeader("User-Agent: " + user_agent_); 68 url_fetcher_->AddExtraRequestHeader("User-Agent: " + user_agent_);
69 url_fetcher_->SetUploadData(kRequestContentType, upload_data); 69 url_fetcher_->SetUploadData(kRequestContentType, upload_data);
70 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 70 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
(...skipping 21 matching lines...) Expand all
92 return false; 92 return false;
93 } 93 }
94 94
95 std::string response_string; 95 std::string response_string;
96 if (!source->GetResponseAsString(&response_string) || 96 if (!source->GetResponseAsString(&response_string) ||
97 response_string.empty()) { 97 response_string.empty()) {
98 LOG(ERROR) << "GCM channel response failed to be retrieved."; 98 LOG(ERROR) << "GCM channel response failed to be retrieved.";
99 return false; 99 return false;
100 } 100 }
101 101
102 gcm_proto::ExperimentStatusResponse response_proto; 102 sync_pb::ExperimentStatusResponse response_proto;
103 if (!response_proto.ParseFromString(response_string)) { 103 if (!response_proto.ParseFromString(response_string)) {
104 LOG(ERROR) << "GCM channel response failed to be parse as proto."; 104 LOG(ERROR) << "GCM channel response failed to be parse as proto.";
105 return false; 105 return false;
106 } 106 }
107 107
108 bool enabled = true; 108 bool enabled = true;
109 if (response_proto.has_gcm_channel() && 109 if (response_proto.experiment_size() == 1 &&
110 response_proto.gcm_channel().has_enabled()) { 110 response_proto.experiment(0).has_gcm_channel() &&
111 enabled = response_proto.gcm_channel().enabled(); 111 response_proto.experiment(0).gcm_channel().has_enabled()) {
112 enabled = response_proto.experiment(0).gcm_channel().enabled();
112 } 113 }
113 114
114 int poll_interval_seconds; 115 int poll_interval_seconds;
115 if (response_proto.has_poll_interval_seconds()) 116 if (response_proto.has_poll_interval_seconds())
116 poll_interval_seconds = response_proto.poll_interval_seconds(); 117 poll_interval_seconds = response_proto.poll_interval_seconds();
117 else 118 else
118 poll_interval_seconds = kDefaultPollIntervalSeconds; 119 poll_interval_seconds = kDefaultPollIntervalSeconds;
119 if (poll_interval_seconds < kMinPollIntervalSeconds) 120 if (poll_interval_seconds < kMinPollIntervalSeconds)
120 poll_interval_seconds = kMinPollIntervalSeconds; 121 poll_interval_seconds = kMinPollIntervalSeconds;
121 122
(...skipping 18 matching lines...) Expand all
140 weak_ptr_factory_.GetWeakPtr(), 141 weak_ptr_factory_.GetWeakPtr(),
141 false), 142 false),
142 backoff_entry_.GetTimeUntilRelease()); 143 backoff_entry_.GetTimeUntilRelease());
143 return; 144 return;
144 } 145 }
145 146
146 Start(); 147 Start();
147 } 148 }
148 149
149 } // namespace gcm 150 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/DEPS ('k') | components/gcm_driver/gcm_channel_status_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698