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

Side by Side Diff: chrome/browser/permissions/permission_blacklist_client.h

Issue 2626853002: Refactor blacklist client into own .h/.cc. (Closed)
Patch Set: Nits 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 | « chrome/browser/BUILD.gn ('k') | chrome/browser/permissions/permission_blacklist_client.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 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 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/permissions/permission_util.h"
11 #include "components/safe_browsing_db/database_manager.h"
12 #include "content/public/browser/permission_type.h"
13 #include "content/public/browser/web_contents_observer.h"
14
15 class GURL;
16
17 namespace content {
18 class WebContents;
19 }
20
21 namespace base {
22 class OneShotTimer;
23 }
24
25 // The client used when checking whether a permission has been blacklisted by
26 // Safe Browsing. The check is done asynchronously as no state can be stored in
27 // PermissionContextBase (since additional permission requests may be made).
28 // This class must be created and destroyed on the UI thread.
29 class PermissionBlacklistClient
30 : public safe_browsing::SafeBrowsingDatabaseManager::Client,
31 public base::RefCountedThreadSafe<PermissionBlacklistClient>,
32 public content::WebContentsObserver {
33 public:
34 static void CheckSafeBrowsingBlacklist(
35 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
36 content::PermissionType permission_type,
37 const GURL& request_origin,
38 content::WebContents* web_contents,
39 int timeout,
40 base::Callback<void(bool)> callback);
41
42 private:
43 friend class base::RefCountedThreadSafe<PermissionBlacklistClient>;
44
45 PermissionBlacklistClient(
46 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
47 content::PermissionType permission_type,
48 const GURL& request_origin,
49 content::WebContents* web_contents,
50 int timeout,
51 base::Callback<void(bool)> callback);
52
53 ~PermissionBlacklistClient() override;
54
55 void StartCheck(const GURL& request_origin);
56
57 // SafeBrowsingDatabaseManager::Client implementation.
58 void OnCheckApiBlacklistUrlResult(
59 const GURL& url,
60 const safe_browsing::ThreatMetadata& metadata) override;
61
62 void EvaluateBlacklistResultOnUiThread(bool permission_blocked);
63
64 // WebContentsObserver implementation. Sets a flag so that when the database
65 // manager returns with a result, it won't attempt to run the callback with a
66 // deleted WebContents.
67 void WebContentsDestroyed() override;
68
69 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_;
70 content::PermissionType permission_type_;
71
72 // PermissionContextBase callback to run on the UI thread.
73 base::Callback<void(bool)> callback_;
74
75 // Timer to abort the Safe Browsing check if it takes too long. Created and
76 // used on the IO Thread.
77 std::unique_ptr<base::OneShotTimer> timer_;
78 int timeout_;
79
80 // True if |callback_| should be invoked, if web_contents() is destroyed, this
81 // is set to false.
82 bool is_active_;
83
84 DISALLOW_COPY_AND_ASSIGN(PermissionBlacklistClient);
85 };
86
87 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/permissions/permission_blacklist_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698