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

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

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

Powered by Google App Engine
This is Rietveld 408576698