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

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: 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // static
196 std::string V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto( 196 std::string V4UpdateProtocolManager::GetBase64SerializedUpdateRequestProto(
197 const StoreStateMap& store_state_map) { 197 const StoreStateMap& store_state_map,
198 const V4ProtocolConfig& config) {
198 DCHECK(!store_state_map.empty()); 199 DCHECK(!store_state_map.empty());
199 // Build the request. Client info and client states are not added to the 200 // 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. 201 // request protocol buffer. Client info is passed as params in the url.
201 FetchThreatListUpdatesRequest request; 202 FetchThreatListUpdatesRequest request;
202 for (const auto& entry : store_state_map) { 203 for (const auto& entry : store_state_map) {
203 const auto& list_to_update = entry.first; 204 const auto& list_to_update = entry.first;
204 const auto& state = entry.second; 205 const auto& state = entry.second;
205 ListUpdateRequest* list_update_request = request.add_list_update_requests(); 206 ListUpdateRequest* list_update_request = request.add_list_update_requests();
206 list_update_request->set_platform_type(list_to_update.platform_type); 207 list_update_request->set_platform_type(list_to_update.platform_type);
207 list_update_request->set_threat_entry_type( 208 list_update_request->set_threat_entry_type(
208 list_to_update.threat_entry_type); 209 list_to_update.threat_entry_type);
209 list_update_request->set_threat_type(list_to_update.threat_type); 210 list_update_request->set_threat_type(list_to_update.threat_type);
210 211
211 if (!state.empty()) { 212 if (!state.empty()) {
212 list_update_request->set_state(state); 213 list_update_request->set_state(state);
213 } 214 }
214 215
215 list_update_request->mutable_constraints()->add_supported_compressions(RAW); 216 list_update_request->mutable_constraints()->add_supported_compressions(RAW);
216 list_update_request->mutable_constraints()->add_supported_compressions( 217 list_update_request->mutable_constraints()->add_supported_compressions(
217 RICE); 218 RICE);
218 } 219 }
219 220
221 V4ProtocolManagerUtil::SetClientInfoFromConfig(request.mutable_client(),
222 config);
223
220 // Serialize and Base64 encode. 224 // Serialize and Base64 encode.
221 std::string req_data, req_base64; 225 std::string req_data, req_base64;
222 request.SerializeToString(&req_data); 226 request.SerializeToString(&req_data);
223 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING, 227 base::Base64UrlEncode(req_data, base::Base64UrlEncodePolicy::INCLUDE_PADDING,
224 &req_base64); 228 &req_base64);
225 return req_base64; 229 return req_base64;
226 } 230 }
227 231
228 bool V4UpdateProtocolManager::ParseUpdateResponse( 232 bool V4UpdateProtocolManager::ParseUpdateResponse(
229 const std::string& data, 233 const std::string& data,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 void V4UpdateProtocolManager::IssueUpdateRequest() { 275 void V4UpdateProtocolManager::IssueUpdateRequest() {
272 DCHECK(CalledOnValidThread()); 276 DCHECK(CalledOnValidThread());
273 277
274 // If an update request is already pending, record and return silently. 278 // If an update request is already pending, record and return silently.
275 if (request_.get()) { 279 if (request_.get()) {
276 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR); 280 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR);
277 return; 281 return;
278 } 282 }
279 283
280 std::string req_base64 = 284 std::string req_base64 =
281 GetBase64SerializedUpdateRequestProto(*store_state_map_.get()); 285 GetBase64SerializedUpdateRequestProto(*store_state_map_.get(), config_);
282 GURL update_url; 286 GURL update_url;
283 net::HttpRequestHeaders headers; 287 net::HttpRequestHeaders headers;
284 GetUpdateUrlAndHeaders(req_base64, &update_url, &headers); 288 GetUpdateUrlAndHeaders(req_base64, &update_url, &headers);
285 289
286 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( 290 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
287 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); 291 url_fetcher_id_++, update_url, net::URLFetcher::GET, this);
288 fetcher->SetExtraRequestHeaders(headers.ToString()); 292 fetcher->SetExtraRequestHeaders(headers.ToString());
289 293
290 request_.reset(fetcher.release()); 294 request_.reset(fetcher.release());
291 295
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 353
350 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( 354 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders(
351 const std::string& req_base64, 355 const std::string& req_base64,
352 GURL* gurl, 356 GURL* gurl,
353 net::HttpRequestHeaders* headers) const { 357 net::HttpRequestHeaders* headers) const {
354 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( 358 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(
355 req_base64, "threatListUpdates:fetch", config_, gurl, headers); 359 req_base64, "threatListUpdates:fetch", config_, gurl, headers);
356 } 360 }
357 361
358 } // namespace safe_browsing 362 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698