OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_ |
| 7 #pragma once |
| 8 |
| 9 // This class gets redirect chain for urls from the history service. |
| 10 |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/hash_tables.h" |
| 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/ref_counted.h" |
| 17 #include "chrome/browser/history/history.h" |
| 18 #include "net/base/completion_callback.h" |
| 19 |
| 20 class TabContents; |
| 21 |
| 22 namespace safe_browsing { |
| 23 typedef std::vector<GURL> RedirectChain; |
| 24 } |
| 25 |
| 26 class MalwareDetailsRedirectsCollector |
| 27 : public base::RefCountedThreadSafe<MalwareDetailsRedirectsCollector> { |
| 28 |
| 29 public: |
| 30 MalwareDetailsRedirectsCollector(); |
| 31 virtual ~MalwareDetailsRedirectsCollector(); |
| 32 |
| 33 // Collects urls' redirects chain information from the history service. |
| 34 // We get access to history service via tab_contents in UI thread. |
| 35 // Notice the callback will be posted to the IO thread. |
| 36 void StartHistoryCollection(const std::vector<GURL>& urls, |
| 37 TabContents* tab_contents, |
| 38 Task* callback); |
| 39 |
| 40 // Returns whether or not StartCacheCollection has been called. |
| 41 bool HasStarted() const; |
| 42 |
| 43 // Returns the redirect urls we get from history service |
| 44 const std::vector<safe_browsing::RedirectChain>& GetCollectedUrls() const; |
| 45 |
| 46 // Sets the pointer to the history service. Use it in unittest. |
| 47 void SetHistory(HistoryService* history); |
| 48 |
| 49 private: |
| 50 TabContents* tab_contents_; |
| 51 HistoryService* history_; |
| 52 CancelableRequestConsumer request_consumer_; |
| 53 |
| 54 // Method we call when we are done. The caller must be alive for the |
| 55 // whole time, we are modifying its state (see above). |
| 56 Task* callback_; |
| 57 |
| 58 // Sets to true once StartHistoryCollection is called |
| 59 bool has_started_; |
| 60 |
| 61 // The urls we need to get redirects for |
| 62 std::vector<GURL> urls_; |
| 63 // The iterator goes over urls_ |
| 64 std::vector<GURL>::iterator urls_it_; |
| 65 // The collected directs from history service |
| 66 std::vector<safe_browsing::RedirectChain> redirects_urls_; |
| 67 |
| 68 void StartGetRedirects(const std::vector<GURL>& urls); |
| 69 void GetRedirects(const GURL& url); |
| 70 void OnGotQueryRedirectsTo(HistoryService::Handle handle, |
| 71 GURL url, |
| 72 bool success, |
| 73 history::RedirectList* redirect_list); |
| 74 |
| 75 // Posts the callback method back to IO thread when redirects collecting |
| 76 // is all done. |
| 77 void AllDone(); |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(MalwareDetailsRedirectsCollector); |
| 80 }; |
| 81 |
| 82 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_ |
OLD | NEW |