OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/permissions/permission_util.h" | 12 #include "chrome/browser/permissions/permission_uma_util.h" |
11 #include "components/safe_browsing_db/database_manager.h" | 13 #include "components/safe_browsing_db/database_manager.h" |
12 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
13 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
14 | 16 |
15 class GURL; | 17 class GURL; |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 class WebContents; | 20 class WebContents; |
19 } | 21 } |
20 | 22 |
21 namespace base { | 23 namespace base { |
22 class OneShotTimer; | 24 class OneShotTimer; |
| 25 class ElapsedTimer; |
23 } | 26 } |
24 | 27 |
25 // The client used when checking whether a permission has been blacklisted by | 28 // 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 | 29 // Safe Browsing. The check is done asynchronously as no state can be stored in |
27 // PermissionContextBase (since additional permission requests may be made). | 30 // PermissionContextBase (since additional permission requests may be made). |
28 // This class must be created and destroyed on the UI thread. | 31 // This class must be created and destroyed on the UI thread. |
29 class PermissionBlacklistClient | 32 class PermissionBlacklistClient |
30 : public safe_browsing::SafeBrowsingDatabaseManager::Client, | 33 : public safe_browsing::SafeBrowsingDatabaseManager::Client, |
31 public base::RefCountedThreadSafe<PermissionBlacklistClient>, | 34 public base::RefCountedThreadSafe<PermissionBlacklistClient>, |
32 public content::WebContentsObserver { | 35 public content::WebContentsObserver { |
(...skipping 22 matching lines...) Expand all Loading... |
55 | 58 |
56 ~PermissionBlacklistClient() override; | 59 ~PermissionBlacklistClient() override; |
57 | 60 |
58 void StartCheck(const GURL& request_origin); | 61 void StartCheck(const GURL& request_origin); |
59 | 62 |
60 // SafeBrowsingDatabaseManager::Client implementation. | 63 // SafeBrowsingDatabaseManager::Client implementation. |
61 void OnCheckApiBlacklistUrlResult( | 64 void OnCheckApiBlacklistUrlResult( |
62 const GURL& url, | 65 const GURL& url, |
63 const safe_browsing::ThreatMetadata& metadata) override; | 66 const safe_browsing::ThreatMetadata& metadata) override; |
64 | 67 |
65 void EvaluateBlacklistResultOnUiThread(bool permission_blocked); | 68 void EvaluateBlacklistResultOnUiThread(bool response); |
66 | 69 |
67 // WebContentsObserver implementation. Sets a flag so that when the database | 70 // WebContentsObserver implementation. Sets a flag so that when the database |
68 // manager returns with a result, it won't attempt to run the callback with a | 71 // manager returns with a result, it won't attempt to run the callback with a |
69 // deleted WebContents. | 72 // deleted WebContents. |
70 void WebContentsDestroyed() override; | 73 void WebContentsDestroyed() override; |
71 | 74 |
72 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | 75 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; |
73 content::PermissionType permission_type_; | 76 content::PermissionType permission_type_; |
74 | 77 |
75 // PermissionContextBase callback to run on the UI thread. | 78 // PermissionContextBase callback to run on the UI thread. |
76 base::Callback<void(bool)> callback_; | 79 base::Callback<void(bool)> callback_; |
77 | 80 |
78 // Timer to abort the Safe Browsing check if it takes too long. Created and | 81 // Timer to abort the Safe Browsing check if it takes too long. Created and |
79 // used on the IO Thread. | 82 // used on the IO Thread. |
80 std::unique_ptr<base::OneShotTimer> timer_; | 83 std::unique_ptr<base::OneShotTimer> timer_; |
| 84 std::unique_ptr<base::ElapsedTimer> elapsed_timer_; |
81 int timeout_; | 85 int timeout_; |
82 | 86 |
83 // True if |callback_| should be invoked, if web_contents() is destroyed, this | 87 // True if |callback_| should be invoked, if web_contents() is destroyed, this |
84 // is set to false. | 88 // is set to false. |
85 bool is_active_; | 89 bool is_active_; |
86 | 90 |
87 DISALLOW_COPY_AND_ASSIGN(PermissionBlacklistClient); | 91 DISALLOW_COPY_AND_ASSIGN(PermissionBlacklistClient); |
88 }; | 92 }; |
89 | 93 |
90 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 94 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
OLD | NEW |