| 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ |
| 7 | 7 |
| 8 // This class gets redirect chain for urls from the history service. | 8 // This class gets redirect chain for urls from the history service. |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/sequenced_task_runner_helpers.h" | 18 #include "base/sequenced_task_runner_helpers.h" |
| 19 #include "base/task/cancelable_task_tracker.h" | 19 #include "base/task/cancelable_task_tracker.h" |
| 20 #include "components/history/core/browser/history_service.h" | 20 #include "components/history/core/browser/history_service.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
| 25 | 25 |
| 26 class Profile; |
| 27 |
| 26 namespace safe_browsing { | 28 namespace safe_browsing { |
| 29 |
| 27 typedef std::vector<GURL> RedirectChain; | 30 typedef std::vector<GURL> RedirectChain; |
| 28 } | |
| 29 | |
| 30 class Profile; | |
| 31 | 31 |
| 32 class ThreatDetailsRedirectsCollector | 32 class ThreatDetailsRedirectsCollector |
| 33 : public base::RefCountedThreadSafe< | 33 : public base::RefCountedThreadSafe< |
| 34 ThreatDetailsRedirectsCollector, | 34 ThreatDetailsRedirectsCollector, |
| 35 content::BrowserThread::DeleteOnUIThread>, | 35 content::BrowserThread::DeleteOnUIThread>, |
| 36 public content::NotificationObserver { | 36 public content::NotificationObserver { |
| 37 public: | 37 public: |
| 38 explicit ThreatDetailsRedirectsCollector(Profile* profile); | 38 explicit ThreatDetailsRedirectsCollector(Profile* profile); |
| 39 | 39 |
| 40 // Collects urls' redirects chain information from the history service. | 40 // Collects urls' redirects chain information from the history service. |
| 41 // We get access to history service via web_contents in UI thread. | 41 // We get access to history service via web_contents in UI thread. |
| 42 // Notice the callback will be posted to the IO thread. | 42 // Notice the callback will be posted to the IO thread. |
| 43 void StartHistoryCollection(const std::vector<GURL>& urls, | 43 void StartHistoryCollection(const std::vector<GURL>& urls, |
| 44 const base::Closure& callback); | 44 const base::Closure& callback); |
| 45 | 45 |
| 46 // Returns whether or not StartCacheCollection has been called. | 46 // Returns whether or not StartCacheCollection has been called. |
| 47 bool HasStarted() const; | 47 bool HasStarted() const; |
| 48 | 48 |
| 49 // Returns the redirect urls we get from history service | 49 // Returns the redirect urls we get from history service |
| 50 const std::vector<safe_browsing::RedirectChain>& GetCollectedUrls() const; | 50 const std::vector<RedirectChain>& GetCollectedUrls() const; |
| 51 | 51 |
| 52 // content::NotificationObserver | 52 // content::NotificationObserver |
| 53 void Observe(int type, | 53 void Observe(int type, |
| 54 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) override; | 55 const content::NotificationDetails& details) override; |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 friend struct content::BrowserThread::DeleteOnThread< | 58 friend struct content::BrowserThread::DeleteOnThread< |
| 59 content::BrowserThread::UI>; | 59 content::BrowserThread::UI>; |
| 60 friend class base::DeleteHelper<ThreatDetailsRedirectsCollector>; | 60 friend class base::DeleteHelper<ThreatDetailsRedirectsCollector>; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 78 base::Closure callback_; | 78 base::Closure callback_; |
| 79 | 79 |
| 80 // Sets to true once StartHistoryCollection is called | 80 // Sets to true once StartHistoryCollection is called |
| 81 bool has_started_; | 81 bool has_started_; |
| 82 | 82 |
| 83 // The urls we need to get redirects for | 83 // The urls we need to get redirects for |
| 84 std::vector<GURL> urls_; | 84 std::vector<GURL> urls_; |
| 85 // The iterator goes over urls_ | 85 // The iterator goes over urls_ |
| 86 std::vector<GURL>::iterator urls_it_; | 86 std::vector<GURL>::iterator urls_it_; |
| 87 // The collected directs from history service | 87 // The collected directs from history service |
| 88 std::vector<safe_browsing::RedirectChain> redirects_urls_; | 88 std::vector<RedirectChain> redirects_urls_; |
| 89 | 89 |
| 90 content::NotificationRegistrar registrar_; | 90 content::NotificationRegistrar registrar_; |
| 91 | 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsRedirectsCollector); | 92 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsRedirectsCollector); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace safe_browsing |
| 96 |
| 95 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | 97 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ |
| OLD | NEW |