| OLD | NEW |
| 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 // Implementation of the MalwareDetails class. | 5 // Implementation of the MalwareDetails class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/malware_details.h" | 7 #include "chrome/browser/safe_browsing/malware_details.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/net/chrome_url_request_context.h" | 13 #include "chrome/browser/net/chrome_url_request_context.h" |
| 14 #include "chrome/browser/safe_browsing/malware_details_cache.h" | 14 #include "chrome/browser/safe_browsing/malware_details_cache.h" |
| 15 #include "chrome/browser/safe_browsing/report.pb.h" | 15 #include "chrome/browser/safe_browsing/report.pb.h" |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/url_fetcher.h" | |
| 19 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 21 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 22 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
| 22 #include "net/url_request/url_fetcher.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using safe_browsing::ClientMalwareReportRequest; | 27 using safe_browsing::ClientMalwareReportRequest; |
| 28 | 28 |
| 29 // Only send small files for now, a better strategy would use the size | 29 // Only send small files for now, a better strategy would use the size |
| 30 // of the whole report and the user's bandwidth. | 30 // of the whole report and the user's bandwidth. |
| 31 static const uint32 kMaxBodySizeBytes = 1024; | 31 static const uint32 kMaxBodySizeBytes = 1024; |
| 32 | 32 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 AllDone(true); | 75 AllDone(true); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (!request_context_getter_) { | 79 if (!request_context_getter_) { |
| 80 DVLOG(1) << "Missing request context getter"; | 80 DVLOG(1) << "Missing request context getter"; |
| 81 AllDone(false); | 81 AllDone(false); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 current_fetch_.reset(content::URLFetcher::Create( | 85 current_fetch_.reset(net::URLFetcher::Create( |
| 86 GURL(resources_it_->first), net::URLFetcher::GET, this)); | 86 GURL(resources_it_->first), net::URLFetcher::GET, this)); |
| 87 current_fetch_->SetRequestContext(request_context_getter_); | 87 current_fetch_->SetRequestContext(request_context_getter_); |
| 88 // Only from cache, and don't save cookies. | 88 // Only from cache, and don't save cookies. |
| 89 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE | | 89 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE | |
| 90 net::LOAD_DO_NOT_SAVE_COOKIES); | 90 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 91 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries. | 91 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries. |
| 92 current_fetch_->Start(); // OnURLFetchComplete will be called when done. | 92 current_fetch_->Start(); // OnURLFetchComplete will be called when done. |
| 93 } | 93 } |
| 94 | 94 |
| 95 ClientMalwareReportRequest::Resource* MalwareDetailsCacheCollector::GetResource( | 95 ClientMalwareReportRequest::Resource* MalwareDetailsCacheCollector::GetResource( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); | 201 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void MalwareDetailsCacheCollector::AllDone(bool success) { | 204 void MalwareDetailsCacheCollector::AllDone(bool success) { |
| 205 DVLOG(1) << "AllDone"; | 205 DVLOG(1) << "AllDone"; |
| 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 207 *result_ = success; | 207 *result_ = success; |
| 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
| 209 callback_.Reset(); | 209 callback_.Reset(); |
| 210 } | 210 } |
| OLD | NEW |