Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: components/safe_browsing/base_safe_browsing_service.h

Issue 2605213002: componentize SafeBrowsingService (Closed)
Patch Set: Remove explicit return statements Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/safe_browsing/DEPS ('k') | components/safe_browsing/base_safe_browsing_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017 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 // The Safe Browsing service is responsible for downloading anti-phishing and
6 // anti-malware tables and checking urls against them.
7
8 #ifndef COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_SERVICE_H_
9 #define COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_SERVICE_H_
10
11 #include <map>
12 #include <memory>
13 #include <string>
14
15 #include "base/callback_list.h"
16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h"
18 #include "content/public/browser/browser_thread.h"
19
20 namespace net {
21 class URLRequest;
22 class URLRequestContextGetter;
23 }
24
25 namespace safe_browsing {
26 struct ResourceRequestInfo;
27 class SafeBrowsingDatabaseManager;
28
29 // Construction needs to happen on the main thread.
30 // The BaseSafeBrowsingService owns both the UI and Database managers which do
31 // the heavylifting of safebrowsing service. Both of these managers stay
32 // alive until BaseSafeBrowsingService is destroyed, however, they are disabled
33 // permanently when Shutdown method is called.
34 class BaseSafeBrowsingService : public base::RefCountedThreadSafe<
35 BaseSafeBrowsingService,
36 content::BrowserThread::DeleteOnUIThread> {
37 public:
38 // Called on the UI thread to initialize the service.
39 virtual void Initialize();
40
41 // Called on the main thread to let us know that the io_thread is going away.
42 virtual void ShutDown();
43
44 // Get current enabled status. Must be called on IO thread.
45 bool enabled() const {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
47 return enabled_;
48 }
49
50 virtual scoped_refptr<net::URLRequestContextGetter> url_request_context();
51
52 // This returns either the v3 or the v4 database manager, depending on
53 // the experiment settings.
54 virtual const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager()
55 const;
56
57 // Observes resource requests made by the renderer and reports suspicious
58 // activity.
59 void OnResourceRequest(const net::URLRequest* request);
60
61 // Type for subscriptions to SafeBrowsing service state.
62 typedef base::CallbackList<void(void)>::Subscription StateSubscription;
63
64 // Adds a listener for when SafeBrowsing preferences might have changed. To
65 // get the current state, the callback should call
66 // SafeBrowsingService::enabled_by_prefs(). Should only be called on the UI
67 // thread.
68 std::unique_ptr<StateSubscription> RegisterStateCallback(
69 const base::Callback<void(void)>& callback);
70
71 protected:
72 // Creates the safe browsing service. Need to initialize before using.
73 BaseSafeBrowsingService();
74
75 virtual ~BaseSafeBrowsingService();
76
77 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager();
78
79 // Whether the service is running. 'enabled_' is used by
80 // BaseSafeBrowsingService on the IO thread during normal operations.
81 bool enabled_;
82
83 // The database manager handles the database and download logic. Accessed on
84 // both UI and IO thread.
85 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
86
87 // Callbacks when SafeBrowsing state might have changed.
88 // Should only be accessed on the UI thread.
89 base::CallbackList<void(void)> state_callback_list_;
90
91 private:
92 friend struct content::BrowserThread::DeleteOnThread<
93 content::BrowserThread::UI>;
94 friend class base::DeleteHelper<BaseSafeBrowsingService>;
95
96 // Process the observed resource requests on the UI thread.
97 void ProcessResourceRequest(const ResourceRequestInfo& request);
98
99 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingService);
100 };
101
102 } // namespace safe_browsing
103
104 #endif // COMPONENTS_SAFE_BROWSING_BASE_SAFE_BROWSING_SERVICE_H_
OLDNEW
« no previous file with comments | « components/safe_browsing/DEPS ('k') | components/safe_browsing/base_safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698