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" |
(...skipping 19 matching lines...) Expand all Loading... |
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 |
33 MalwareDetailsCacheCollector::MalwareDetailsCacheCollector() | 33 MalwareDetailsCacheCollector::MalwareDetailsCacheCollector() |
34 : resources_(NULL), | 34 : resources_(NULL), |
35 result_(NULL), | 35 result_(NULL), |
36 has_started_(false), | 36 has_started_(false), |
37 current_fetch_(NULL) { | 37 current_fetch_(NULL) { |
38 } | 38 } |
39 | 39 |
40 MalwareDetailsCacheCollector::~MalwareDetailsCacheCollector() { | |
41 } | |
42 | |
43 void MalwareDetailsCacheCollector::StartCacheCollection( | 40 void MalwareDetailsCacheCollector::StartCacheCollection( |
44 net::URLRequestContextGetter* request_context_getter, | 41 net::URLRequestContextGetter* request_context_getter, |
45 safe_browsing::ResourceMap* resources, | 42 safe_browsing::ResourceMap* resources, |
46 bool* result, | 43 bool* result, |
47 const base::Closure& callback) { | 44 const base::Closure& callback) { |
48 // Start the data collection from the HTTP cache. We use a URLFetcher | 45 // Start the data collection from the HTTP cache. We use a URLFetcher |
49 // and set the right flags so we only hit the cache. | 46 // and set the right flags so we only hit the cache. |
50 DVLOG(1) << "Getting cache data for all urls..."; | 47 DVLOG(1) << "Getting cache data for all urls..."; |
51 request_context_getter_ = request_context_getter; | 48 request_context_getter_ = request_context_getter; |
52 resources_ = resources; | 49 resources_ = resources; |
53 resources_it_ = resources_->begin(); | 50 resources_it_ = resources_->begin(); |
54 result_ = result; | 51 result_ = result; |
55 callback_ = callback; | 52 callback_ = callback; |
56 has_started_ = true; | 53 has_started_ = true; |
57 | 54 |
58 // Post a task in the message loop, so the callers don't need to | 55 // Post a task in the message loop, so the callers don't need to |
59 // check if we call their callback immediately. | 56 // check if we call their callback immediately. |
60 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
61 BrowserThread::IO, FROM_HERE, | 58 BrowserThread::IO, FROM_HERE, |
62 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); | 59 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); |
63 } | 60 } |
64 | 61 |
65 bool MalwareDetailsCacheCollector::HasStarted() { | 62 bool MalwareDetailsCacheCollector::HasStarted() { |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
67 return has_started_; | 64 return has_started_; |
68 } | 65 } |
69 | 66 |
| 67 MalwareDetailsCacheCollector::~MalwareDetailsCacheCollector() {} |
| 68 |
70 // Fetch a URL and advance to the next one when done. | 69 // Fetch a URL and advance to the next one when done. |
71 void MalwareDetailsCacheCollector::OpenEntry() { | 70 void MalwareDetailsCacheCollector::OpenEntry() { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
73 DVLOG(1) << "OpenEntry"; | 72 DVLOG(1) << "OpenEntry"; |
74 | 73 |
75 if (resources_it_ == resources_->end()) { // We are done. | 74 if (resources_it_ == resources_->end()) { // We are done. |
76 AllDone(true); | 75 AllDone(true); |
77 return; | 76 return; |
78 } | 77 } |
79 | 78 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); | 201 base::Bind(&MalwareDetailsCacheCollector::OpenEntry, this)); |
203 } | 202 } |
204 | 203 |
205 void MalwareDetailsCacheCollector::AllDone(bool success) { | 204 void MalwareDetailsCacheCollector::AllDone(bool success) { |
206 DVLOG(1) << "AllDone"; | 205 DVLOG(1) << "AllDone"; |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
208 *result_ = success; | 207 *result_ = success; |
209 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
210 callback_.Reset(); | 209 callback_.Reset(); |
211 } | 210 } |
OLD | NEW |