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.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_
8 // This class gets redirect chain for urls from the history service.
13 #include "base/callback.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/sequenced_task_runner_helpers.h"
18 #include "base/task/cancelable_task_tracker.h"
19 #include "components/history/core/browser/history_service.h"
20 #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"
25 namespace safe_browsing
{
26 typedef std::vector
<GURL
> RedirectChain
;
31 class MalwareDetailsRedirectsCollector
32 : public base::RefCountedThreadSafe
<
33 MalwareDetailsRedirectsCollector
,
34 content::BrowserThread::DeleteOnUIThread
>,
35 public content::NotificationObserver
{
37 explicit MalwareDetailsRedirectsCollector(Profile
* profile
);
39 // Collects urls' redirects chain information from the history service.
40 // We get access to history service via web_contents in UI thread.
41 // Notice the callback will be posted to the IO thread.
42 void StartHistoryCollection(const std::vector
<GURL
>& urls
,
43 const base::Closure
& callback
);
45 // Returns whether or not StartCacheCollection has been called.
46 bool HasStarted() const;
48 // Returns the redirect urls we get from history service
49 const std::vector
<safe_browsing::RedirectChain
>& GetCollectedUrls() const;
51 // content::NotificationObserver
52 void Observe(int type
,
53 const content::NotificationSource
& source
,
54 const content::NotificationDetails
& details
) override
;
57 friend struct content::BrowserThread::DeleteOnThread
<
58 content::BrowserThread::UI
>;
59 friend class base::DeleteHelper
<MalwareDetailsRedirectsCollector
>;
61 ~MalwareDetailsRedirectsCollector() override
;
63 void StartGetRedirects(const std::vector
<GURL
>& urls
);
64 void GetRedirects(const GURL
& url
);
65 void OnGotQueryRedirectsTo(const GURL
& url
,
66 const history::RedirectList
* redirect_list
);
68 // Posts the callback method back to IO thread when redirects collecting
73 base::CancelableTaskTracker request_tracker_
;
75 // Method we call when we are done. The caller must be alive for the
76 // whole time, we are modifying its state (see above).
77 base::Closure callback_
;
79 // Sets to true once StartHistoryCollection is called
82 // The urls we need to get redirects for
83 std::vector
<GURL
> urls_
;
84 // The iterator goes over urls_
85 std::vector
<GURL
>::iterator urls_it_
;
86 // The collected directs from history service
87 std::vector
<safe_browsing::RedirectChain
> redirects_urls_
;
89 content::NotificationRegistrar registrar_
;
91 DISALLOW_COPY_AND_ASSIGN(MalwareDetailsRedirectsCollector
);
94 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_