Convert SafeBrowsingBlockingPage and test to new Bind/Callback system.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / malware_details_history.h
blob59ccdf84ebbd3a4e319e68cf0a5704999bf94f6a
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.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_
7 #pragma once
9 // This class gets redirect chain for urls from the history service.
11 #include <string>
12 #include <vector>
14 #include "base/callback.h"
15 #include "base/hash_tables.h"
16 #include "base/memory/linked_ptr.h"
17 #include "base/memory/ref_counted.h"
18 #include "chrome/browser/history/history.h"
19 #include "content/browser/browser_thread.h"
20 #include "content/common/notification_observer.h"
21 #include "content/common/notification_registrar.h"
22 #include "net/base/completion_callback.h"
24 class TabContents;
26 namespace safe_browsing {
27 typedef std::vector<GURL> RedirectChain;
30 class MalwareDetailsRedirectsCollector
31 : public base::RefCountedThreadSafe<MalwareDetailsRedirectsCollector,
32 BrowserThread::DeleteOnUIThread>,
33 public NotificationObserver {
35 public:
36 explicit MalwareDetailsRedirectsCollector(Profile* profile);
37 virtual ~MalwareDetailsRedirectsCollector();
39 // Collects urls' redirects chain information from the history service.
40 // We get access to history service via tab_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 private:
52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
53 friend class DeleteTask<MalwareDetailsRedirectsCollector>;
55 Profile* profile_;
56 CancelableRequestConsumer request_consumer_;
58 // Method we call when we are done. The caller must be alive for the
59 // whole time, we are modifying its state (see above).
60 base::Closure callback_;
62 // Sets to true once StartHistoryCollection is called
63 bool has_started_;
65 // The urls we need to get redirects for
66 std::vector<GURL> urls_;
67 // The iterator goes over urls_
68 std::vector<GURL>::iterator urls_it_;
69 // The collected directs from history service
70 std::vector<safe_browsing::RedirectChain> redirects_urls_;
72 NotificationRegistrar registrar_;
74 void StartGetRedirects(const std::vector<GURL>& urls);
75 void GetRedirects(const GURL& url);
76 void OnGotQueryRedirectsTo(HistoryService::Handle handle,
77 GURL url,
78 bool success,
79 history::RedirectList* redirect_list);
81 // Posts the callback method back to IO thread when redirects collecting
82 // is all done.
83 void AllDone();
85 virtual void Observe(int type,
86 const NotificationSource& source,
87 const NotificationDetails& details) OVERRIDE;
89 DISALLOW_COPY_AND_ASSIGN(MalwareDetailsRedirectsCollector);
92 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_HISTORY_H_