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 "chrome/browser/history/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
;
29 class MalwareDetailsRedirectsCollector
30 : public base::RefCountedThreadSafe
<
31 MalwareDetailsRedirectsCollector
,
32 content::BrowserThread::DeleteOnUIThread
>,
33 public content::NotificationObserver
{
35 explicit MalwareDetailsRedirectsCollector(Profile
* profile
);
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
);
43 // Returns whether or not StartCacheCollection has been called.
44 bool HasStarted() const;
46 // Returns the redirect urls we get from history service
47 const std::vector
<safe_browsing::RedirectChain
>& GetCollectedUrls() const;
49 // content::NotificationObserver
50 virtual void Observe(int type
,
51 const content::NotificationSource
& source
,
52 const content::NotificationDetails
& details
) override
;
55 friend struct content::BrowserThread::DeleteOnThread
<
56 content::BrowserThread::UI
>;
57 friend class base::DeleteHelper
<MalwareDetailsRedirectsCollector
>;
59 virtual ~MalwareDetailsRedirectsCollector();
61 void StartGetRedirects(const std::vector
<GURL
>& urls
);
62 void GetRedirects(const GURL
& url
);
63 void OnGotQueryRedirectsTo(const GURL
& url
,
64 const history::RedirectList
* redirect_list
);
66 // Posts the callback method back to IO thread when redirects collecting
71 base::CancelableTaskTracker request_tracker_
;
73 // Method we call when we are done. The caller must be alive for the
74 // whole time, we are modifying its state (see above).
75 base::Closure callback_
;
77 // Sets to true once StartHistoryCollection is called
80 // The urls we need to get redirects for
81 std::vector
<GURL
> urls_
;
82 // The iterator goes over urls_
83 std::vector
<GURL
>::iterator urls_it_
;
84 // The collected directs from history service
85 std::vector
<safe_browsing::RedirectChain
> redirects_urls_
;
87 content::NotificationRegistrar registrar_
;
89 DISALLOW_COPY_AND_ASSIGN(MalwareDetailsRedirectsCollector
);
92 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_