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 "chrome/browser/history/history_service.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "net/base/completion_callback.h"
24 namespace safe_browsing
{
25 typedef std::vector
<GURL
> RedirectChain
;
28 class MalwareDetailsRedirectsCollector
29 : public base::RefCountedThreadSafe
<
30 MalwareDetailsRedirectsCollector
,
31 content::BrowserThread::DeleteOnUIThread
>,
32 public content::NotificationObserver
{
34 explicit MalwareDetailsRedirectsCollector(Profile
* profile
);
36 // Collects urls' redirects chain information from the history service.
37 // We get access to history service via web_contents in UI thread.
38 // Notice the callback will be posted to the IO thread.
39 void StartHistoryCollection(const std::vector
<GURL
>& urls
,
40 const base::Closure
& callback
);
42 // Returns whether or not StartCacheCollection has been called.
43 bool HasStarted() const;
45 // Returns the redirect urls we get from history service
46 const std::vector
<safe_browsing::RedirectChain
>& GetCollectedUrls() const;
48 // content::NotificationObserver
49 virtual void Observe(int type
,
50 const content::NotificationSource
& source
,
51 const content::NotificationDetails
& details
) OVERRIDE
;
54 friend struct content::BrowserThread::DeleteOnThread
<
55 content::BrowserThread::UI
>;
56 friend class base::DeleteHelper
<MalwareDetailsRedirectsCollector
>;
58 virtual ~MalwareDetailsRedirectsCollector();
60 void StartGetRedirects(const std::vector
<GURL
>& urls
);
61 void GetRedirects(const GURL
& url
);
62 void OnGotQueryRedirectsTo(HistoryService::Handle handle
,
65 history::RedirectList
* redirect_list
);
67 // Posts the callback method back to IO thread when redirects collecting
72 CancelableRequestConsumer request_consumer_
;
74 // Method we call when we are done. The caller must be alive for the
75 // whole time, we are modifying its state (see above).
76 base::Closure callback_
;
78 // Sets to true once StartHistoryCollection is called
81 // The urls we need to get redirects for
82 std::vector
<GURL
> urls_
;
83 // The iterator goes over urls_
84 std::vector
<GURL
>::iterator urls_it_
;
85 // The collected directs from history service
86 std::vector
<safe_browsing::RedirectChain
> redirects_urls_
;
88 content::NotificationRegistrar registrar_
;
90 DISALLOW_COPY_AND_ASSIGN(MalwareDetailsRedirectsCollector
);
93 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_