| 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/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 522 |
| 523 void SafeBrowsingService::GetChunks(GetChunksCallback callback) { | 523 void SafeBrowsingService::GetChunks(GetChunksCallback callback) { |
| 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 525 DCHECK(enabled_); | 525 DCHECK(enabled_); |
| 526 DCHECK(!callback.is_null()); | 526 DCHECK(!callback.is_null()); |
| 527 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 527 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 528 &SafeBrowsingService::GetAllChunksFromDatabase, this, callback)); | 528 &SafeBrowsingService::GetAllChunksFromDatabase, this, callback)); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void SafeBrowsingService::AddChunks(const std::string& list, | 531 void SafeBrowsingService::AddChunks(const std::string& list, |
| 532 SBChunkList* chunks) { | 532 SBChunkList* chunks, |
| 533 AddChunksCallback callback) { |
| 533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 534 DCHECK(enabled_); | 535 DCHECK(enabled_); |
| 535 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 536 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 536 &SafeBrowsingService::HandleChunkForDatabase, this, list, chunks)); | 537 &SafeBrowsingService::HandleChunkForDatabase, this, list, chunks, |
| 538 callback)); |
| 537 } | 539 } |
| 538 | 540 |
| 539 void SafeBrowsingService::DeleteChunks( | 541 void SafeBrowsingService::DeleteChunks( |
| 540 std::vector<SBChunkDelete>* chunk_deletes) { | 542 std::vector<SBChunkDelete>* chunk_deletes) { |
| 541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 542 DCHECK(enabled_); | 544 DCHECK(enabled_); |
| 543 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 545 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 544 &SafeBrowsingService::DeleteDatabaseChunks, this, chunk_deletes)); | 546 &SafeBrowsingService::DeleteDatabaseChunks, this, chunk_deletes)); |
| 545 } | 547 } |
| 546 | 548 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 } | 897 } |
| 896 | 898 |
| 897 void SafeBrowsingService::OnGetAllChunksFromDatabase( | 899 void SafeBrowsingService::OnGetAllChunksFromDatabase( |
| 898 const std::vector<SBListChunkRanges>& lists, bool database_error, | 900 const std::vector<SBListChunkRanges>& lists, bool database_error, |
| 899 GetChunksCallback callback) { | 901 GetChunksCallback callback) { |
| 900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 901 if (enabled_) | 903 if (enabled_) |
| 902 callback.Run(lists, database_error); | 904 callback.Run(lists, database_error); |
| 903 } | 905 } |
| 904 | 906 |
| 905 void SafeBrowsingService::OnChunkInserted() { | 907 void SafeBrowsingService::OnAddChunksComplete(AddChunksCallback callback) { |
| 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 907 if (enabled_) | 909 if (enabled_) |
| 908 protocol_manager_->OnChunkInserted(); | 910 callback.Run(); |
| 909 } | 911 } |
| 910 | 912 |
| 911 void SafeBrowsingService::DatabaseLoadComplete() { | 913 void SafeBrowsingService::DatabaseLoadComplete() { |
| 912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 913 if (!enabled_) | 915 if (!enabled_) |
| 914 return; | 916 return; |
| 915 | 917 |
| 916 HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size()); | 918 HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size()); |
| 917 if (queued_checks_.empty()) | 919 if (queued_checks_.empty()) |
| 918 return; | 920 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 932 sb_check.urls.push_back(check.url); | 934 sb_check.urls.push_back(check.url); |
| 933 sb_check.client = check.client; | 935 sb_check.client = check.client; |
| 934 sb_check.threat_type = SB_THREAT_TYPE_SAFE; | 936 sb_check.threat_type = SB_THREAT_TYPE_SAFE; |
| 935 check.client->OnSafeBrowsingResult(sb_check); | 937 check.client->OnSafeBrowsingResult(sb_check); |
| 936 } | 938 } |
| 937 queued_checks_.pop_front(); | 939 queued_checks_.pop_front(); |
| 938 } | 940 } |
| 939 } | 941 } |
| 940 | 942 |
| 941 void SafeBrowsingService::HandleChunkForDatabase( | 943 void SafeBrowsingService::HandleChunkForDatabase( |
| 942 const std::string& list_name, SBChunkList* chunks) { | 944 const std::string& list_name, SBChunkList* chunks, |
| 945 AddChunksCallback callback) { |
| 943 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); | 946 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
| 944 if (chunks) { | 947 if (chunks) { |
| 945 GetDatabase()->InsertChunks(list_name, *chunks); | 948 GetDatabase()->InsertChunks(list_name, *chunks); |
| 946 delete chunks; | 949 delete chunks; |
| 947 } | 950 } |
| 948 BrowserThread::PostTask( | 951 BrowserThread::PostTask( |
| 949 BrowserThread::IO, FROM_HERE, | 952 BrowserThread::IO, FROM_HERE, |
| 950 base::Bind(&SafeBrowsingService::OnChunkInserted, this)); | 953 base::Bind(&SafeBrowsingService::OnAddChunksComplete, this, callback)); |
| 951 } | 954 } |
| 952 | 955 |
| 953 void SafeBrowsingService::DeleteDatabaseChunks( | 956 void SafeBrowsingService::DeleteDatabaseChunks( |
| 954 std::vector<SBChunkDelete>* chunk_deletes) { | 957 std::vector<SBChunkDelete>* chunk_deletes) { |
| 955 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); | 958 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
| 956 if (chunk_deletes) { | 959 if (chunk_deletes) { |
| 957 GetDatabase()->DeleteChunks(*chunk_deletes); | 960 GetDatabase()->DeleteChunks(*chunk_deletes); |
| 958 delete chunk_deletes; | 961 delete chunk_deletes; |
| 959 } | 962 } |
| 960 } | 963 } |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 Stop(); | 1447 Stop(); |
| 1445 | 1448 |
| 1446 if (csd_service_.get()) | 1449 if (csd_service_.get()) |
| 1447 csd_service_->SetEnabledAndRefreshState(enable); | 1450 csd_service_->SetEnabledAndRefreshState(enable); |
| 1448 if (download_service_.get()) { | 1451 if (download_service_.get()) { |
| 1449 download_service_->SetEnabled( | 1452 download_service_->SetEnabled( |
| 1450 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1453 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1451 switches::kDisableImprovedDownloadProtection)); | 1454 switches::kDisableImprovedDownloadProtection)); |
| 1452 } | 1455 } |
| 1453 } | 1456 } |
| OLD | NEW |