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/callback.h" | 9 #include "base/callback.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/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "chrome/browser/safe_browsing/report.pb.h" | 16 #include "chrome/browser/safe_browsing/report.pb.h" |
17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
18 #include "net/base/host_port_pair.h" | |
18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
22 | 23 |
23 using safe_browsing::ClientMalwareReportRequest; | 24 using safe_browsing::ClientMalwareReportRequest; |
24 | 25 |
25 // Only send small files for now, a better strategy would use the size | 26 // Only send small files for now, a better strategy would use the size |
26 // of the whole report and the user's bandwidth. | 27 // of the whole report and the user's bandwidth. |
27 static const uint32 kMaxBodySizeBytes = 1024; | 28 static const uint32 kMaxBodySizeBytes = 1024; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 ClientMalwareReportRequest::HTTPHeader* pb_header = | 159 ClientMalwareReportRequest::HTTPHeader* pb_header = |
159 pb_response->add_headers(); | 160 pb_response->add_headers(); |
160 pb_header->set_name(name); | 161 pb_header->set_name(name); |
161 // Strip any Set-Cookie headers. | 162 // Strip any Set-Cookie headers. |
162 if (LowerCaseEqualsASCII(name, "set-cookie")) { | 163 if (LowerCaseEqualsASCII(name, "set-cookie")) { |
163 pb_header->set_value(""); | 164 pb_header->set_value(""); |
164 } else { | 165 } else { |
165 pb_header->set_value(value); | 166 pb_header->set_value(value); |
166 } | 167 } |
167 } | 168 } |
169 | |
170 net::HostPortPair socket_address = source->socket_address(); | |
mattm
2011/05/10 21:26:30
Could go in the if block, or just do it inline in
panayiotis
2011/05/10 21:47:36
Done.
| |
171 if (!source->was_fetched_via_proxy()) { | |
172 pb_response->set_remote_ip(socket_address.ToString()); | |
mattm
2011/05/10 21:26:30
Can the test be updated to check this?
panayiotis
2011/05/10 21:47:36
Done.
| |
173 } | |
168 } | 174 } |
169 | 175 |
170 void MalwareDetailsCacheCollector::ReadData( | 176 void MalwareDetailsCacheCollector::ReadData( |
171 ClientMalwareReportRequest::Resource* pb_resource, | 177 ClientMalwareReportRequest::Resource* pb_resource, |
172 const std::string& data) { | 178 const std::string& data) { |
173 DVLOG(1) << "ReadData"; | 179 DVLOG(1) << "ReadData"; |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
175 ClientMalwareReportRequest::HTTPResponse* pb_response = | 181 ClientMalwareReportRequest::HTTPResponse* pb_response = |
176 pb_resource->mutable_response(); | 182 pb_resource->mutable_response(); |
177 if (data.size() <= kMaxBodySizeBytes) { // Only send small bodies for now. | 183 if (data.size() <= kMaxBodySizeBytes) { // Only send small bodies for now. |
(...skipping 17 matching lines...) Expand all Loading... | |
195 BrowserThread::IO, FROM_HERE, | 201 BrowserThread::IO, FROM_HERE, |
196 NewRunnableMethod(this, &MalwareDetailsCacheCollector::OpenEntry)); | 202 NewRunnableMethod(this, &MalwareDetailsCacheCollector::OpenEntry)); |
197 } | 203 } |
198 | 204 |
199 void MalwareDetailsCacheCollector::AllDone(bool success) { | 205 void MalwareDetailsCacheCollector::AllDone(bool success) { |
200 DVLOG(1) << "AllDone"; | 206 DVLOG(1) << "AllDone"; |
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
202 *result_ = success; | 208 *result_ = success; |
203 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 209 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
204 } | 210 } |
OLD | NEW |