| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | |
| 7 | |
| 8 // This class gets redirect chain for urls from the history service. | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/containers/hash_tables.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/memory/ref_counted.h" | |
| 17 #include "base/scoped_observer.h" | |
| 18 #include "base/sequenced_task_runner_helpers.h" | |
| 19 #include "base/task/cancelable_task_tracker.h" | |
| 20 #include "components/history/core/browser/history_service_observer.h" | |
| 21 #include "content/public/browser/browser_thread.h" | |
| 22 #include "net/base/completion_callback.h" | |
| 23 | |
| 24 namespace safe_browsing { | |
| 25 | |
| 26 typedef std::vector<GURL> RedirectChain; | |
| 27 | |
| 28 class ThreatDetailsRedirectsCollector | |
| 29 : public base::RefCountedThreadSafe< | |
| 30 ThreatDetailsRedirectsCollector, | |
| 31 content::BrowserThread::DeleteOnUIThread>, | |
| 32 public history::HistoryServiceObserver { | |
| 33 public: | |
| 34 explicit ThreatDetailsRedirectsCollector( | |
| 35 const base::WeakPtr<history::HistoryService>& history_service); | |
| 36 | |
| 37 // Collects urls' redirects chain information from the history service. | |
| 38 // We get access to history service via web_contents in UI thread. | |
| 39 // Notice the callback will be posted to the IO thread. | |
| 40 void StartHistoryCollection(const std::vector<GURL>& urls, | |
| 41 const base::Closure& callback); | |
| 42 | |
| 43 // Returns whether or not StartCacheCollection has been called. | |
| 44 bool HasStarted() const; | |
| 45 | |
| 46 // Returns the redirect urls we get from history service | |
| 47 const std::vector<RedirectChain>& GetCollectedUrls() const; | |
| 48 | |
| 49 // history::HistoryServiceObserver | |
| 50 void HistoryServiceBeingDeleted( | |
| 51 history::HistoryService* history_service) override; | |
| 52 | |
| 53 private: | |
| 54 friend struct content::BrowserThread::DeleteOnThread< | |
| 55 content::BrowserThread::UI>; | |
| 56 friend class base::DeleteHelper<ThreatDetailsRedirectsCollector>; | |
| 57 | |
| 58 ~ThreatDetailsRedirectsCollector() override; | |
| 59 | |
| 60 void StartGetRedirects(const std::vector<GURL>& urls); | |
| 61 void GetRedirects(const GURL& url); | |
| 62 void OnGotQueryRedirectsTo(const GURL& url, | |
| 63 const history::RedirectList* redirect_list); | |
| 64 | |
| 65 // Posts the callback method back to IO thread when redirects collecting | |
| 66 // is all done. | |
| 67 void AllDone(); | |
| 68 | |
| 69 base::CancelableTaskTracker request_tracker_; | |
| 70 | |
| 71 // Method we call when we are done. The caller must be alive for the | |
| 72 // whole time, we are modifying its state (see above). | |
| 73 base::Closure callback_; | |
| 74 | |
| 75 // Sets to true once StartHistoryCollection is called | |
| 76 bool has_started_; | |
| 77 | |
| 78 // The urls we need to get redirects for | |
| 79 std::vector<GURL> urls_; | |
| 80 // The iterator goes over urls_ | |
| 81 std::vector<GURL>::iterator urls_it_; | |
| 82 // The collected directs from history service | |
| 83 std::vector<RedirectChain> redirects_urls_; | |
| 84 | |
| 85 base::WeakPtr<history::HistoryService> history_service_; | |
| 86 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | |
| 87 history_service_observer_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsRedirectsCollector); | |
| 90 }; | |
| 91 | |
| 92 } // namespace safe_browsing | |
| 93 | |
| 94 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ | |
| OLD | NEW |