| 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 MalwareDetailsRedirectsCollector class. | 5 // Implementation of the MalwareDetailsRedirectsCollector class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/malware_details_history.h" | 7 #include "chrome/browser/safe_browsing/malware_details_history.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 Profile* profile) | 23 Profile* profile) |
| 24 : profile_(profile), | 24 : profile_(profile), |
| 25 has_started_(false) { | 25 has_started_(false) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 27 if (profile) { | 27 if (profile) { |
| 28 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 28 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 29 content::Source<Profile>(profile)); | 29 content::Source<Profile>(profile)); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() { | |
| 34 } | |
| 35 | |
| 36 void MalwareDetailsRedirectsCollector::StartHistoryCollection( | 33 void MalwareDetailsRedirectsCollector::StartHistoryCollection( |
| 37 const std::vector<GURL>& urls, | 34 const std::vector<GURL>& urls, |
| 38 const base::Closure& callback) { | 35 const base::Closure& callback) { |
| 39 DVLOG(1) << "Num of urls to check in history service: " << urls.size(); | 36 DVLOG(1) << "Num of urls to check in history service: " << urls.size(); |
| 40 has_started_ = true; | 37 has_started_ = true; |
| 41 callback_ = callback; | 38 callback_ = callback; |
| 42 | 39 |
| 43 if (urls.size() == 0) { | 40 if (urls.size() == 0) { |
| 44 AllDone(); | 41 AllDone(); |
| 45 return; | 42 return; |
| 46 } | 43 } |
| 47 | 44 |
| 48 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 49 BrowserThread::UI, FROM_HERE, | 46 BrowserThread::UI, FROM_HERE, |
| 50 base::Bind(&MalwareDetailsRedirectsCollector::StartGetRedirects, | 47 base::Bind(&MalwareDetailsRedirectsCollector::StartGetRedirects, |
| 51 this, urls)); | 48 this, urls)); |
| 52 } | 49 } |
| 53 | 50 |
| 51 bool MalwareDetailsRedirectsCollector::HasStarted() const { |
| 52 return has_started_; |
| 53 } |
| 54 |
| 55 const std::vector<safe_browsing::RedirectChain>& |
| 56 MalwareDetailsRedirectsCollector::GetCollectedUrls() const { |
| 57 return redirects_urls_; |
| 58 } |
| 59 |
| 60 void MalwareDetailsRedirectsCollector::Observe( |
| 61 int type, |
| 62 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); |
| 66 DVLOG(1) << "Profile gone."; |
| 67 profile_ = NULL; |
| 68 } |
| 69 |
| 70 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() {} |
| 71 |
| 54 void MalwareDetailsRedirectsCollector::StartGetRedirects( | 72 void MalwareDetailsRedirectsCollector::StartGetRedirects( |
| 55 const std::vector<GURL>& urls) { | 73 const std::vector<GURL>& urls) { |
| 56 // History access from profile needs to happen in UI thread | 74 // History access from profile needs to happen in UI thread |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 for (size_t i = 0; i < urls.size(); ++i) { | 76 for (size_t i = 0; i < urls.size(); ++i) { |
| 59 urls_.push_back(urls[i]); | 77 urls_.push_back(urls[i]); |
| 60 } | 78 } |
| 61 urls_it_ = urls_.begin(); | 79 urls_it_ = urls_.begin(); |
| 62 GetRedirects(*urls_it_); | 80 GetRedirects(*urls_it_); |
| 63 } | 81 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ++urls_it_; | 120 ++urls_it_; |
| 103 | 121 |
| 104 if (urls_it_ == urls_.end()) { | 122 if (urls_it_ == urls_.end()) { |
| 105 AllDone(); | 123 AllDone(); |
| 106 return; | 124 return; |
| 107 } | 125 } |
| 108 | 126 |
| 109 GetRedirects(*urls_it_); | 127 GetRedirects(*urls_it_); |
| 110 } | 128 } |
| 111 | 129 |
| 112 bool MalwareDetailsRedirectsCollector::HasStarted() const { | |
| 113 return has_started_; | |
| 114 } | |
| 115 | |
| 116 void MalwareDetailsRedirectsCollector::AllDone() { | 130 void MalwareDetailsRedirectsCollector::AllDone() { |
| 117 DVLOG(1) << "AllDone"; | 131 DVLOG(1) << "AllDone"; |
| 118 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 132 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
| 119 callback_.Reset(); | 133 callback_.Reset(); |
| 120 } | 134 } |
| 121 | |
| 122 const std::vector<safe_browsing::RedirectChain>& | |
| 123 MalwareDetailsRedirectsCollector::GetCollectedUrls() const { | |
| 124 return redirects_urls_; | |
| 125 } | |
| 126 | |
| 127 void MalwareDetailsRedirectsCollector::Observe( | |
| 128 int type, | |
| 129 const content::NotificationSource& source, | |
| 130 const content::NotificationDetails& details) { | |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 132 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); | |
| 133 DVLOG(1) << "Profile gone."; | |
| 134 profile_ = NULL; | |
| 135 } | |
| OLD | NEW |