| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "content/common/net/url_fetcher.h" |
| 18 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
| 19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
| 21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 22 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
| 23 | 24 |
| 24 using safe_browsing::ClientMalwareReportRequest; | 25 using safe_browsing::ClientMalwareReportRequest; |
| 25 | 26 |
| 26 // Only send small files for now, a better strategy would use the size | 27 // Only send small files for now, a better strategy would use the size |
| 27 // of the whole report and the user's bandwidth. | 28 // of the whole report and the user's bandwidth. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ClientMalwareReportRequest::Resource* MalwareDetailsCacheCollector::GetResource( | 96 ClientMalwareReportRequest::Resource* MalwareDetailsCacheCollector::GetResource( |
| 96 const GURL& url) { | 97 const GURL& url) { |
| 97 safe_browsing::ResourceMap::iterator it = resources_->find(url.spec()); | 98 safe_browsing::ResourceMap::iterator it = resources_->find(url.spec()); |
| 98 if (it != resources_->end()) { | 99 if (it != resources_->end()) { |
| 99 return it->second.get(); | 100 return it->second.get(); |
| 100 } | 101 } |
| 101 return NULL; | 102 return NULL; |
| 102 } | 103 } |
| 103 | 104 |
| 104 void MalwareDetailsCacheCollector::OnURLFetchComplete( | 105 void MalwareDetailsCacheCollector::OnURLFetchComplete( |
| 105 const URLFetcher* source, | 106 const URLFetcher* source) { |
| 106 const GURL& url, | |
| 107 const net::URLRequestStatus& status, | |
| 108 int response_code, | |
| 109 const net::ResponseCookies& cookies, | |
| 110 const std::string& data) { | |
| 111 DVLOG(1) << "OnUrlFetchComplete"; | 107 DVLOG(1) << "OnUrlFetchComplete"; |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 113 DCHECK(current_fetch_.get()); | 109 DCHECK(current_fetch_.get()); |
| 114 if (status.status() != net::URLRequestStatus::SUCCESS && | 110 if (source->status().status() != net::URLRequestStatus::SUCCESS && |
| 115 status.error() == net::ERR_CACHE_MISS) { | 111 source->status().error() == net::ERR_CACHE_MISS) { |
| 116 // Cache miss, skip this resource. | 112 // Cache miss, skip this resource. |
| 117 DVLOG(1) << "Cache miss for url: " << url; | 113 DVLOG(1) << "Cache miss for url: " << source->url(); |
| 118 AdvanceEntry(); | 114 AdvanceEntry(); |
| 119 return; | 115 return; |
| 120 } | 116 } |
| 121 | 117 |
| 122 if (status.status() != net::URLRequestStatus::SUCCESS) { | 118 if (source->status().status() != net::URLRequestStatus::SUCCESS) { |
| 123 // Some other error occurred, e.g. the request could have been cancelled. | 119 // Some other error occurred, e.g. the request could have been cancelled. |
| 124 DVLOG(1) << "Unsuccessful fetch: " << url; | 120 DVLOG(1) << "Unsuccessful fetch: " << source->url(); |
| 125 AdvanceEntry(); | 121 AdvanceEntry(); |
| 126 return; | 122 return; |
| 127 } | 123 } |
| 128 | 124 |
| 129 // Set the response headers and body to the right resource, which | 125 // Set the response headers and body to the right resource, which |
| 130 // might not be the same as the one we asked for. | 126 // might not be the same as the one we asked for. |
| 131 // For redirects, resources_it_->first != url.spec(). | 127 // For redirects, resources_it_->first != url.spec(). |
| 132 ClientMalwareReportRequest::Resource* resource = GetResource(url); | 128 ClientMalwareReportRequest::Resource* resource = GetResource(source->url()); |
| 133 if (!resource) { | 129 if (!resource) { |
| 134 DVLOG(1) << "Cannot find resource for url:" << url; | 130 DVLOG(1) << "Cannot find resource for url:" << source->url(); |
| 135 AdvanceEntry(); | 131 AdvanceEntry(); |
| 136 return; | 132 return; |
| 137 } | 133 } |
| 138 | 134 |
| 139 ReadResponse(resource, source); | 135 ReadResponse(resource, source); |
| 136 std::string data; |
| 137 CHECK(source->GetResponseAsString(&data)); |
| 140 ReadData(resource, data); | 138 ReadData(resource, data); |
| 141 AdvanceEntry(); | 139 AdvanceEntry(); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void MalwareDetailsCacheCollector::ReadResponse( | 142 void MalwareDetailsCacheCollector::ReadResponse( |
| 145 ClientMalwareReportRequest::Resource* pb_resource, | 143 ClientMalwareReportRequest::Resource* pb_resource, |
| 146 const URLFetcher* source) { | 144 const URLFetcher* source) { |
| 147 DVLOG(1) << "ReadResponse"; | 145 DVLOG(1) << "ReadResponse"; |
| 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 149 net::HttpResponseHeaders* headers = source->response_headers(); | 147 net::HttpResponseHeaders* headers = source->response_headers(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); | 201 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); |
| 204 } | 202 } |
| 205 | 203 |
| 206 void MalwareDetailsCacheCollector::AllDone(bool success) { | 204 void MalwareDetailsCacheCollector::AllDone(bool success) { |
| 207 DVLOG(1) << "AllDone"; | 205 DVLOG(1) << "AllDone"; |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 209 *result_ = success; | 207 *result_ = success; |
| 210 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
| 211 callback_.Reset(); | 209 callback_.Reset(); |
| 212 } | 210 } |
| OLD | NEW |