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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 12313141: Use DownloadItem directly in DownloadProtectionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win unit_tests fixes Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 DOWNLOAD_HASH_CHECKS_TOTAL, 133 DOWNLOAD_HASH_CHECKS_TOTAL,
134 DOWNLOAD_HASH_CHECKS_MALWARE, 134 DOWNLOAD_HASH_CHECKS_MALWARE,
135 135
136 // Memory space for histograms is determined by the max. 136 // Memory space for histograms is determined by the max.
137 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. 137 // ALWAYS ADD NEW VALUES BEFORE THIS ONE.
138 DOWNLOAD_CHECKS_MAX 138 DOWNLOAD_CHECKS_MAX
139 }; 139 };
140 } // namespace 140 } // namespace
141 141
142 DownloadProtectionService::DownloadInfo::DownloadInfo()
143 : total_bytes(0), user_initiated(false), zipped_executable(false) {}
144
145 DownloadProtectionService::DownloadInfo::~DownloadInfo() {}
146
147 std::string DownloadProtectionService::DownloadInfo::DebugString() const {
148 std::string chain;
149 for (size_t i = 0; i < download_url_chain.size(); ++i) {
150 chain += download_url_chain[i].spec();
151 if (i < download_url_chain.size() - 1) {
152 chain += " -> ";
153 }
154 }
155 return base::StringPrintf(
156 "DownloadInfo {addr:0x%p, download_url_chain:[%s], local_file:%"
157 PRFilePath ", target_file:%" PRFilePath ", referrer_url:%s, "
158 "sha256_hash:%s, total_bytes:%" PRId64 ", user_initiated: %s, "
159 "zipped_executable: %s}",
160 reinterpret_cast<const void*>(this),
161 chain.c_str(),
162 local_file.value().c_str(),
163 target_file.value().c_str(),
164 referrer_url.spec().c_str(),
165 base::HexEncode(sha256_hash.data(), sha256_hash.size()).c_str(),
166 total_bytes,
167 user_initiated ? "true" : "false",
168 zipped_executable ? "true" : "false");
169 }
170
171 // static
172 DownloadProtectionService::DownloadInfo
173 DownloadProtectionService::DownloadInfo::FromDownloadItem(
174 const content::DownloadItem& item) {
175 DownloadInfo download_info;
176 download_info.target_file = item.GetTargetFilePath();
177 download_info.sha256_hash = item.GetHash();
178 download_info.local_file = item.GetFullPath();
179 download_info.download_url_chain = item.GetUrlChain();
180 download_info.referrer_url = item.GetReferrerUrl();
181 download_info.total_bytes = item.GetTotalBytes();
182 download_info.remote_address = item.GetRemoteAddress();
183 download_info.user_initiated = item.HasUserGesture();
184 return download_info;
185 }
186
187 // Parent SafeBrowsing::Client class used to lookup the bad binary 142 // Parent SafeBrowsing::Client class used to lookup the bad binary
188 // URL and digest list. There are two sub-classes (one for each list). 143 // URL and digest list. There are two sub-classes (one for each list).
189 class DownloadSBClient 144 class DownloadSBClient
190 : public SafeBrowsingDatabaseManager::Client, 145 : public SafeBrowsingDatabaseManager::Client,
191 public base::RefCountedThreadSafe<DownloadSBClient> { 146 public base::RefCountedThreadSafe<DownloadSBClient> {
192 public: 147 public:
193 DownloadSBClient( 148 DownloadSBClient(
194 const DownloadProtectionService::DownloadInfo& info, 149 const content::DownloadItem& item,
195 const DownloadProtectionService::CheckDownloadCallback& callback, 150 const DownloadProtectionService::CheckDownloadCallback& callback,
196 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, 151 const scoped_refptr<SafeBrowsingUIManager>& ui_manager,
197 SBStatsType total_type, 152 SBStatsType total_type,
198 SBStatsType dangerous_type) 153 SBStatsType dangerous_type)
199 : info_(info), 154 : sha256_hash_(item.GetHash()),
155 url_chain_(item.GetUrlChain()),
156 referrer_url_(item.GetReferrerUrl()),
200 callback_(callback), 157 callback_(callback),
201 ui_manager_(ui_manager), 158 ui_manager_(ui_manager),
202 start_time_(base::TimeTicks::Now()), 159 start_time_(base::TimeTicks::Now()),
203 total_type_(total_type), 160 total_type_(total_type),
204 dangerous_type_(dangerous_type) {} 161 dangerous_type_(dangerous_type) {}
205 162
206 virtual void StartCheck() = 0; 163 virtual void StartCheck() = 0;
207 virtual bool IsDangerous(SBThreatType threat_type) const = 0; 164 virtual bool IsDangerous(SBThreatType threat_type) const = 0;
208 165
209 protected: 166 protected:
(...skipping 14 matching lines...) Expand all
224 BrowserThread::PostTask( 181 BrowserThread::PostTask(
225 BrowserThread::UI, 182 BrowserThread::UI,
226 FROM_HERE, 183 FROM_HERE,
227 base::Bind(&DownloadSBClient::ReportMalware, 184 base::Bind(&DownloadSBClient::ReportMalware,
228 this, threat_type)); 185 this, threat_type));
229 } 186 }
230 } 187 }
231 188
232 void ReportMalware(SBThreatType threat_type) { 189 void ReportMalware(SBThreatType threat_type) {
233 std::string post_data; 190 std::string post_data;
234 if (!info_.sha256_hash.empty()) 191 if (!sha256_hash_.empty())
235 post_data += base::HexEncode(info_.sha256_hash.data(), 192 post_data += base::HexEncode(sha256_hash_.data(),
236 info_.sha256_hash.size()) + "\n"; 193 sha256_hash_.size()) + "\n";
237 for (size_t i = 0; i < info_.download_url_chain.size(); ++i) { 194 for (size_t i = 0; i < url_chain_.size(); ++i) {
238 post_data += info_.download_url_chain[i].spec() + "\n"; 195 post_data += url_chain_[i].spec() + "\n";
239 } 196 }
240 ui_manager_->ReportSafeBrowsingHit( 197 ui_manager_->ReportSafeBrowsingHit(
241 info_.download_url_chain.back(), // malicious_url 198 url_chain_.back(), // malicious_url
242 info_.download_url_chain.front(), // page_url 199 url_chain_.front(), // page_url
243 info_.referrer_url, 200 referrer_url_,
244 true, // is_subresource 201 true, // is_subresource
245 threat_type, 202 threat_type,
246 post_data); 203 post_data);
247 } 204 }
248 205
249 void UpdateDownloadCheckStats(SBStatsType stat_type) { 206 void UpdateDownloadCheckStats(SBStatsType stat_type) {
250 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks", 207 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadChecks",
251 stat_type, 208 stat_type,
252 DOWNLOAD_CHECKS_MAX); 209 DOWNLOAD_CHECKS_MAX);
253 } 210 }
254 211
255 DownloadProtectionService::DownloadInfo info_; 212 std::string sha256_hash_;
213 std::vector<GURL> url_chain_;
214 GURL referrer_url_;
256 DownloadProtectionService::CheckDownloadCallback callback_; 215 DownloadProtectionService::CheckDownloadCallback callback_;
257 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 216 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
258 base::TimeTicks start_time_; 217 base::TimeTicks start_time_;
259 218
260 private: 219 private:
261 const SBStatsType total_type_; 220 const SBStatsType total_type_;
262 const SBStatsType dangerous_type_; 221 const SBStatsType dangerous_type_;
263 222
264 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient); 223 DISALLOW_COPY_AND_ASSIGN(DownloadSBClient);
265 }; 224 };
266 225
267 class DownloadUrlSBClient : public DownloadSBClient { 226 class DownloadUrlSBClient : public DownloadSBClient {
268 public: 227 public:
269 DownloadUrlSBClient( 228 DownloadUrlSBClient(
270 const DownloadProtectionService::DownloadInfo& info, 229 const content::DownloadItem& item,
271 const DownloadProtectionService::CheckDownloadCallback& callback, 230 const DownloadProtectionService::CheckDownloadCallback& callback,
272 const scoped_refptr<SafeBrowsingUIManager>& ui_manager, 231 const scoped_refptr<SafeBrowsingUIManager>& ui_manager,
273 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) 232 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager)
274 : DownloadSBClient(info, callback, ui_manager, 233 : DownloadSBClient(item, callback, ui_manager,
275 DOWNLOAD_URL_CHECKS_TOTAL, 234 DOWNLOAD_URL_CHECKS_TOTAL,
276 DOWNLOAD_URL_CHECKS_MALWARE), 235 DOWNLOAD_URL_CHECKS_MALWARE),
277 database_manager_(database_manager) { } 236 database_manager_(database_manager) { }
278 237
279 virtual void StartCheck() OVERRIDE { 238 virtual void StartCheck() OVERRIDE {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
281 if (!database_manager_ || database_manager_->CheckDownloadUrl( 240 if (!database_manager_ || database_manager_->CheckDownloadUrl(
282 info_.download_url_chain, this)) { 241 url_chain_, this)) {
283 CheckDone(SB_THREAT_TYPE_SAFE); 242 CheckDone(SB_THREAT_TYPE_SAFE);
284 } else { 243 } else {
285 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr. 244 AddRef(); // SafeBrowsingService takes a pointer not a scoped_refptr.
286 } 245 }
287 } 246 }
288 247
289 virtual bool IsDangerous(SBThreatType threat_type) const OVERRIDE { 248 virtual bool IsDangerous(SBThreatType threat_type) const OVERRIDE {
290 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL; 249 return threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL;
291 } 250 }
292 251
(...skipping 11 matching lines...) Expand all
304 private: 263 private:
305 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 264 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
306 265
307 DISALLOW_COPY_AND_ASSIGN(DownloadUrlSBClient); 266 DISALLOW_COPY_AND_ASSIGN(DownloadUrlSBClient);
308 }; 267 };
309 268
310 class DownloadProtectionService::CheckClientDownloadRequest 269 class DownloadProtectionService::CheckClientDownloadRequest
311 : public base::RefCountedThreadSafe< 270 : public base::RefCountedThreadSafe<
312 DownloadProtectionService::CheckClientDownloadRequest, 271 DownloadProtectionService::CheckClientDownloadRequest,
313 BrowserThread::DeleteOnUIThread>, 272 BrowserThread::DeleteOnUIThread>,
314 public net::URLFetcherDelegate { 273 public net::URLFetcherDelegate,
274 public content::DownloadItem::Observer {
315 public: 275 public:
316 CheckClientDownloadRequest( 276 CheckClientDownloadRequest(
317 const DownloadInfo& info, 277 content::DownloadItem* item,
318 const CheckDownloadCallback& callback, 278 const CheckDownloadCallback& callback,
319 DownloadProtectionService* service, 279 DownloadProtectionService* service,
320 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, 280 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
321 SignatureUtil* signature_util) 281 SignatureUtil* signature_util)
322 : info_(info), 282 : item_(item),
283 zipped_executable_(false),
323 callback_(callback), 284 callback_(callback),
324 service_(service), 285 service_(service),
325 signature_util_(signature_util), 286 signature_util_(signature_util),
326 database_manager_(database_manager), 287 database_manager_(database_manager),
327 pingback_enabled_(service_->enabled()), 288 pingback_enabled_(service_->enabled()),
328 finished_(false), 289 finished_(false),
329 type_(ClientDownloadRequest::WIN_EXECUTABLE), 290 type_(ClientDownloadRequest::WIN_EXECUTABLE),
330 ALLOW_THIS_IN_INITIALIZER_LIST(weakptr_factory_(this)), 291 ALLOW_THIS_IN_INITIALIZER_LIST(weakptr_factory_(this)),
331 start_time_(base::TimeTicks::Now()) { 292 start_time_(base::TimeTicks::Now()) {
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
294 item_->AddObserver(this);
333 } 295 }
334 296
335 void Start() { 297 void Start() {
336 VLOG(2) << "Starting SafeBrowsing download check for: " 298 VLOG(2) << "Starting SafeBrowsing download check for: "
337 << info_.DebugString(); 299 << item_->DebugString(true);
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
339 // TODO(noelutz): implement some cache to make sure we don't issue the same 301 // TODO(noelutz): implement some cache to make sure we don't issue the same
340 // request over and over again if a user downloads the same binary multiple 302 // request over and over again if a user downloads the same binary multiple
341 // times. 303 // times.
342 DownloadCheckResultReason reason = REASON_MAX; 304 DownloadCheckResultReason reason = REASON_MAX;
343 if (!IsSupportedDownload(info_, &reason, &type_)) { 305 if (!IsSupportedDownload(
306 *item_, item_->GetTargetFilePath(), &reason, &type_)) {
344 switch (reason) { 307 switch (reason) {
345 case REASON_EMPTY_URL_CHAIN: 308 case REASON_EMPTY_URL_CHAIN:
346 case REASON_INVALID_URL: 309 case REASON_INVALID_URL:
347 RecordImprovedProtectionStats(reason); 310 RecordImprovedProtectionStats(reason);
348 PostFinishTask(SAFE); 311 PostFinishTask(SAFE);
349 return; 312 return;
350 313
351 case REASON_NOT_BINARY_FILE: 314 case REASON_NOT_BINARY_FILE:
352 RecordFileExtensionType(info_.target_file); 315 RecordFileExtensionType(item_->GetTargetFilePath());
353 RecordImprovedProtectionStats(reason); 316 RecordImprovedProtectionStats(reason);
354 PostFinishTask(SAFE); 317 PostFinishTask(SAFE);
355 return; 318 return;
356 319
357 default: 320 default:
358 // We only expect the reasons explicitly handled above. 321 // We only expect the reasons explicitly handled above.
359 NOTREACHED(); 322 NOTREACHED();
360 } 323 }
361 } 324 }
362 RecordFileExtensionType(info_.target_file); 325 RecordFileExtensionType(item_->GetTargetFilePath());
363 326
364 // Compute features from the file contents. Note that we record histograms 327 // Compute features from the file contents. Note that we record histograms
365 // based on the result, so this runs regardless of whether the pingbacks 328 // based on the result, so this runs regardless of whether the pingbacks
366 // are enabled. 329 // are enabled.
367 if (info_.target_file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) { 330 if (item_->GetTargetFilePath().MatchesExtension(
331 FILE_PATH_LITERAL(".zip"))) {
368 StartExtractZipFeatures(); 332 StartExtractZipFeatures();
369 } else { 333 } else {
370 DCHECK(!download_protection_util::IsArchiveFile(info_.target_file)); 334 DCHECK(!download_protection_util::IsArchiveFile(
335 item_->GetTargetFilePath()));
371 StartExtractSignatureFeatures(); 336 StartExtractSignatureFeatures();
372 } 337 }
373 } 338 }
374 339
375 // Start a timeout to cancel the request if it takes too long. 340 // Start a timeout to cancel the request if it takes too long.
376 // This should only be called after we have finished accessing the file. 341 // This should only be called after we have finished accessing the file.
377 void StartTimeout() { 342 void StartTimeout() {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
379 if (!service_) { 344 if (!service_) {
380 // Request has already been cancelled. 345 // Request has already been cancelled.
(...skipping 21 matching lines...) Expand all
402 // might be destroyed before the URLFetcher completes. Cancel the 367 // might be destroyed before the URLFetcher completes. Cancel the
403 // fetcher so it does not try to invoke OnURLFetchComplete. 368 // fetcher so it does not try to invoke OnURLFetchComplete.
404 fetcher_.reset(); 369 fetcher_.reset();
405 } 370 }
406 // Note: If there is no fetcher, then some callback is still holding a 371 // Note: If there is no fetcher, then some callback is still holding a
407 // reference to this object. We'll eventually wind up in some method on 372 // reference to this object. We'll eventually wind up in some method on
408 // the UI thread that will call FinishRequest() again. If FinishRequest() 373 // the UI thread that will call FinishRequest() again. If FinishRequest()
409 // is called a second time, it will be a no-op. 374 // is called a second time, it will be a no-op.
410 } 375 }
411 376
377 // content::DownloadItem::Observer implementation.
378 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE {
379 Cancel();
asanka 2013/02/27 18:06:43 Nit: DCHECK(item_ == NULL)
mattm 2013/02/28 01:33:07 Done.
380 }
381
412 // From the net::URLFetcherDelegate interface. 382 // From the net::URLFetcherDelegate interface.
413 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { 383 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
415 DCHECK_EQ(source, fetcher_.get()); 385 DCHECK_EQ(source, fetcher_.get());
416 VLOG(2) << "Received a response for URL: " 386 VLOG(2) << "Received a response for URL: "
417 << info_.download_url_chain.back() << ": success=" 387 << item_->GetUrlChain().back() << ": success="
418 << source->GetStatus().is_success() << " response_code=" 388 << source->GetStatus().is_success() << " response_code="
419 << source->GetResponseCode(); 389 << source->GetResponseCode();
420 DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED; 390 DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED;
421 DownloadCheckResult result = SAFE; 391 DownloadCheckResult result = SAFE;
422 if (source->GetStatus().is_success() && 392 if (source->GetStatus().is_success() &&
423 net::HTTP_OK == source->GetResponseCode()) { 393 net::HTTP_OK == source->GetResponseCode()) {
424 ClientDownloadResponse response; 394 ClientDownloadResponse response;
425 std::string data; 395 std::string data;
426 bool got_data = source->GetResponseAsString(&data); 396 bool got_data = source->GetResponseAsString(&data);
427 DCHECK(got_data); 397 DCHECK(got_data);
428 if (!response.ParseFromString(data)) { 398 if (!response.ParseFromString(data)) {
429 reason = REASON_INVALID_RESPONSE_PROTO; 399 reason = REASON_INVALID_RESPONSE_PROTO;
430 } else if (response.verdict() == ClientDownloadResponse::SAFE) { 400 } else if (response.verdict() == ClientDownloadResponse::SAFE) {
431 reason = REASON_DOWNLOAD_SAFE; 401 reason = REASON_DOWNLOAD_SAFE;
432 } else if (service_ && !service_->IsSupportedDownload(info_)) { 402 } else if (service_ && !service_->IsSupportedDownload(
403 *item_, item_->GetTargetFilePath())) {
433 // The client of the download protection service assumes that we don't 404 // The client of the download protection service assumes that we don't
434 // support this download so we cannot return any other verdict than 405 // support this download so we cannot return any other verdict than
435 // SAFE even if the server says it's dangerous to download this file. 406 // SAFE even if the server says it's dangerous to download this file.
436 // Note: if service_ is NULL we already cancelled the request and 407 // Note: if service_ is NULL we already cancelled the request and
437 // returned SAFE. 408 // returned SAFE.
438 reason = REASON_DOWNLOAD_NOT_SUPPORTED; 409 reason = REASON_DOWNLOAD_NOT_SUPPORTED;
439 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { 410 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) {
440 reason = REASON_DOWNLOAD_DANGEROUS; 411 reason = REASON_DOWNLOAD_DANGEROUS;
441 result = DANGEROUS; 412 result = DANGEROUS;
442 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { 413 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) {
443 reason = REASON_DOWNLOAD_UNCOMMON; 414 reason = REASON_DOWNLOAD_UNCOMMON;
444 result = UNCOMMON; 415 result = UNCOMMON;
445 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS_HOST) { 416 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS_HOST) {
446 reason = REASON_DOWNLOAD_DANGEROUS_HOST; 417 reason = REASON_DOWNLOAD_DANGEROUS_HOST;
447 result = DANGEROUS_HOST; 418 result = DANGEROUS_HOST;
448 } else { 419 } else {
449 LOG(DFATAL) << "Unknown download response verdict: " 420 LOG(DFATAL) << "Unknown download response verdict: "
450 << response.verdict(); 421 << response.verdict();
451 reason = REASON_INVALID_RESPONSE_VERDICT; 422 reason = REASON_INVALID_RESPONSE_VERDICT;
452 } 423 }
453 } 424 }
454 // We don't need the fetcher anymore. 425 // We don't need the fetcher anymore.
455 fetcher_.reset(); 426 fetcher_.reset();
456 RecordImprovedProtectionStats(reason); 427 RecordImprovedProtectionStats(reason);
457 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration", 428 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration",
458 base::TimeTicks::Now() - start_time_); 429 base::TimeTicks::Now() - start_time_);
459 FinishRequest(result); 430 FinishRequest(result);
460 } 431 }
461 432
462 static bool IsSupportedDownload(const DownloadInfo& info, 433 static bool IsSupportedDownload(const content::DownloadItem& item,
434 const base::FilePath& target_path,
463 DownloadCheckResultReason* reason, 435 DownloadCheckResultReason* reason,
464 ClientDownloadRequest::DownloadType* type) { 436 ClientDownloadRequest::DownloadType* type) {
465 if (info.download_url_chain.empty()) { 437 if (item.GetUrlChain().empty()) {
466 *reason = REASON_EMPTY_URL_CHAIN; 438 *reason = REASON_EMPTY_URL_CHAIN;
467 return false; 439 return false;
468 } 440 }
469 const GURL& final_url = info.download_url_chain.back(); 441 const GURL& final_url = item.GetUrlChain().back();
470 if (!final_url.is_valid() || final_url.is_empty() || 442 if (!final_url.is_valid() || final_url.is_empty() ||
471 !final_url.IsStandard() || final_url.SchemeIsFile()) { 443 !final_url.IsStandard() || final_url.SchemeIsFile()) {
472 *reason = REASON_INVALID_URL; 444 *reason = REASON_INVALID_URL;
473 return false; 445 return false;
474 } 446 }
475 if (!download_protection_util::IsBinaryFile(info.target_file)) { 447 if (!download_protection_util::IsBinaryFile(target_path)) {
476 *reason = REASON_NOT_BINARY_FILE; 448 *reason = REASON_NOT_BINARY_FILE;
477 return false; 449 return false;
478 } 450 }
479 *type = GetDownloadType(info.target_file); 451 *type = GetDownloadType(target_path);
480 return true; 452 return true;
481 } 453 }
482 454
483 private: 455 private:
484 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 456 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
485 friend class base::DeleteHelper<CheckClientDownloadRequest>; 457 friend class base::DeleteHelper<CheckClientDownloadRequest>;
486 458
487 virtual ~CheckClientDownloadRequest() { 459 virtual ~CheckClientDownloadRequest() {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
461 DCHECK(item_ == NULL);
489 } 462 }
490 463
491 void OnFileFeatureExtractionDone() { 464 void OnFileFeatureExtractionDone() {
492 // This can run in any thread, since it just posts more messages. 465 // This can run in any thread, since it just posts more messages.
493 466
494 // TODO(noelutz): DownloadInfo should also contain the IP address of 467 // TODO(noelutz): DownloadInfo should also contain the IP address of
495 // every URL in the redirect chain. We also should check whether the 468 // every URL in the redirect chain. We also should check whether the
496 // download URL is hosted on the internal network. 469 // download URL is hosted on the internal network.
497 BrowserThread::PostTask( 470 BrowserThread::PostTask(
498 BrowserThread::IO, 471 BrowserThread::IO,
(...skipping 14 matching lines...) Expand all
513 // The task does not need to block shutdown. 486 // The task does not need to block shutdown.
514 BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( 487 BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
515 FROM_HERE, 488 FROM_HERE,
516 base::Bind(&CheckClientDownloadRequest::ExtractSignatureFeatures, 489 base::Bind(&CheckClientDownloadRequest::ExtractSignatureFeatures,
517 this), 490 this),
518 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 491 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
519 } 492 }
520 493
521 void ExtractSignatureFeatures() { 494 void ExtractSignatureFeatures() {
522 base::TimeTicks start_time = base::TimeTicks::Now(); 495 base::TimeTicks start_time = base::TimeTicks::Now();
523 signature_util_->CheckSignature(info_.local_file, &signature_info_); 496 signature_util_->CheckSignature(item_->GetFullPath(), &signature_info_);
524 bool is_signed = (signature_info_.certificate_chain_size() > 0); 497 bool is_signed = (signature_info_.certificate_chain_size() > 0);
525 if (is_signed) { 498 if (is_signed) {
526 VLOG(2) << "Downloaded a signed binary: " << info_.local_file.value(); 499 VLOG(2) << "Downloaded a signed binary: " << item_->GetFullPath().value();
527 } else { 500 } else {
528 VLOG(2) << "Downloaded an unsigned binary: " << info_.local_file.value(); 501 VLOG(2) << "Downloaded an unsigned binary: "
502 << item_->GetFullPath().value();
529 } 503 }
530 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.SignedBinaryDownload", is_signed); 504 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.SignedBinaryDownload", is_signed);
531 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractSignatureFeaturesTime", 505 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractSignatureFeaturesTime",
532 base::TimeTicks::Now() - start_time); 506 base::TimeTicks::Now() - start_time);
533 507
534 OnFileFeatureExtractionDone(); 508 OnFileFeatureExtractionDone();
535 } 509 }
536 510
537 void StartExtractZipFeatures() { 511 void StartExtractZipFeatures() {
538 zip_analysis_start_time_ = base::TimeTicks::Now(); 512 zip_analysis_start_time_ = base::TimeTicks::Now();
539 // We give the zip analyzer a weak pointer to this object. Since the 513 // We give the zip analyzer a weak pointer to this object. Since the
540 // analyzer is refcounted, it might outlive the request. 514 // analyzer is refcounted, it might outlive the request.
541 analyzer_ = new SandboxedZipAnalyzer( 515 analyzer_ = new SandboxedZipAnalyzer(
542 info_.local_file, 516 item_->GetFullPath(),
543 base::Bind(&CheckClientDownloadRequest::OnZipAnalysisFinished, 517 base::Bind(&CheckClientDownloadRequest::OnZipAnalysisFinished,
544 weakptr_factory_.GetWeakPtr())); 518 weakptr_factory_.GetWeakPtr()));
545 analyzer_->Start(); 519 analyzer_->Start();
546 } 520 }
547 521
548 void OnZipAnalysisFinished(const zip_analyzer::Results& results) { 522 void OnZipAnalysisFinished(const zip_analyzer::Results& results) {
549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
550 if (results.success) { 524 if (results.success) {
551 info_.zipped_executable = results.has_executable; 525 zipped_executable_ = results.has_executable;
552 VLOG(1) << "Zip analysis finished for " << info_.local_file.value() 526 VLOG(1) << "Zip analysis finished for " << item_->GetFullPath().value()
553 << ", has_executable=" << results.has_executable 527 << ", has_executable=" << results.has_executable
554 << " has_archive=" << results.has_archive; 528 << " has_archive=" << results.has_archive;
555 } else { 529 } else {
556 VLOG(1) << "Zip analysis failed for " << info_.local_file.value(); 530 VLOG(1) << "Zip analysis failed for " << item_->GetFullPath().value();
557 } 531 }
558 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable", 532 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasExecutable",
559 info_.zipped_executable); 533 zipped_executable_);
560 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable", 534 UMA_HISTOGRAM_BOOLEAN("SBClientDownload.ZipFileHasArchiveButNoExecutable",
561 results.has_archive && !info_.zipped_executable); 535 results.has_archive && !zipped_executable_);
562 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractZipFeaturesTime", 536 UMA_HISTOGRAM_TIMES("SBClientDownload.ExtractZipFeaturesTime",
563 base::TimeTicks::Now() - zip_analysis_start_time_); 537 base::TimeTicks::Now() - zip_analysis_start_time_);
564 538
565 if (!info_.zipped_executable) { 539 if (!zipped_executable_) {
566 RecordImprovedProtectionStats(REASON_ARCHIVE_WITHOUT_BINARIES); 540 RecordImprovedProtectionStats(REASON_ARCHIVE_WITHOUT_BINARIES);
567 PostFinishTask(SAFE); 541 PostFinishTask(SAFE);
568 return; 542 return;
569 } 543 }
570 OnFileFeatureExtractionDone(); 544 OnFileFeatureExtractionDone();
571 } 545 }
572 546
573 void CheckWhitelists() { 547 void CheckWhitelists() {
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
575 DownloadCheckResultReason reason = REASON_MAX; 549 DownloadCheckResultReason reason = REASON_MAX;
576 if (!database_manager_) { 550 if (!database_manager_) {
577 reason = REASON_SB_DISABLED; 551 reason = REASON_SB_DISABLED;
578 } else { 552 } else {
579 for (size_t i = 0; i < info_.download_url_chain.size(); ++i) { 553 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) {
580 const GURL& url = info_.download_url_chain[i]; 554 const GURL& url = item_->GetUrlChain()[i];
581 if (url.is_valid() && 555 if (url.is_valid() &&
582 database_manager_->MatchDownloadWhitelistUrl(url)) { 556 database_manager_->MatchDownloadWhitelistUrl(url)) {
583 VLOG(2) << url << " is on the download whitelist."; 557 VLOG(2) << url << " is on the download whitelist.";
584 reason = REASON_WHITELISTED_URL; 558 reason = REASON_WHITELISTED_URL;
585 break; 559 break;
586 } 560 }
587 } 561 }
588 if (info_.referrer_url.is_valid() && reason == REASON_MAX && 562 if (item_->GetReferrerUrl().is_valid() && reason == REASON_MAX &&
589 database_manager_->MatchDownloadWhitelistUrl( 563 database_manager_->MatchDownloadWhitelistUrl(
590 info_.referrer_url)) { 564 item_->GetReferrerUrl())) {
591 VLOG(2) << "Referrer url " << info_.referrer_url 565 VLOG(2) << "Referrer url " << item_->GetReferrerUrl()
592 << " is on the download whitelist."; 566 << " is on the download whitelist.";
593 reason = REASON_WHITELISTED_REFERRER; 567 reason = REASON_WHITELISTED_REFERRER;
594 } 568 }
595 if (reason != REASON_MAX || signature_info_.trusted()) { 569 if (reason != REASON_MAX || signature_info_.trusted()) {
596 UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1); 570 UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1);
597 } 571 }
598 } 572 }
599 if (reason == REASON_MAX && signature_info_.trusted()) { 573 if (reason == REASON_MAX && signature_info_.trusted()) {
600 for (int i = 0; i < signature_info_.certificate_chain_size(); ++i) { 574 for (int i = 0; i < signature_info_.certificate_chain_size(); ++i) {
601 if (CertificateChainIsWhitelisted( 575 if (CertificateChainIsWhitelisted(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 608
635 // This is our last chance to check whether the request has been canceled 609 // This is our last chance to check whether the request has been canceled
636 // before sending it. 610 // before sending it.
637 if (!service_) { 611 if (!service_) {
638 RecordImprovedProtectionStats(REASON_REQUEST_CANCELED); 612 RecordImprovedProtectionStats(REASON_REQUEST_CANCELED);
639 FinishRequest(SAFE); 613 FinishRequest(SAFE);
640 return; 614 return;
641 } 615 }
642 616
643 ClientDownloadRequest request; 617 ClientDownloadRequest request;
644 request.set_url(info_.download_url_chain.back().spec()); 618 request.set_url(item_->GetUrlChain().back().spec());
645 request.mutable_digests()->set_sha256(info_.sha256_hash); 619 request.mutable_digests()->set_sha256(item_->GetHash());
646 request.set_length(info_.total_bytes); 620 request.set_length(item_->GetTotalBytes());
asanka 2013/02/27 18:06:43 GetTotalBytes() might return <= 0 if the Content-L
mattm 2013/02/28 01:33:07 Thanks, switched to GetReceivedBytes.
647 for (size_t i = 0; i < info_.download_url_chain.size(); ++i) { 621 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) {
648 ClientDownloadRequest::Resource* resource = request.add_resources(); 622 ClientDownloadRequest::Resource* resource = request.add_resources();
649 resource->set_url(info_.download_url_chain[i].spec()); 623 resource->set_url(item_->GetUrlChain()[i].spec());
650 if (i == info_.download_url_chain.size() - 1) { 624 if (i == item_->GetUrlChain().size() - 1) {
651 // The last URL in the chain is the download URL. 625 // The last URL in the chain is the download URL.
652 resource->set_type(ClientDownloadRequest::DOWNLOAD_URL); 626 resource->set_type(ClientDownloadRequest::DOWNLOAD_URL);
653 resource->set_referrer(info_.referrer_url.spec()); 627 resource->set_referrer(item_->GetReferrerUrl().spec());
654 if (!info_.remote_address.empty()) { 628 if (!item_->GetRemoteAddress().empty()) {
655 resource->set_remote_ip(info_.remote_address); 629 resource->set_remote_ip(item_->GetRemoteAddress());
656 } 630 }
657 } else { 631 } else {
658 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT); 632 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT);
659 } 633 }
660 // TODO(noelutz): fill out the remote IP addresses. 634 // TODO(noelutz): fill out the remote IP addresses.
661 } 635 }
662 request.set_user_initiated(info_.user_initiated); 636 request.set_user_initiated(item_->HasUserGesture());
663 request.set_file_basename(info_.target_file.BaseName().AsUTF8Unsafe()); 637 request.set_file_basename(
638 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe());
664 request.set_download_type(type_); 639 request.set_download_type(type_);
665 request.mutable_signature()->CopyFrom(signature_info_); 640 request.mutable_signature()->CopyFrom(signature_info_);
666 std::string request_data; 641 std::string request_data;
667 if (!request.SerializeToString(&request_data)) { 642 if (!request.SerializeToString(&request_data)) {
668 RecordImprovedProtectionStats(REASON_INVALID_REQUEST_PROTO); 643 RecordImprovedProtectionStats(REASON_INVALID_REQUEST_PROTO);
669 FinishRequest(SAFE); 644 FinishRequest(SAFE);
670 return; 645 return;
671 } 646 }
672 647
673 VLOG(2) << "Sending a request for URL: " 648 VLOG(2) << "Sending a request for URL: "
674 << info_.download_url_chain.back(); 649 << item_->GetUrlChain().back();
675 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, 650 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */,
676 GURL(GetDownloadRequestUrl()), 651 GURL(GetDownloadRequestUrl()),
677 net::URLFetcher::POST, 652 net::URLFetcher::POST,
678 this)); 653 this));
679 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 654 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
680 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. 655 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error.
681 fetcher_->SetRequestContext(service_->request_context_getter_.get()); 656 fetcher_->SetRequestContext(service_->request_context_getter_.get());
682 fetcher_->SetUploadData("application/octet-stream", request_data); 657 fetcher_->SetUploadData("application/octet-stream", request_data);
683 fetcher_->Start(); 658 fetcher_->Start();
684 } 659 }
685 660
686 void PostFinishTask(DownloadCheckResult result) { 661 void PostFinishTask(DownloadCheckResult result) {
687 BrowserThread::PostTask( 662 BrowserThread::PostTask(
688 BrowserThread::UI, 663 BrowserThread::UI,
689 FROM_HERE, 664 FROM_HERE,
690 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result)); 665 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result));
691 } 666 }
692 667
693 void FinishRequest(DownloadCheckResult result) { 668 void FinishRequest(DownloadCheckResult result) {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
695 if (finished_) { 670 if (finished_) {
696 return; 671 return;
697 } 672 }
698 finished_ = true; 673 finished_ = true;
699 if (service_) { 674 if (service_) {
700 callback_.Run(result); 675 callback_.Run(result);
676 item_->RemoveObserver(this);
677 item_ = NULL;
701 DownloadProtectionService* service = service_; 678 DownloadProtectionService* service = service_;
702 service_ = NULL; 679 service_ = NULL;
703 service->RequestFinished(this); 680 service->RequestFinished(this);
704 // DownloadProtectionService::RequestFinished will decrement our refcount, 681 // DownloadProtectionService::RequestFinished will decrement our refcount,
705 // so we may be deleted now. 682 // so we may be deleted now.
706 } else { 683 } else {
707 callback_.Run(SAFE); 684 callback_.Run(SAFE);
708 } 685 }
709 } 686 }
710 687
711 void RecordImprovedProtectionStats(DownloadCheckResultReason reason) { 688 void RecordImprovedProtectionStats(DownloadCheckResultReason reason) {
712 VLOG(2) << "SafeBrowsing download verdict for: " 689 VLOG(2) << "SafeBrowsing download verdict for: "
713 << info_.DebugString() << " verdict:" << reason; 690 << item_->DebugString(true) << " verdict:" << reason;
714 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", 691 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats",
715 reason, 692 reason,
716 REASON_MAX); 693 REASON_MAX);
717 } 694 }
718 695
719 bool CertificateChainIsWhitelisted( 696 bool CertificateChainIsWhitelisted(
720 const ClientDownloadRequest_CertificateChain& chain) { 697 const ClientDownloadRequest_CertificateChain& chain) {
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
722 if (chain.element_size() < 2) { 699 if (chain.element_size() < 2) {
723 // We need to have both a signing certificate and its issuer certificate 700 // We need to have both a signing certificate and its issuer certificate
(...skipping 26 matching lines...) Expand all
750 << cert->subject().GetDisplayName() 727 << cert->subject().GetDisplayName()
751 << " issuer=" << issuer->subject().GetDisplayName(); 728 << " issuer=" << issuer->subject().GetDisplayName();
752 return true; 729 return true;
753 } 730 }
754 } 731 }
755 cert = issuer; 732 cert = issuer;
756 } 733 }
757 return false; 734 return false;
758 } 735 }
759 736
760 DownloadInfo info_; 737 // Will be NULL if the request has been canceled.
738 content::DownloadItem* item_;
739 bool zipped_executable_;
761 ClientDownloadRequest_SignatureInfo signature_info_; 740 ClientDownloadRequest_SignatureInfo signature_info_;
762 CheckDownloadCallback callback_; 741 CheckDownloadCallback callback_;
763 // Will be NULL if the request has been canceled. 742 // Will be NULL if the request has been canceled.
764 DownloadProtectionService* service_; 743 DownloadProtectionService* service_;
765 scoped_refptr<SignatureUtil> signature_util_; 744 scoped_refptr<SignatureUtil> signature_util_;
766 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 745 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
767 const bool pingback_enabled_; 746 const bool pingback_enabled_;
768 scoped_ptr<net::URLFetcher> fetcher_; 747 scoped_ptr<net::URLFetcher> fetcher_;
769 scoped_refptr<SandboxedZipAnalyzer> analyzer_; 748 scoped_refptr<SandboxedZipAnalyzer> analyzer_;
770 base::TimeTicks zip_analysis_start_time_; 749 base::TimeTicks zip_analysis_start_time_;
(...skipping 29 matching lines...) Expand all
800 if (enabled == enabled_) { 779 if (enabled == enabled_) {
801 return; 780 return;
802 } 781 }
803 enabled_ = enabled; 782 enabled_ = enabled;
804 if (!enabled_) { 783 if (!enabled_) {
805 CancelPendingRequests(); 784 CancelPendingRequests();
806 } 785 }
807 } 786 }
808 787
809 void DownloadProtectionService::CheckClientDownload( 788 void DownloadProtectionService::CheckClientDownload(
810 const DownloadProtectionService::DownloadInfo& info, 789 content::DownloadItem* item,
811 const CheckDownloadCallback& callback) { 790 const CheckDownloadCallback& callback) {
812 scoped_refptr<CheckClientDownloadRequest> request( 791 scoped_refptr<CheckClientDownloadRequest> request(
813 new CheckClientDownloadRequest(info, callback, this, 792 new CheckClientDownloadRequest(item, callback, this,
814 database_manager_, signature_util_.get())); 793 database_manager_, signature_util_.get()));
815 download_requests_.insert(request); 794 download_requests_.insert(request);
816 request->Start(); 795 request->Start();
817 } 796 }
818 797
819 void DownloadProtectionService::CheckDownloadUrl( 798 void DownloadProtectionService::CheckDownloadUrl(
820 const DownloadProtectionService::DownloadInfo& info, 799 const content::DownloadItem& item,
821 const CheckDownloadCallback& callback) { 800 const CheckDownloadCallback& callback) {
822 DCHECK(!info.download_url_chain.empty()); 801 DCHECK(!item.GetUrlChain().empty());
823 scoped_refptr<DownloadUrlSBClient> client( 802 scoped_refptr<DownloadUrlSBClient> client(
824 new DownloadUrlSBClient(info, callback, ui_manager_, database_manager_)); 803 new DownloadUrlSBClient(item, callback, ui_manager_, database_manager_));
825 // The client will release itself once it is done. 804 // The client will release itself once it is done.
826 BrowserThread::PostTask( 805 BrowserThread::PostTask(
827 BrowserThread::IO, 806 BrowserThread::IO,
828 FROM_HERE, 807 FROM_HERE,
829 base::Bind(&DownloadUrlSBClient::StartCheck, client)); 808 base::Bind(&DownloadUrlSBClient::StartCheck, client));
830 } 809 }
831 810
832 bool DownloadProtectionService::IsSupportedDownload( 811 bool DownloadProtectionService::IsSupportedDownload(
833 const DownloadInfo& info) const { 812 const content::DownloadItem& item,
813 const base::FilePath& target_path) const {
834 // Currently, the UI only works on Windows. On Linux and Mac we still 814 // Currently, the UI only works on Windows. On Linux and Mac we still
835 // want to show the dangerous file type warning if the file is possibly 815 // want to show the dangerous file type warning if the file is possibly
836 // dangerous which means we have to always return false here. 816 // dangerous which means we have to always return false here.
837 #if defined(OS_WIN) 817 #if defined(OS_WIN)
838 DownloadCheckResultReason reason = REASON_MAX; 818 DownloadCheckResultReason reason = REASON_MAX;
839 ClientDownloadRequest::DownloadType type = 819 ClientDownloadRequest::DownloadType type =
840 ClientDownloadRequest::WIN_EXECUTABLE; 820 ClientDownloadRequest::WIN_EXECUTABLE;
841 return (CheckClientDownloadRequest::IsSupportedDownload(info, 821 return (CheckClientDownloadRequest::IsSupportedDownload(item, target_path,
842 &reason, 822 &reason, &type) &&
843 &type) &&
844 (ClientDownloadRequest::ANDROID_APK == type || 823 (ClientDownloadRequest::ANDROID_APK == type ||
845 ClientDownloadRequest::WIN_EXECUTABLE == type || 824 ClientDownloadRequest::WIN_EXECUTABLE == type ||
846 ClientDownloadRequest::ZIPPED_EXECUTABLE == type)); 825 ClientDownloadRequest::ZIPPED_EXECUTABLE == type));
847 #else 826 #else
848 return false; 827 return false;
849 #endif 828 #endif
850 } 829 }
851 830
852 void DownloadProtectionService::CancelPendingRequests() { 831 void DownloadProtectionService::CancelPendingRequests() {
853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 832 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 11 matching lines...) Expand all
865 void DownloadProtectionService::RequestFinished( 844 void DownloadProtectionService::RequestFinished(
866 CheckClientDownloadRequest* request) { 845 CheckClientDownloadRequest* request) {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
868 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = 847 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it =
869 download_requests_.find(request); 848 download_requests_.find(request);
870 DCHECK(it != download_requests_.end()); 849 DCHECK(it != download_requests_.end());
871 download_requests_.erase(*it); 850 download_requests_.erase(*it);
872 } 851 }
873 852
874 void DownloadProtectionService::ShowDetailsForDownload( 853 void DownloadProtectionService::ShowDetailsForDownload(
875 const DownloadProtectionService::DownloadInfo& info, 854 const content::DownloadItem& item,
876 content::PageNavigator* navigator) { 855 content::PageNavigator* navigator) {
877 navigator->OpenURL( 856 navigator->OpenURL(
878 content::OpenURLParams(GURL(chrome::kDownloadScanningLearnMoreURL), 857 content::OpenURLParams(GURL(chrome::kDownloadScanningLearnMoreURL),
879 content::Referrer(), 858 content::Referrer(),
880 NEW_FOREGROUND_TAB, 859 NEW_FOREGROUND_TAB,
881 content::PAGE_TRANSITION_LINK, 860 content::PAGE_TRANSITION_LINK,
882 false)); 861 false));
883 } 862 }
884 863
885 namespace { 864 namespace {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 std::string url = kDownloadRequestUrl; 941 std::string url = kDownloadRequestUrl;
963 std::string api_key = google_apis::GetAPIKey(); 942 std::string api_key = google_apis::GetAPIKey();
964 if (!api_key.empty()) { 943 if (!api_key.empty()) {
965 base::StringAppendF(&url, "?key=%s", 944 base::StringAppendF(&url, "?key=%s",
966 net::EscapeQueryParamValue(api_key, true).c_str()); 945 net::EscapeQueryParamValue(api_key, true).c_str());
967 } 946 }
968 return url; 947 return url;
969 } 948 }
970 949
971 } // namespace safe_browsing 950 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698