Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/safe_browsing/ui_manager.h" | 5 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/debug/leak_tracker.h" | 10 #include "base/debug/leak_tracker.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 const base::Closure& callback) { | 274 const base::Closure& callback) { |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 276 BrowserThread::PostTaskAndReply( | 276 BrowserThread::PostTaskAndReply( |
| 277 BrowserThread::IO, FROM_HERE, | 277 BrowserThread::IO, FROM_HERE, |
| 278 base::Bind( | 278 base::Bind( |
| 279 &SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread, this, | 279 &SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread, this, |
| 280 serialized_report), | 280 serialized_report), |
| 281 callback); | 281 callback); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void SafeBrowsingUIManager::ReportPermissionAction( | |
| 285 const GURL& origin, | |
| 286 content::PermissionType permission, | |
| 287 PermissionAction action) { | |
| 288 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 289 | |
| 290 // Do not report permission action when the permission action reporting | |
| 291 // flag is not enabled. | |
| 292 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 293 switches::kEnablePermissionActionReporting)) { | |
| 294 return; | |
| 295 } | |
| 296 | |
| 297 Profile* profile = ProfileManager::GetLastUsedProfile(); | |
|
raymes
2016/06/16 01:10:23
We should use the actual profile (as discussed).
stefanocs
2016/06/16 01:52:20
Done.
| |
| 298 | |
| 299 // Do not report when SafeBrowsing is not enabled. | |
| 300 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | |
|
raymes
2016/06/16 01:10:22
Let's check with nparker for this check.
raymes
2016/06/16 01:10:23
nit: no {} for single-line if statements (and belo
stefanocs
2016/06/16 01:52:20
Acknowledged.
stefanocs
2016/06/16 01:52:20
Done.
| |
| 301 return; | |
| 302 } | |
| 303 // Do not report if profile doesn't have profile sync service. | |
| 304 if (!ProfileSyncServiceFactory::HasProfileSyncService(profile)) { | |
| 305 return; | |
| 306 } | |
| 307 | |
| 308 ProfileSyncService* profile_sync_service = | |
| 309 ProfileSyncServiceFactory::GetForProfile(profile); | |
| 310 syncer::ModelTypeSet preferred_data_types = | |
| 311 profile_sync_service->GetPreferredDataTypes(); | |
| 312 | |
| 313 // Do not report if profile can't start sync immediately. | |
| 314 if (!profile_sync_service->CanSyncStart()) { | |
|
raymes
2016/06/16 01:10:23
Let's check with pavely about how to find out:
-Wh
stefanocs
2016/06/16 01:52:20
Acknowledged.
| |
| 315 return; | |
| 316 } | |
| 317 // Do not report if Chrome Tab Sync is not enabled. | |
| 318 if (!preferred_data_types.Has(syncer::PROXY_TABS)) { | |
| 319 return; | |
| 320 } | |
| 321 // Do not report if Chrome Pref Sync is not enabled. | |
| 322 if (!preferred_data_types.Has(syncer::PREFERENCES)) { | |
| 323 return; | |
| 324 } | |
| 325 | |
| 326 BrowserThread::PostTask( | |
| 327 BrowserThread::IO, FROM_HERE, | |
| 328 base::Bind(&SafeBrowsingUIManager::ReportPermissionActionOnIOThread, this, | |
| 329 origin, permission, action)); | |
| 330 } | |
| 331 | |
| 284 void SafeBrowsingUIManager::AddObserver(Observer* observer) { | 332 void SafeBrowsingUIManager::AddObserver(Observer* observer) { |
| 285 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 286 observer_list_.AddObserver(observer); | 334 observer_list_.AddObserver(observer); |
| 287 } | 335 } |
| 288 | 336 |
| 289 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) { | 337 void SafeBrowsingUIManager::RemoveObserver(Observer* observer) { |
| 290 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 291 observer_list_.RemoveObserver(observer); | 339 observer_list_.RemoveObserver(observer); |
| 292 } | 340 } |
| 293 | 341 |
| 294 void SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread( | 342 void SafeBrowsingUIManager::ReportInvalidCertificateChainOnIOThread( |
| 295 const std::string& serialized_report) { | 343 const std::string& serialized_report) { |
| 296 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 344 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 297 | 345 |
| 298 // The service may delete the ping manager (i.e. when user disabling service, | 346 // The service may delete the ping manager (i.e. when user disabling service, |
| 299 // etc). This happens on the IO thread. | 347 // etc). This happens on the IO thread. |
| 300 if (!sb_service_ || !sb_service_->ping_manager()) | 348 if (!sb_service_ || !sb_service_->ping_manager()) |
| 301 return; | 349 return; |
| 302 | 350 |
| 303 sb_service_->ping_manager()->ReportInvalidCertificateChain(serialized_report); | 351 sb_service_->ping_manager()->ReportInvalidCertificateChain(serialized_report); |
| 304 } | 352 } |
| 305 | 353 |
| 354 void SafeBrowsingUIManager::ReportPermissionActionOnIOThread( | |
| 355 const GURL& origin, | |
| 356 content::PermissionType permission, | |
| 357 PermissionAction action) { | |
| 358 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 359 | |
| 360 // The service may delete the ping manager (i.e. when user disabling service, | |
| 361 // etc). This happens on the IO thread. | |
| 362 if (!sb_service_ || !sb_service_->ping_manager()) | |
| 363 return; | |
| 364 | |
| 365 sb_service_->ping_manager()->ReportPermissionAction(origin, permission, | |
| 366 action); | |
| 367 } | |
| 368 | |
| 306 // If the user had opted-in to send ThreatDetails, this gets called | 369 // If the user had opted-in to send ThreatDetails, this gets called |
| 307 // when the report is ready. | 370 // when the report is ready. |
| 308 void SafeBrowsingUIManager::SendSerializedThreatDetails( | 371 void SafeBrowsingUIManager::SendSerializedThreatDetails( |
| 309 const std::string& serialized) { | 372 const std::string& serialized) { |
| 310 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 373 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 311 | 374 |
| 312 // The service may delete the ping manager (i.e. when user disabling service, | 375 // The service may delete the ping manager (i.e. when user disabling service, |
| 313 // etc). This happens on the IO thread. | 376 // etc). This happens on the IO thread. |
| 314 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL) | 377 if (sb_service_.get() == NULL || sb_service_->ping_manager() == NULL) |
| 315 return; | 378 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 } | 428 } |
| 366 | 429 |
| 367 WhitelistUrlSet* site_list = | 430 WhitelistUrlSet* site_list = |
| 368 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); | 431 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); |
| 369 if (!site_list) | 432 if (!site_list) |
| 370 return false; | 433 return false; |
| 371 return site_list->Contains(maybe_whitelisted_url); | 434 return site_list->Contains(maybe_whitelisted_url); |
| 372 } | 435 } |
| 373 | 436 |
| 374 } // namespace safe_browsing | 437 } // namespace safe_browsing |
| OLD | NEW |