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

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

Issue 2684523002: Check result of ApiBlacklist query in client. (Closed)
Patch Set: Check callback. Created 3 years, 10 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 | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/permissions/permission_blacklist_client.h" 5 #include "chrome/browser/permissions/permission_blacklist_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 23 matching lines...) Expand all
34 const GURL& request_origin, 34 const GURL& request_origin,
35 content::WebContents* web_contents, 35 content::WebContents* web_contents,
36 int timeout, 36 int timeout,
37 base::Callback<void(bool)> callback) 37 base::Callback<void(bool)> callback)
38 : content::WebContentsObserver(web_contents), 38 : content::WebContentsObserver(web_contents),
39 db_manager_(db_manager), 39 db_manager_(db_manager),
40 permission_type_(permission_type), 40 permission_type_(permission_type),
41 callback_(callback), 41 callback_(callback),
42 timeout_(timeout), 42 timeout_(timeout),
43 is_active_(true) { 43 is_active_(true) {
44 // Balanced by a call to Release() in OnCheckApiBlacklistUrlResult(). 44 // Balanced by a call to Release() in EvaluateBlacklistResultOnUiThread().
45 AddRef(); 45 AddRef();
46 content::BrowserThread::PostTask( 46 content::BrowserThread::PostTask(
47 content::BrowserThread::IO, FROM_HERE, 47 content::BrowserThread::IO, FROM_HERE,
48 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); 48 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin));
49 } 49 }
50 50
51 PermissionBlacklistClient::~PermissionBlacklistClient() {} 51 PermissionBlacklistClient::~PermissionBlacklistClient() {}
52 52
53 void PermissionBlacklistClient::StartCheck(const GURL& request_origin) { 53 void PermissionBlacklistClient::StartCheck(const GURL& request_origin) {
54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
55 55
56 // Start the timer to interrupt into the client callback method with an 56 // Start the timer to interrupt into the client callback method with an
57 // empty response if Safe Browsing times out. 57 // empty response if Safe Browsing times out.
58 safe_browsing::ThreatMetadata empty_metadata; 58 safe_browsing::ThreatMetadata empty_metadata;
59 timer_ = base::MakeUnique<base::OneShotTimer>(); 59 timer_ = base::MakeUnique<base::OneShotTimer>();
60 timer_->Start( 60 timer_->Start(
61 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_), 61 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_),
62 base::Bind(&PermissionBlacklistClient::OnCheckApiBlacklistUrlResult, this, 62 base::Bind(&PermissionBlacklistClient::OnCheckApiBlacklistUrlResult, this,
63 request_origin, empty_metadata)); 63 request_origin, empty_metadata));
64 db_manager_->CheckApiBlacklistUrl(request_origin, this); 64 // If CheckApiBlacklistUrl returns true, no asynchronous call to |this| will
65 // be made, so just directly call through to OnCheckApiBlacklistUrlResult.
66 if (db_manager_->CheckApiBlacklistUrl(request_origin, this))
67 OnCheckApiBlacklistUrlResult(request_origin, empty_metadata);
65 } 68 }
66 69
67 void PermissionBlacklistClient::OnCheckApiBlacklistUrlResult( 70 void PermissionBlacklistClient::OnCheckApiBlacklistUrlResult(
68 const GURL& url, 71 const GURL& url,
69 const safe_browsing::ThreatMetadata& metadata) { 72 const safe_browsing::ThreatMetadata& metadata) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 73 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
71
72 if (timer_->IsRunning()) 74 if (timer_->IsRunning())
73 timer_->Stop(); 75 timer_->Stop();
74 else 76 else
75 db_manager_->CancelApiCheck(this); 77 db_manager_->CancelApiCheck(this);
76 timer_.reset(nullptr); 78 timer_.reset(nullptr);
77 79
78 bool permission_blocked = 80 bool permission_blocked =
79 metadata.api_permissions.find( 81 metadata.api_permissions.find(
80 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( 82 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName(
81 permission_type_)) != metadata.api_permissions.end(); 83 permission_type_)) != metadata.api_permissions.end();
(...skipping 10 matching lines...) Expand all
92 94
93 if (is_active_) 95 if (is_active_)
94 callback_.Run(permission_blocked); 96 callback_.Run(permission_blocked);
95 Release(); 97 Release();
96 } 98 }
97 99
98 void PermissionBlacklistClient::WebContentsDestroyed() { 100 void PermissionBlacklistClient::WebContentsDestroyed() {
99 is_active_ = false; 101 is_active_ = false;
100 Observe(nullptr); 102 Observe(nullptr);
101 } 103 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698