Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/safe_browsing/threat_details_history.h

Issue 2796123003: Componentize safe_browsing: factor out chrome/ deps in ThreatDetailsRedirectsCollector. (Closed)
Patch Set: fix crashes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/scoped_observer.h"
17 #include "base/sequenced_task_runner_helpers.h" 18 #include "base/sequenced_task_runner_helpers.h"
18 #include "base/task/cancelable_task_tracker.h" 19 #include "base/task/cancelable_task_tracker.h"
19 #include "components/history/core/browser/history_service.h" 20 #include "components/history/core/browser/history_service_observer.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23 #include "net/base/completion_callback.h" 22 #include "net/base/completion_callback.h"
24 23
25 class Profile;
26
27 namespace safe_browsing { 24 namespace safe_browsing {
28 25
29 typedef std::vector<GURL> RedirectChain; 26 typedef std::vector<GURL> RedirectChain;
30 27
31 class ThreatDetailsRedirectsCollector 28 class ThreatDetailsRedirectsCollector
32 : public base::RefCountedThreadSafe< 29 : public base::RefCountedThreadSafe<
33 ThreatDetailsRedirectsCollector, 30 ThreatDetailsRedirectsCollector,
34 content::BrowserThread::DeleteOnUIThread>, 31 content::BrowserThread::DeleteOnUIThread>,
35 public content::NotificationObserver { 32 public history::HistoryServiceObserver {
36 public: 33 public:
37 explicit ThreatDetailsRedirectsCollector(Profile* profile); 34 explicit ThreatDetailsRedirectsCollector(
35 const base::WeakPtr<history::HistoryService>& history_service);
38 36
39 // Collects urls' redirects chain information from the history service. 37 // Collects urls' redirects chain information from the history service.
40 // We get access to history service via web_contents in UI thread. 38 // We get access to history service via web_contents in UI thread.
41 // Notice the callback will be posted to the IO thread. 39 // Notice the callback will be posted to the IO thread.
42 void StartHistoryCollection(const std::vector<GURL>& urls, 40 void StartHistoryCollection(const std::vector<GURL>& urls,
43 const base::Closure& callback); 41 const base::Closure& callback);
44 42
45 // Returns whether or not StartCacheCollection has been called. 43 // Returns whether or not StartCacheCollection has been called.
46 bool HasStarted() const; 44 bool HasStarted() const;
47 45
48 // Returns the redirect urls we get from history service 46 // Returns the redirect urls we get from history service
49 const std::vector<RedirectChain>& GetCollectedUrls() const; 47 const std::vector<RedirectChain>& GetCollectedUrls() const;
50 48
51 // content::NotificationObserver 49 // history::HistoryServiceObserver
52 void Observe(int type, 50 void HistoryServiceBeingDeleted(
53 const content::NotificationSource& source, 51 history::HistoryService* history_service) override;
54 const content::NotificationDetails& details) override;
55 52
56 private: 53 private:
57 friend struct content::BrowserThread::DeleteOnThread< 54 friend struct content::BrowserThread::DeleteOnThread<
58 content::BrowserThread::UI>; 55 content::BrowserThread::UI>;
59 friend class base::DeleteHelper<ThreatDetailsRedirectsCollector>; 56 friend class base::DeleteHelper<ThreatDetailsRedirectsCollector>;
60 57
61 ~ThreatDetailsRedirectsCollector() override; 58 ~ThreatDetailsRedirectsCollector() override;
62 59
63 void StartGetRedirects(const std::vector<GURL>& urls); 60 void StartGetRedirects(const std::vector<GURL>& urls);
64 void GetRedirects(const GURL& url); 61 void GetRedirects(const GURL& url);
65 void OnGotQueryRedirectsTo(const GURL& url, 62 void OnGotQueryRedirectsTo(const GURL& url,
66 const history::RedirectList* redirect_list); 63 const history::RedirectList* redirect_list);
67 64
68 // Posts the callback method back to IO thread when redirects collecting 65 // Posts the callback method back to IO thread when redirects collecting
69 // is all done. 66 // is all done.
70 void AllDone(); 67 void AllDone();
71 68
72 Profile* profile_;
73 base::CancelableTaskTracker request_tracker_; 69 base::CancelableTaskTracker request_tracker_;
74 70
75 // Method we call when we are done. The caller must be alive for the 71 // Method we call when we are done. The caller must be alive for the
76 // whole time, we are modifying its state (see above). 72 // whole time, we are modifying its state (see above).
77 base::Closure callback_; 73 base::Closure callback_;
78 74
79 // Sets to true once StartHistoryCollection is called 75 // Sets to true once StartHistoryCollection is called
80 bool has_started_; 76 bool has_started_;
81 77
82 // The urls we need to get redirects for 78 // The urls we need to get redirects for
83 std::vector<GURL> urls_; 79 std::vector<GURL> urls_;
84 // The iterator goes over urls_ 80 // The iterator goes over urls_
85 std::vector<GURL>::iterator urls_it_; 81 std::vector<GURL>::iterator urls_it_;
86 // The collected directs from history service 82 // The collected directs from history service
87 std::vector<RedirectChain> redirects_urls_; 83 std::vector<RedirectChain> redirects_urls_;
88 84
89 content::NotificationRegistrar registrar_; 85 base::WeakPtr<history::HistoryService> history_service_;
86 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
87 history_service_observer_;
90 88
91 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsRedirectsCollector); 89 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsRedirectsCollector);
92 }; 90 };
93 91
94 } // namespace safe_browsing 92 } // namespace safe_browsing
95 93
96 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_ 94 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_HISTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698