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.
4 
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_TAB_OBSERVER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_TAB_OBSERVER_H_
7 
8 #include <memory>
9 
10 #include "base/macros.h"
11 #include "components/prefs/pref_change_registrar.h"
12 #include "content/public/browser/web_contents_user_data.h"
13 
14 namespace content {
15 class WebContents;
16 }
17 
18 namespace safe_browsing {
19 
20 class ClientSideDetectionHost;
21 
22 // Per-tab class to handle safe-browsing functionality.
23 class SafeBrowsingTabObserver
24     : public content::WebContentsUserData<SafeBrowsingTabObserver> {
25  public:
26   ~SafeBrowsingTabObserver() override;
27 
28  private:
29   explicit SafeBrowsingTabObserver(content::WebContents* web_contents);
30   friend class content::WebContentsUserData<SafeBrowsingTabObserver>;
31 
32   // Internal helpers ----------------------------------------------------------
33 
34   // Create or destroy SafebrowsingDetectionHost as needed if the user's
35   // safe browsing preference has changed.
36   void UpdateSafebrowsingDetectionHost();
37 
38   // Handles IPCs.
39   std::unique_ptr<ClientSideDetectionHost> safebrowsing_detection_host_;
40 
41   // Our owning WebContents.
42   content::WebContents* web_contents_;
43 
44   PrefChangeRegistrar pref_change_registrar_;
45 
46   WEB_CONTENTS_USER_DATA_KEY_DECL();
47 
48   DISALLOW_COPY_AND_ASSIGN(SafeBrowsingTabObserver);
49 };
50 
51 }  // namespace safe_browsing
52 
53 #endif  // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_TAB_OBSERVER_H_
54