| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 if ((*it)->client) | 570 if ((*it)->client) |
| 571 (*it)->client->OnSafeBrowsingResult((*it)->url, URL_SAFE); | 571 (*it)->client->OnSafeBrowsingResult((*it)->url, URL_SAFE); |
| 572 delete *it; | 572 delete *it; |
| 573 } | 573 } |
| 574 checks_.clear(); | 574 checks_.clear(); |
| 575 | 575 |
| 576 gethash_requests_.clear(); | 576 gethash_requests_.clear(); |
| 577 } | 577 } |
| 578 | 578 |
| 579 bool SafeBrowsingService::DatabaseAvailable() const { | 579 bool SafeBrowsingService::DatabaseAvailable() const { |
| 580 AutoLock lock(database_lock_); | 580 base::AutoLock lock(database_lock_); |
| 581 return !closing_database_ && (database_ != NULL); | 581 return !closing_database_ && (database_ != NULL); |
| 582 } | 582 } |
| 583 | 583 |
| 584 bool SafeBrowsingService::MakeDatabaseAvailable() { | 584 bool SafeBrowsingService::MakeDatabaseAvailable() { |
| 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 586 DCHECK(enabled_); | 586 DCHECK(enabled_); |
| 587 if (DatabaseAvailable()) | 587 if (DatabaseAvailable()) |
| 588 return true; | 588 return true; |
| 589 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 589 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |
| 590 NewRunnableMethod(this, &SafeBrowsingService::GetDatabase)); | 590 NewRunnableMethod(this, &SafeBrowsingService::GetDatabase)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 603 | 603 |
| 604 Time before = Time::Now(); | 604 Time before = Time::Now(); |
| 605 | 605 |
| 606 SafeBrowsingDatabase* database = | 606 SafeBrowsingDatabase* database = |
| 607 SafeBrowsingDatabase::Create(enable_download_protection_); | 607 SafeBrowsingDatabase::Create(enable_download_protection_); |
| 608 | 608 |
| 609 database->Init(path); | 609 database->Init(path); |
| 610 { | 610 { |
| 611 // Acquiring the lock here guarantees correct ordering between the writes to | 611 // Acquiring the lock here guarantees correct ordering between the writes to |
| 612 // the new database object above, and the setting of |databse_| below. | 612 // the new database object above, and the setting of |databse_| below. |
| 613 AutoLock lock(database_lock_); | 613 base::AutoLock lock(database_lock_); |
| 614 database_ = database; | 614 database_ = database; |
| 615 } | 615 } |
| 616 | 616 |
| 617 BrowserThread::PostTask( | 617 BrowserThread::PostTask( |
| 618 BrowserThread::IO, FROM_HERE, | 618 BrowserThread::IO, FROM_HERE, |
| 619 NewRunnableMethod(this, &SafeBrowsingService::DatabaseLoadComplete)); | 619 NewRunnableMethod(this, &SafeBrowsingService::DatabaseLoadComplete)); |
| 620 | 620 |
| 621 UMA_HISTOGRAM_TIMES("SB2.DatabaseOpen", Time::Now() - before); | 621 UMA_HISTOGRAM_TIMES("SB2.DatabaseOpen", Time::Now() - before); |
| 622 return database_; | 622 return database_; |
| 623 } | 623 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 807 |
| 808 // Because |closing_database_| is true, nothing on the IO thread will be | 808 // Because |closing_database_| is true, nothing on the IO thread will be |
| 809 // accessing the database, so it's safe to delete and then NULL the pointer. | 809 // accessing the database, so it's safe to delete and then NULL the pointer. |
| 810 delete database_; | 810 delete database_; |
| 811 database_ = NULL; | 811 database_ = NULL; |
| 812 | 812 |
| 813 // Acquiring the lock here guarantees correct ordering between the resetting | 813 // Acquiring the lock here guarantees correct ordering between the resetting |
| 814 // of |database_| above and of |closing_database_| below, which ensures there | 814 // of |database_| above and of |closing_database_| below, which ensures there |
| 815 // won't be a window during which the IO thread falsely believes the database | 815 // won't be a window during which the IO thread falsely believes the database |
| 816 // is available. | 816 // is available. |
| 817 AutoLock lock(database_lock_); | 817 base::AutoLock lock(database_lock_); |
| 818 closing_database_ = false; | 818 closing_database_ = false; |
| 819 } | 819 } |
| 820 | 820 |
| 821 void SafeBrowsingService::OnResetDatabase() { | 821 void SafeBrowsingService::OnResetDatabase() { |
| 822 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); | 822 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
| 823 GetDatabase()->ResetDatabase(); | 823 GetDatabase()->ResetDatabase(); |
| 824 } | 824 } |
| 825 | 825 |
| 826 void SafeBrowsingService::CacheHashResults( | 826 void SafeBrowsingService::CacheHashResults( |
| 827 const std::vector<SBPrefix>& prefixes, | 827 const std::vector<SBPrefix>& prefixes, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 // checkbox on the blocking page. | 965 // checkbox on the blocking page. |
| 966 void SafeBrowsingService::ReportMalwareDetails( | 966 void SafeBrowsingService::ReportMalwareDetails( |
| 967 scoped_refptr<MalwareDetails> details) { | 967 scoped_refptr<MalwareDetails> details) { |
| 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 969 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); | 969 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); |
| 970 if (!serialized->empty()) { | 970 if (!serialized->empty()) { |
| 971 DVLOG(1) << "Sending serialized malware details."; | 971 DVLOG(1) << "Sending serialized malware details."; |
| 972 protocol_manager_->ReportMalwareDetails(*serialized); | 972 protocol_manager_->ReportMalwareDetails(*serialized); |
| 973 } | 973 } |
| 974 } | 974 } |
| OLD | NEW |