Chromium Code Reviews| 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 #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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/timer/elapsed_timer.h" | |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( | 19 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( |
| 19 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 20 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 20 content::PermissionType permission_type, | 21 content::PermissionType permission_type, |
| 21 const GURL& request_origin, | 22 const GURL& request_origin, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 PermissionBlacklistClient::~PermissionBlacklistClient() {} | 52 PermissionBlacklistClient::~PermissionBlacklistClient() {} |
| 52 | 53 |
| 53 void PermissionBlacklistClient::StartCheck(const GURL& request_origin) { | 54 void PermissionBlacklistClient::StartCheck(const GURL& request_origin) { |
| 54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 55 | 56 |
| 56 // Start the timer to interrupt into the client callback method with an | 57 // Start the timer to interrupt into the client callback method with an |
| 57 // empty response if Safe Browsing times out. | 58 // empty response if Safe Browsing times out. |
| 58 safe_browsing::ThreatMetadata empty_metadata; | 59 safe_browsing::ThreatMetadata empty_metadata; |
| 59 timer_ = base::MakeUnique<base::OneShotTimer>(); | 60 timer_ = base::MakeUnique<base::OneShotTimer>(); |
| 61 elapsed_timer_.reset(new base::ElapsedTimer()); | |
| 60 timer_->Start( | 62 timer_->Start( |
| 61 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_), | 63 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_), |
| 62 base::Bind(&PermissionBlacklistClient::OnCheckApiBlacklistUrlResult, this, | 64 base::Bind(&PermissionBlacklistClient::OnCheckApiBlacklistUrlResult, this, |
| 63 request_origin, empty_metadata)); | 65 request_origin, empty_metadata)); |
| 64 db_manager_->CheckApiBlacklistUrl(request_origin, this); | 66 db_manager_->CheckApiBlacklistUrl(request_origin, this); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void PermissionBlacklistClient::OnCheckApiBlacklistUrlResult( | 69 void PermissionBlacklistClient::OnCheckApiBlacklistUrlResult( |
| 68 const GURL& url, | 70 const GURL& url, |
| 69 const safe_browsing::ThreatMetadata& metadata) { | 71 const safe_browsing::ThreatMetadata& metadata) { |
| 70 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 72 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 71 | 73 |
| 72 if (timer_->IsRunning()) | 74 base::TimeDelta response_time = elapsed_timer_->Elapsed(); |
| 75 SafeBrowsingResponse response = SafeBrowsingResponse::NOT_BLACKLISTED; | |
| 76 | |
| 77 if (timer_->IsRunning()) { | |
| 73 timer_->Stop(); | 78 timer_->Stop(); |
| 74 else | 79 } else { |
| 75 db_manager_->CancelApiCheck(this); | 80 db_manager_->CancelApiCheck(this); |
| 81 response = SafeBrowsingResponse::TIMEOUT; | |
| 82 } | |
| 83 | |
| 76 timer_.reset(nullptr); | 84 timer_.reset(nullptr); |
| 77 | |
| 78 bool permission_blocked = | 85 bool permission_blocked = |
| 79 metadata.api_permissions.find( | 86 metadata.api_permissions.find( |
| 80 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( | 87 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( |
| 81 permission_type_)) != metadata.api_permissions.end(); | 88 permission_type_)) != metadata.api_permissions.end(); |
| 89 if (permission_blocked) | |
| 90 response = SafeBrowsingResponse::BLACKLISTED; | |
| 82 | 91 |
| 92 // record elapsed time in PermissionUmaUtil | |
|
dominickn
2017/01/27 06:05:46
This comment is probably not needed.
meredithl
2017/01/29 23:48:29
Done.
| |
| 93 PermissionUmaUtil::RecordSafeBrowsingResponse(response_time, response); | |
| 83 content::BrowserThread::PostTask( | 94 content::BrowserThread::PostTask( |
| 84 content::BrowserThread::UI, FROM_HERE, | 95 content::BrowserThread::UI, FROM_HERE, |
| 85 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, | 96 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, |
| 86 this, permission_blocked)); | 97 this, permission_blocked)); |
| 87 } | 98 } |
| 88 | 99 |
| 89 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( | 100 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( |
| 90 bool permission_blocked) { | 101 bool response) { |
| 91 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 92 | 103 |
| 93 if (is_active_) | 104 if (is_active_) |
| 94 callback_.Run(permission_blocked); | 105 callback_.Run(response); |
| 95 Release(); | 106 Release(); |
| 96 } | 107 } |
| 97 | 108 |
| 98 void PermissionBlacklistClient::WebContentsDestroyed() { | 109 void PermissionBlacklistClient::WebContentsDestroyed() { |
| 99 is_active_ = false; | 110 is_active_ = false; |
| 100 Observe(nullptr); | 111 Observe(nullptr); |
| 101 } | 112 } |
| OLD | NEW |