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" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/safe_browsing/malware_details.h" | 14 #include "chrome/browser/safe_browsing/malware_details.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 | 22 |
23 MalwareDetailsRedirectsCollector::MalwareDetailsRedirectsCollector( | 23 MalwareDetailsRedirectsCollector::MalwareDetailsRedirectsCollector( |
24 Profile* profile) | 24 Profile* profile) |
25 : profile_(profile), | 25 : profile_(profile), |
26 has_started_(false) { | 26 has_started_(false) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 27 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
28 if (profile) { | 28 if (profile) { |
29 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 29 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
30 content::Source<Profile>(profile)); | 30 content::Source<Profile>(profile)); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 void MalwareDetailsRedirectsCollector::StartHistoryCollection( | 34 void MalwareDetailsRedirectsCollector::StartHistoryCollection( |
35 const std::vector<GURL>& urls, | 35 const std::vector<GURL>& urls, |
36 const base::Closure& callback) { | 36 const base::Closure& callback) { |
37 DVLOG(1) << "Num of urls to check in history service: " << urls.size(); | 37 DVLOG(1) << "Num of urls to check in history service: " << urls.size(); |
(...skipping 17 matching lines...) Expand all Loading... |
55 | 55 |
56 const std::vector<safe_browsing::RedirectChain>& | 56 const std::vector<safe_browsing::RedirectChain>& |
57 MalwareDetailsRedirectsCollector::GetCollectedUrls() const { | 57 MalwareDetailsRedirectsCollector::GetCollectedUrls() const { |
58 return redirects_urls_; | 58 return redirects_urls_; |
59 } | 59 } |
60 | 60 |
61 void MalwareDetailsRedirectsCollector::Observe( | 61 void MalwareDetailsRedirectsCollector::Observe( |
62 int type, | 62 int type, |
63 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) { | 64 const content::NotificationDetails& details) { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
66 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); | 66 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED); |
67 DVLOG(1) << "Profile gone."; | 67 DVLOG(1) << "Profile gone."; |
68 profile_ = NULL; | 68 profile_ = NULL; |
69 } | 69 } |
70 | 70 |
71 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() {} | 71 MalwareDetailsRedirectsCollector::~MalwareDetailsRedirectsCollector() {} |
72 | 72 |
73 void MalwareDetailsRedirectsCollector::StartGetRedirects( | 73 void MalwareDetailsRedirectsCollector::StartGetRedirects( |
74 const std::vector<GURL>& urls) { | 74 const std::vector<GURL>& urls) { |
75 // History access from profile needs to happen in UI thread | 75 // History access from profile needs to happen in UI thread |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
77 for (size_t i = 0; i < urls.size(); ++i) { | 77 for (size_t i = 0; i < urls.size(); ++i) { |
78 urls_.push_back(urls[i]); | 78 urls_.push_back(urls[i]); |
79 } | 79 } |
80 urls_it_ = urls_.begin(); | 80 urls_it_ = urls_.begin(); |
81 GetRedirects(*urls_it_); | 81 GetRedirects(*urls_it_); |
82 } | 82 } |
83 | 83 |
84 void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) { | 84 void MalwareDetailsRedirectsCollector::GetRedirects(const GURL& url) { |
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
86 if (!profile_) { | 86 if (!profile_) { |
87 AllDone(); | 87 AllDone(); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 91 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
92 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 92 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
93 if (!history) { | 93 if (!history) { |
94 AllDone(); | 94 AllDone(); |
95 return; | 95 return; |
(...skipping 26 matching lines...) Expand all Loading... |
122 } | 122 } |
123 | 123 |
124 GetRedirects(*urls_it_); | 124 GetRedirects(*urls_it_); |
125 } | 125 } |
126 | 126 |
127 void MalwareDetailsRedirectsCollector::AllDone() { | 127 void MalwareDetailsRedirectsCollector::AllDone() { |
128 DVLOG(1) << "AllDone"; | 128 DVLOG(1) << "AllDone"; |
129 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); | 129 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); |
130 callback_.Reset(); | 130 callback_.Reset(); |
131 } | 131 } |
OLD | NEW |