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" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 ClientMalwareReportRequest::Resource* pb_resource, | 172 ClientMalwareReportRequest::Resource* pb_resource, |
173 const std::string& data) { | 173 const std::string& data) { |
174 DVLOG(1) << "ReadData"; | 174 DVLOG(1) << "ReadData"; |
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
176 ClientMalwareReportRequest::HTTPResponse* pb_response = | 176 ClientMalwareReportRequest::HTTPResponse* pb_response = |
177 pb_resource->mutable_response(); | 177 pb_resource->mutable_response(); |
178 if (data.size() <= kMaxBodySizeBytes) { // Only send small bodies for now. | 178 if (data.size() <= kMaxBodySizeBytes) { // Only send small bodies for now. |
179 pb_response->set_body(data); | 179 pb_response->set_body(data); |
180 } | 180 } |
181 pb_response->set_bodylength(data.size()); | 181 pb_response->set_bodylength(data.size()); |
182 base::MD5Digest digest; | 182 pb_response->set_bodydigest(base::MD5String(data)); |
183 base::MD5Sum(data.c_str(), data.size(), &digest); | |
184 pb_response->set_bodydigest(base::MD5DigestToBase16(digest)); | |
185 } | 183 } |
186 | 184 |
187 void MalwareDetailsCacheCollector::AdvanceEntry() { | 185 void MalwareDetailsCacheCollector::AdvanceEntry() { |
188 DVLOG(1) << "AdvanceEntry"; | 186 DVLOG(1) << "AdvanceEntry"; |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
190 // Advance to the next resource. | 188 // Advance to the next resource. |
191 ++resources_it_; | 189 ++resources_it_; |
192 current_fetch_.reset(NULL); | 190 current_fetch_.reset(NULL); |
193 | 191 |
194 // Create a task so we don't take over the IO thread for too long. | 192 // Create a task so we don't take over the IO thread for too long. |
195 BrowserThread::PostTask( | 193 BrowserThread::PostTask( |
196 BrowserThread::IO, FROM_HERE, | 194 BrowserThread::IO, FROM_HERE, |
197 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); | 195 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); |
198 } | 196 } |
199 | 197 |
200 void MalwareDetailsCacheCollector::AllDone(bool success) { | 198 void MalwareDetailsCacheCollector::AllDone(bool success) { |
201 DVLOG(1) << "AllDone"; | 199 DVLOG(1) << "AllDone"; |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
203 *result_ = success; | 201 *result_ = success; |
204 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 202 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
205 callback_.Reset(); | 203 callback_.Reset(); |
206 } | 204 } |
OLD | NEW |