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

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

Issue 635093002: [GCM] Updating GCM Status Syncer to the new Experiment Status pb (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing CR comments 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 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
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
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 if (response_proto.experiment_size() == 1 &&
107 response_proto.gcm_channel().has_enabled()) { 107 response_proto.experiment(0).has_gcm_channel() &&
108 enabled = response_proto.gcm_channel().enabled(); 108 response_proto.experiment(0).gcm_channel().has_enabled()) {
109 enabled = response_proto.experiment(0).gcm_channel().enabled();
109 } 110 }
110 111
111 int poll_interval_seconds; 112 int poll_interval_seconds;
112 if (response_proto.has_poll_interval_seconds()) 113 if (response_proto.has_poll_interval_seconds())
113 poll_interval_seconds = response_proto.poll_interval_seconds(); 114 poll_interval_seconds = response_proto.poll_interval_seconds();
114 else 115 else
115 poll_interval_seconds = kDefaultPollIntervalSeconds; 116 poll_interval_seconds = kDefaultPollIntervalSeconds;
116 if (poll_interval_seconds < kMinPollIntervalSeconds) 117 if (poll_interval_seconds < kMinPollIntervalSeconds)
117 poll_interval_seconds = kMinPollIntervalSeconds; 118 poll_interval_seconds = kMinPollIntervalSeconds;
118 119
(...skipping 18 matching lines...) Expand all
137 weak_ptr_factory_.GetWeakPtr(), 138 weak_ptr_factory_.GetWeakPtr(),
138 false), 139 false),
139 backoff_entry_.GetTimeUntilRelease()); 140 backoff_entry_.GetTimeUntilRelease());
140 return; 141 return;
141 } 142 }
142 143
143 Start(); 144 Start();
144 } 145 }
145 146
146 } // namespace gcm 147 } // 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