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

Side by Side Diff: components/safe_browsing_db/v4_update_protocol_manager.cc

Issue 2356443002: Set client_id and client_version in requests sent to SafeBrowsing (Closed)
Patch Set: Make GetBase64SerializedUpdateRequestProto non static Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/safe_browsing_db/v4_update_protocol_manager.h" 5 #include "components/safe_browsing_db/v4_update_protocol_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64url.h" 9 #include "base/base64url.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 base::TimeDelta interval) { 185 base::TimeDelta interval) {
186 DCHECK(CalledOnValidThread()); 186 DCHECK(CalledOnValidThread());
187 DCHECK(interval >= base::TimeDelta()); 187 DCHECK(interval >= base::TimeDelta());
188 188
189 // Unschedule any current timer. 189 // Unschedule any current timer.
190 update_timer_.Stop(); 190 update_timer_.Stop();
191 update_timer_.Start(FROM_HERE, interval, this, 191 update_timer_.Start(FROM_HERE, interval, this,
192 &V4UpdateProtocolManager::IssueUpdateRequest); 192 &V4UpdateProtocolManager::IssueUpdateRequest);
193 } 193 }
194 194
195 // static 195 std::string V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto() {
196 std::string V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( 196 DCHECK(!store_state_map_->empty());
197 const StoreStateMap& store_state_map) {
198 DCHECK(!store_state_map.empty());
199 // Build the request. Client info and client states are not added to the 197 // Build the request. Client info and client states are not added to the
200 // request protocol buffer. Client info is passed as params in the url. 198 // request protocol buffer. Client info is passed as params in the url.
201 FetchThreatListUpdatesRequest request; 199 FetchThreatListUpdatesRequest request;
202 for (const auto& entry : store_state_map) { 200 for (const auto& entry : *store_state_map_) {
203 const auto& list_to_update = entry.first; 201 const auto& list_to_update = entry.first;
204 const auto& state = entry.second; 202 const auto& state = entry.second;
205 ListUpdateRequest* list_update_request = request.add_list_update_requests(); 203 ListUpdateRequest* list_update_request = request.add_list_update_requests();
206 list_update_request->set_platform_type(list_to_update.platform_type); 204 list_update_request->set_platform_type(list_to_update.platform_type);
207 list_update_request->set_threat_entry_type( 205 list_update_request->set_threat_entry_type(
208 list_to_update.threat_entry_type); 206 list_to_update.threat_entry_type);
209 list_update_request->set_threat_type(list_to_update.threat_type); 207 list_update_request->set_threat_type(list_to_update.threat_type);
210 208
211 if (!state.empty()) { 209 if (!state.empty()) {
212 list_update_request->set_state(state); 210 list_update_request->set_state(state);
213 } 211 }
214 212
215 list_update_request->mutable_constraints()->add_supported_compressions(RAW); 213 list_update_request->mutable_constraints()->add_supported_compressions(RAW);
216 list_update_request->mutable_constraints()->add_supported_compressions( 214 list_update_request->mutable_constraints()->add_supported_compressions(
217 RICE); 215 RICE);
218 } 216 }
219 217
218 V4ProtocolManagerUtil::SetClientInfoFromConfig(request.mutable_client(),
219 config_);
220
220 // Serialize and Base64 encode. 221 // Serialize and Base64 encode.
221 std::string req_data, req_base64; 222 std::string req_data, req_base64;
222 request.SerializeToString(&req_data); 223 request.SerializeToString(&req_data);
223 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING, 224 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING,
224 &req_base64); 225 &req_base64);
225 return req_base64; 226 return req_base64;
226 } 227 }
227 228
228 bool V4UpdateProtocolManager::ParseUpdateResponse( 229 bool V4UpdateProtocolManager::ParseUpdateResponse(
229 const std::string& data, 230 const std::string& data,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 271
271 void V4UpdateProtocolManager::IssueUpdateRequest() { 272 void V4UpdateProtocolManager::IssueUpdateRequest() {
272 DCHECK(CalledOnValidThread()); 273 DCHECK(CalledOnValidThread());
273 274
274 // If an update request is already pending, record and return silently. 275 // If an update request is already pending, record and return silently.
275 if (request_.get()) { 276 if (request_.get()) {
276 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR); 277 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR);
277 return; 278 return;
278 } 279 }
279 280
280 std::string req_base64 = 281 std::string req_base64 = GetBase64SerializedUpdateRequestProto();
281 GetBase64SerializedUpdateRequestProto(*store_state_map_.get());
282 GURL update_url; 282 GURL update_url;
283 net::HttpRequestHeaders headers; 283 net::HttpRequestHeaders headers;
284 GetUpdateUrlAndHeaders(req_base64, &update_url, &headers); 284 GetUpdateUrlAndHeaders(req_base64, &update_url, &headers);
285 285
286 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( 286 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
287 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); 287 url_fetcher_id_++, update_url, net::URLFetcher::GET, this);
288 fetcher->SetExtraRequestHeaders(headers.ToString()); 288 fetcher->SetExtraRequestHeaders(headers.ToString());
289 289
290 request_.reset(fetcher.release()); 290 request_.reset(fetcher.release());
291 291
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( 350 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders(
351 const std::string& req_base64, 351 const std::string& req_base64,
352 GURL* gurl, 352 GURL* gurl,
353 net::HttpRequestHeaders* headers) const { 353 net::HttpRequestHeaders* headers) const {
354 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( 354 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(
355 req_base64, "threatListUpdates:fetch", config_, gurl, headers); 355 req_base64, "threatListUpdates:fetch", config_, gurl, headers);
356 } 356 }
357 357
358 } // namespace safe_browsing 358 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698