| 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/database_manager.h" |     5 #include "chrome/browser/safe_browsing/database_manager.h" | 
|     6  |     6  | 
|     7 #include <algorithm> |     7 #include <algorithm> | 
|     8  |     8  | 
|     9 #include "base/bind.h" |     9 #include "base/bind.h" | 
|    10 #include "base/bind_helpers.h" |    10 #include "base/bind_helpers.h" | 
|    11 #include "base/callback.h" |    11 #include "base/callback.h" | 
|    12 #include "base/command_line.h" |    12 #include "base/command_line.h" | 
|    13 #include "base/debug/leak_tracker.h" |    13 #include "base/debug/leak_tracker.h" | 
 |    14 #include "base/metrics/histogram_macros.h" | 
|    14 #include "base/stl_util.h" |    15 #include "base/stl_util.h" | 
|    15 #include "base/strings/string_util.h" |    16 #include "base/strings/string_util.h" | 
|    16 #include "base/threading/thread.h" |    17 #include "base/threading/thread.h" | 
|    17 #include "base/threading/thread_restrictions.h" |    18 #include "base/threading/thread_restrictions.h" | 
|    18 #include "chrome/browser/browser_process.h" |    19 #include "chrome/browser/browser_process.h" | 
|    19 #include "chrome/browser/chrome_notification_types.h" |    20 #include "chrome/browser/chrome_notification_types.h" | 
|    20 #include "chrome/browser/prerender/prerender_field_trial.h" |    21 #include "chrome/browser/prerender/prerender_field_trial.h" | 
|    21 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |    22 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 
|    22 #include "chrome/browser/safe_browsing/download_protection_service.h" |    23 #include "chrome/browser/safe_browsing/download_protection_service.h" | 
|    23 #include "chrome/browser/safe_browsing/malware_details.h" |    24 #include "chrome/browser/safe_browsing/malware_details.h" | 
|    24 #include "chrome/browser/safe_browsing/protocol_manager.h" |    25 #include "chrome/browser/safe_browsing/protocol_manager.h" | 
|    25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |    26 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 
|    26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |    27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 
|    27 #include "chrome/browser/safe_browsing/ui_manager.h" |    28 #include "chrome/browser/safe_browsing/ui_manager.h" | 
|    28 #include "chrome/common/chrome_constants.h" |    29 #include "chrome/common/chrome_constants.h" | 
|    29 #include "chrome/common/chrome_paths.h" |    30 #include "chrome/common/chrome_paths.h" | 
|    30 #include "chrome/common/chrome_switches.h" |    31 #include "chrome/common/chrome_switches.h" | 
|    31 #include "components/metrics/metrics_service.h" |  | 
|    32 #include "components/startup_metric_utils/startup_metric_utils.h" |    32 #include "components/startup_metric_utils/startup_metric_utils.h" | 
 |    33 #include "components/variations/variations_associated_data.h" | 
|    33 #include "content/public/browser/browser_thread.h" |    34 #include "content/public/browser/browser_thread.h" | 
|    34 #include "content/public/browser/notification_service.h" |    35 #include "content/public/browser/notification_service.h" | 
|    35 #include "url/url_constants.h" |    36 #include "url/url_constants.h" | 
|    36  |    37  | 
|    37 using content::BrowserThread; |    38 using content::BrowserThread; | 
|    38  |    39  | 
|    39 namespace { |    40 namespace { | 
|    40  |    41  | 
|    41 // Timeout for match checks, e.g. download URLs, hashes. |    42 // Timeout for match checks, e.g. download URLs, hashes. | 
|    42 const int kCheckTimeoutMs = 10000; |    43 const int kCheckTimeoutMs = 10000; | 
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   588  |   589  | 
|   589   // Cache the GetHash results. |   590   // Cache the GetHash results. | 
|   590   if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) |   591   if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) | 
|   591     database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); |   592     database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); | 
|   592 } |   593 } | 
|   593  |   594  | 
|   594 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { |   595 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { | 
|   595   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   596   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   596   DCHECK(enabled_); |   597   DCHECK(enabled_); | 
|   597   DCHECK(!callback.is_null()); |   598   DCHECK(!callback.is_null()); | 
|   598   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |   599   safe_browsing_task_runner_->PostTask( | 
|   599       &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); |   600       FROM_HERE, | 
 |   601       base::Bind(&SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, | 
 |   602                  callback)); | 
|   600 } |   603 } | 
|   601  |   604  | 
|   602 void SafeBrowsingDatabaseManager::AddChunks( |   605 void SafeBrowsingDatabaseManager::AddChunks( | 
|   603     const std::string& list, |   606     const std::string& list, | 
|   604     scoped_ptr<ScopedVector<SBChunkData> > chunks, |   607     scoped_ptr<ScopedVector<SBChunkData> > chunks, | 
|   605     AddChunksCallback callback) { |   608     AddChunksCallback callback) { | 
|   606   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   609   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   607   DCHECK(enabled_); |   610   DCHECK(enabled_); | 
|   608   DCHECK(!callback.is_null()); |   611   DCHECK(!callback.is_null()); | 
|   609   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |   612   safe_browsing_task_runner_->PostTask( | 
|   610       &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, |   613       FROM_HERE, base::Bind(&SafeBrowsingDatabaseManager::AddDatabaseChunks, | 
|   611       base::Passed(&chunks), callback)); |   614                             this, list, base::Passed(&chunks), callback)); | 
|   612 } |   615 } | 
|   613  |   616  | 
|   614 void SafeBrowsingDatabaseManager::DeleteChunks( |   617 void SafeBrowsingDatabaseManager::DeleteChunks( | 
|   615     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |   618     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 
|   616   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   619   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   617   DCHECK(enabled_); |   620   DCHECK(enabled_); | 
|   618   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |   621   safe_browsing_task_runner_->PostTask( | 
|   619       &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, |   622       FROM_HERE, base::Bind(&SafeBrowsingDatabaseManager::DeleteDatabaseChunks, | 
|   620       base::Passed(&chunk_deletes))); |   623                             this, base::Passed(&chunk_deletes))); | 
|   621 } |   624 } | 
|   622  |   625  | 
|   623 void SafeBrowsingDatabaseManager::UpdateStarted() { |   626 void SafeBrowsingDatabaseManager::UpdateStarted() { | 
|   624   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   627   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   625   DCHECK(enabled_); |   628   DCHECK(enabled_); | 
|   626   DCHECK(!update_in_progress_); |   629   DCHECK(!update_in_progress_); | 
|   627   update_in_progress_ = true; |   630   update_in_progress_ = true; | 
|   628 } |   631 } | 
|   629  |   632  | 
|   630 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { |   633 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { | 
|   631   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   634   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   632   DCHECK(enabled_); |   635   DCHECK(enabled_); | 
|   633   if (update_in_progress_) { |   636   if (update_in_progress_) { | 
|   634     update_in_progress_ = false; |   637     update_in_progress_ = false; | 
|   635     safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |   638     safe_browsing_task_runner_->PostTask( | 
|   636       base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, |   639         FROM_HERE, | 
|   637                  this, update_succeeded)); |   640         base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, this, | 
 |   641                    update_succeeded)); | 
|   638   } |   642   } | 
|   639 } |   643 } | 
|   640  |   644  | 
|   641 void SafeBrowsingDatabaseManager::ResetDatabase() { |   645 void SafeBrowsingDatabaseManager::ResetDatabase() { | 
|   642   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   646   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   643   DCHECK(enabled_); |   647   DCHECK(enabled_); | 
|   644   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |   648   safe_browsing_task_runner_->PostTask( | 
|   645       &SafeBrowsingDatabaseManager::OnResetDatabase, this)); |   649       FROM_HERE, | 
 |   650       base::Bind(&SafeBrowsingDatabaseManager::OnResetDatabase, this)); | 
|   646 } |   651 } | 
|   647  |   652  | 
|   648 void SafeBrowsingDatabaseManager::StartOnIOThread() { |   653 void SafeBrowsingDatabaseManager::StartOnIOThread() { | 
|   649   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   654   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   650   if (enabled_) |   655   if (enabled_) | 
|   651     return; |   656     return; | 
|   652  |   657  | 
|   653   DCHECK(!safe_browsing_thread_.get()); |   658   // Don't create the thread under "BlockingPool" experimental group - instead | 
|   654   safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |   659   // the blocking pool will be used for safe browsing work. | 
|   655   if (!safe_browsing_thread_->Start()) |   660   const std::string sb_threading_mode = | 
|   656     return; |   661       variations::GetVariationParamValue("LightSpeed", "SBThreadingMode"); | 
 |   662   if (sb_threading_mode == "BlockingPool") { | 
 |   663     base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 
 |   664     safe_browsing_task_runner_ = | 
 |   665         pool->GetSequencedTaskRunner(pool->GetSequenceToken()); | 
 |   666   } else { | 
 |   667     DCHECK(!safe_browsing_thread_.get()); | 
 |   668     safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 
 |   669     if (!safe_browsing_thread_->Start()) | 
 |   670       return; | 
 |   671     safe_browsing_task_runner_ = safe_browsing_thread_->task_runner(); | 
 |   672   } | 
|   657   enabled_ = true; |   673   enabled_ = true; | 
|   658  |   674  | 
|   659   MakeDatabaseAvailable(); |   675   MakeDatabaseAvailable(); | 
|   660 } |   676 } | 
|   661  |   677  | 
|   662 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |   678 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 
|   663   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   679   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   664  |   680  | 
|   665   DoStopOnIOThread(); |   681   DoStopOnIOThread(); | 
|   666   if (shutdown) { |   682   if (shutdown) { | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   722   //    could start using it on the IO thread and then have the second request |   738   //    could start using it on the IO thread and then have the second request | 
|   723   //    handler delete it out from under us. |   739   //    handler delete it out from under us. | 
|   724   //  * If |database_| is NULL, then either no creation request is in flight, in |   740   //  * If |database_| is NULL, then either no creation request is in flight, in | 
|   725   //    which case we don't need to do anything, or one is in flight, in which |   741   //    which case we don't need to do anything, or one is in flight, in which | 
|   726   //    case the database will be recreated before our deletion request is |   742   //    case the database will be recreated before our deletion request is | 
|   727   //    handled, and could be used on the IO thread in that time period, leading |   743   //    handled, and could be used on the IO thread in that time period, leading | 
|   728   //    to the same problem as above. |   744   //    to the same problem as above. | 
|   729   // Checking DatabaseAvailable() avoids both of these. |   745   // Checking DatabaseAvailable() avoids both of these. | 
|   730   if (DatabaseAvailable()) { |   746   if (DatabaseAvailable()) { | 
|   731     closing_database_ = true; |   747     closing_database_ = true; | 
|   732     safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |   748     safe_browsing_task_runner_->PostTask( | 
 |   749         FROM_HERE, | 
|   733         base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); |   750         base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); | 
|   734   } |   751   } | 
|   735  |   752  | 
|   736   // Flush the database thread. Any in-progress database check results will be |   753   // Flush the database thread. Any in-progress database check results will be | 
|   737   // ignored and cleaned up below. |   754   // ignored and cleaned up below. | 
|   738   // |   755   // | 
|   739   // Note that to avoid leaking the database, we rely on the fact that no new |   756   // Note that to avoid leaking the database, we rely on the fact that no new | 
|   740   // tasks will be added to the db thread between the call above and this one. |   757   // tasks will be added to the db thread between the call above and this one. | 
|   741   // See comments on the declaration of |safe_browsing_thread_|. |   758   // See comments on the declaration of |safe_browsing_thread_|. | 
|   742   { |   759   if (safe_browsing_thread_) { | 
|   743     // A ScopedAllowIO object is required to join the thread when calling Stop. |   760     // A ScopedAllowIO object is required to join the thread when calling Stop. | 
|   744     // See http://crbug.com/72696. Note that we call Stop() first to clear out |   761     // See http://crbug.com/72696. Note that we call Stop() first to clear out | 
|   745     // any remaining tasks before clearing safe_browsing_thread_. |   762     // any remaining tasks before clearing safe_browsing_thread_. | 
|   746     base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |   763     base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 
|   747     safe_browsing_thread_->Stop(); |   764     safe_browsing_thread_->Stop(); | 
|   748     safe_browsing_thread_.reset(); |   765     safe_browsing_thread_.reset(); | 
|   749   } |   766   } | 
|   750  |   767  | 
|   751   // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. |   768   // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. | 
|   752   // We have to do this after the db thread returns because methods on it can |   769   // We have to do this after the db thread returns because methods on it can | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|   766 bool SafeBrowsingDatabaseManager::DatabaseAvailable() const { |   783 bool SafeBrowsingDatabaseManager::DatabaseAvailable() const { | 
|   767   base::AutoLock lock(database_lock_); |   784   base::AutoLock lock(database_lock_); | 
|   768   return !closing_database_ && (database_ != NULL); |   785   return !closing_database_ && (database_ != NULL); | 
|   769 } |   786 } | 
|   770  |   787  | 
|   771 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { |   788 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { | 
|   772   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   789   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   773   DCHECK(enabled_); |   790   DCHECK(enabled_); | 
|   774   if (DatabaseAvailable()) |   791   if (DatabaseAvailable()) | 
|   775     return true; |   792     return true; | 
|   776   safe_browsing_thread_->message_loop()->PostTask( |   793   safe_browsing_task_runner_->PostTask( | 
|   777       FROM_HERE, |   794       FROM_HERE, | 
|   778       base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), |   795       base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), | 
|   779                  this)); |   796                  this)); | 
|   780   return false; |   797   return false; | 
|   781 } |   798 } | 
|   782  |   799  | 
|   783 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { |   800 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { | 
|   784   DCHECK_EQ(base::MessageLoop::current(), |   801   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   785             safe_browsing_thread_->message_loop()); |   802  | 
|   786   if (database_) |   803   if (database_) | 
|   787     return database_; |   804     return database_; | 
|   788   startup_metric_utils::ScopedSlowStartupUMA |   805   startup_metric_utils::ScopedSlowStartupUMA | 
|   789       scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); |   806       scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); | 
|   790   const base::TimeTicks before = base::TimeTicks::Now(); |   807   const base::TimeTicks before = base::TimeTicks::Now(); | 
|   791  |   808  | 
|   792   SafeBrowsingDatabase* database = |   809   SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( | 
|   793       SafeBrowsingDatabase::Create(enable_download_protection_, |   810       safe_browsing_task_runner_, enable_download_protection_, | 
|   794                                    enable_csd_whitelist_, |   811       enable_csd_whitelist_, enable_download_whitelist_, | 
|   795                                    enable_download_whitelist_, |   812       enable_extension_blacklist_, enable_side_effect_free_whitelist_, | 
|   796                                    enable_extension_blacklist_, |   813       enable_ip_blacklist_, enable_unwanted_software_blacklist_); | 
|   797                                    enable_side_effect_free_whitelist_, |  | 
|   798                                    enable_ip_blacklist_, |  | 
|   799                                    enable_unwanted_software_blacklist_); |  | 
|   800  |   814  | 
|   801   database->Init(SafeBrowsingService::GetBaseFilename()); |   815   database->Init(SafeBrowsingService::GetBaseFilename()); | 
|   802   { |   816   { | 
|   803     // Acquiring the lock here guarantees correct ordering between the writes to |   817     // Acquiring the lock here guarantees correct ordering between the writes to | 
|   804     // the new database object above, and the setting of |database_| below. |   818     // the new database object above, and the setting of |database_| below. | 
|   805     base::AutoLock lock(database_lock_); |   819     base::AutoLock lock(database_lock_); | 
|   806     database_ = database; |   820     database_ = database; | 
|   807   } |   821   } | 
|   808  |   822  | 
|   809   BrowserThread::PostTask( |   823   BrowserThread::PostTask( | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   861         is_download); |   875         is_download); | 
|   862   } else { |   876   } else { | 
|   863     // We may have cached results for previous GetHash queries.  Since |   877     // We may have cached results for previous GetHash queries.  Since | 
|   864     // this data comes from cache, don't histogram hits. |   878     // this data comes from cache, don't histogram hits. | 
|   865     HandleOneCheck(check, check->cache_hits); |   879     HandleOneCheck(check, check->cache_hits); | 
|   866   } |   880   } | 
|   867 } |   881 } | 
|   868  |   882  | 
|   869 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |   883 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 
|   870     GetChunksCallback callback) { |   884     GetChunksCallback callback) { | 
|   871   DCHECK_EQ(base::MessageLoop::current(), |   885   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   872             safe_browsing_thread_->message_loop()); |  | 
|   873  |   886  | 
|   874   bool database_error = true; |   887   bool database_error = true; | 
|   875   std::vector<SBListChunkRanges> lists; |   888   std::vector<SBListChunkRanges> lists; | 
|   876   DCHECK(!database_update_in_progress_); |   889   DCHECK(!database_update_in_progress_); | 
|   877   database_update_in_progress_ = true; |   890   database_update_in_progress_ = true; | 
|   878   GetDatabase();  // This guarantees that |database_| is non-NULL. |   891   GetDatabase();  // This guarantees that |database_| is non-NULL. | 
|   879   if (database_->UpdateStarted(&lists)) { |   892   if (database_->UpdateStarted(&lists)) { | 
|   880     database_error = false; |   893     database_error = false; | 
|   881   } else { |   894   } else { | 
|   882     database_->UpdateFinished(false); |   895     database_->UpdateFinished(false); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   932       check.client->OnSafeBrowsingResult(sb_check); |   945       check.client->OnSafeBrowsingResult(sb_check); | 
|   933     } |   946     } | 
|   934     queued_checks_.pop_front(); |   947     queued_checks_.pop_front(); | 
|   935   } |   948   } | 
|   936 } |   949 } | 
|   937  |   950  | 
|   938 void SafeBrowsingDatabaseManager::AddDatabaseChunks( |   951 void SafeBrowsingDatabaseManager::AddDatabaseChunks( | 
|   939     const std::string& list_name, |   952     const std::string& list_name, | 
|   940     scoped_ptr<ScopedVector<SBChunkData> > chunks, |   953     scoped_ptr<ScopedVector<SBChunkData> > chunks, | 
|   941     AddChunksCallback callback) { |   954     AddChunksCallback callback) { | 
|   942   DCHECK_EQ(base::MessageLoop::current(), |   955   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   943             safe_browsing_thread_->message_loop()); |  | 
|   944   if (chunks) |   956   if (chunks) | 
|   945     GetDatabase()->InsertChunks(list_name, chunks->get()); |   957     GetDatabase()->InsertChunks(list_name, chunks->get()); | 
|   946   BrowserThread::PostTask( |   958   BrowserThread::PostTask( | 
|   947       BrowserThread::IO, FROM_HERE, |   959       BrowserThread::IO, FROM_HERE, | 
|   948       base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, |   960       base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, | 
|   949                  callback)); |   961                  callback)); | 
|   950 } |   962 } | 
|   951  |   963  | 
|   952 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( |   964 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( | 
|   953     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |   965     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 
|   954   DCHECK_EQ(base::MessageLoop::current(), |   966   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   955             safe_browsing_thread_->message_loop()); |  | 
|   956   if (chunk_deletes) |   967   if (chunk_deletes) | 
|   957     GetDatabase()->DeleteChunks(*chunk_deletes); |   968     GetDatabase()->DeleteChunks(*chunk_deletes); | 
|   958 } |   969 } | 
|   959  |   970  | 
|   960 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( |   971 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( | 
|   961     bool update_succeeded) { |   972     bool update_succeeded) { | 
|   962   DCHECK_EQ(base::MessageLoop::current(), |   973   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   963             safe_browsing_thread_->message_loop()); |  | 
|   964   GetDatabase()->UpdateFinished(update_succeeded); |   974   GetDatabase()->UpdateFinished(update_succeeded); | 
|   965   DCHECK(database_update_in_progress_); |   975   DCHECK(database_update_in_progress_); | 
|   966   database_update_in_progress_ = false; |   976   database_update_in_progress_ = false; | 
|   967   BrowserThread::PostTask( |   977   BrowserThread::PostTask( | 
|   968       BrowserThread::UI, FROM_HERE, |   978       BrowserThread::UI, FROM_HERE, | 
|   969       base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, |   979       base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, | 
|   970                  this, update_succeeded)); |   980                  this, update_succeeded)); | 
|   971 } |   981 } | 
|   972  |   982  | 
|   973 void SafeBrowsingDatabaseManager::OnCloseDatabase() { |   983 void SafeBrowsingDatabaseManager::OnCloseDatabase() { | 
|   974   DCHECK_EQ(base::MessageLoop::current(), |   984   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   975             safe_browsing_thread_->message_loop()); |  | 
|   976   DCHECK(closing_database_); |   985   DCHECK(closing_database_); | 
|   977  |   986  | 
|   978   // Because |closing_database_| is true, nothing on the IO thread will be |   987   // Because |closing_database_| is true, nothing on the IO thread will be | 
|   979   // accessing the database, so it's safe to delete and then NULL the pointer. |   988   // accessing the database, so it's safe to delete and then NULL the pointer. | 
|   980   delete database_; |   989   delete database_; | 
|   981   database_ = NULL; |   990   database_ = NULL; | 
|   982  |   991  | 
|   983   // Acquiring the lock here guarantees correct ordering between the resetting |   992   // Acquiring the lock here guarantees correct ordering between the resetting | 
|   984   // of |database_| above and of |closing_database_| below, which ensures there |   993   // of |database_| above and of |closing_database_| below, which ensures there | 
|   985   // won't be a window during which the IO thread falsely believes the database |   994   // won't be a window during which the IO thread falsely believes the database | 
|   986   // is available. |   995   // is available. | 
|   987   base::AutoLock lock(database_lock_); |   996   base::AutoLock lock(database_lock_); | 
|   988   closing_database_ = false; |   997   closing_database_ = false; | 
|   989 } |   998 } | 
|   990  |   999  | 
|   991 void SafeBrowsingDatabaseManager::OnResetDatabase() { |  1000 void SafeBrowsingDatabaseManager::OnResetDatabase() { | 
|   992   DCHECK_EQ(base::MessageLoop::current(), |  1001   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   993             safe_browsing_thread_->message_loop()); |  1002  | 
|   994   GetDatabase()->ResetDatabase(); |  1003   GetDatabase()->ResetDatabase(); | 
|   995 } |  1004 } | 
|   996  |  1005  | 
|   997 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( |  1006 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( | 
|   998     SafeBrowsingCheck* check, |  1007     SafeBrowsingCheck* check, | 
|   999     const std::vector<SBFullHashResult>& full_hashes) { |  1008     const std::vector<SBFullHashResult>& full_hashes) { | 
|  1000   DCHECK_CURRENTLY_ON(BrowserThread::IO); |  1009   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|  1001   safe_browsing_util::ListType check_type = check->check_type; |  1010   safe_browsing_util::ListType check_type = check->check_type; | 
|  1002   SBPrefix prefix = check->prefix_hits[0]; |  1011   SBPrefix prefix = check->prefix_hits[0]; | 
|  1003   GetHashRequests::iterator it = gethash_requests_.find(prefix); |  1012   GetHashRequests::iterator it = gethash_requests_.find(prefix); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1065       is_threat = true; |  1074       is_threat = true; | 
|  1066     } |  1075     } | 
|  1067   } |  1076   } | 
|  1068  |  1077  | 
|  1069   SafeBrowsingCheckDone(check); |  1078   SafeBrowsingCheckDone(check); | 
|  1070   return is_threat; |  1079   return is_threat; | 
|  1071 } |  1080 } | 
|  1072  |  1081  | 
|  1073 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( |  1082 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( | 
|  1074     SafeBrowsingCheck* check) { |  1083     SafeBrowsingCheck* check) { | 
|  1075   DCHECK_EQ(base::MessageLoop::current(), |  1084   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|  1076             safe_browsing_thread_->message_loop()); |  | 
|  1077   DCHECK(enable_download_protection_); |  1085   DCHECK(enable_download_protection_); | 
|  1078  |  1086  | 
|  1079   std::vector<SBPrefix> prefix_hits; |  1087   std::vector<SBPrefix> prefix_hits; | 
|  1080  |  1088  | 
|  1081   if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { |  1089   if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { | 
|  1082     // Good, we don't have hash for this url prefix. |  1090     // Good, we don't have hash for this url prefix. | 
|  1083     BrowserThread::PostTask( |  1091     BrowserThread::PostTask( | 
|  1084         BrowserThread::IO, FROM_HERE, |  1092         BrowserThread::IO, FROM_HERE, | 
|  1085         base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, |  1093         base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, | 
|  1086                    check)); |  1094                    check)); | 
|  1087     return; |  1095     return; | 
|  1088   } |  1096   } | 
|  1089  |  1097  | 
|  1090   check->need_get_hash = true; |  1098   check->need_get_hash = true; | 
|  1091   check->prefix_hits.clear(); |  1099   check->prefix_hits.clear(); | 
|  1092   check->prefix_hits = prefix_hits; |  1100   check->prefix_hits = prefix_hits; | 
|  1093   BrowserThread::PostTask( |  1101   BrowserThread::PostTask( | 
|  1094       BrowserThread::IO, FROM_HERE, |  1102       BrowserThread::IO, FROM_HERE, | 
|  1095       base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); |  1103       base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 
|  1096 } |  1104 } | 
|  1097  |  1105  | 
|  1098 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( |  1106 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( | 
|  1099     SafeBrowsingCheck* check) { |  1107     SafeBrowsingCheck* check) { | 
|  1100   DCHECK_EQ(base::MessageLoop::current(), |  1108   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|  1101             safe_browsing_thread_->message_loop()); |  | 
|  1102  |  1109  | 
|  1103   std::vector<SBPrefix> prefixes; |  1110   std::vector<SBPrefix> prefixes; | 
|  1104   for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); |  1111   for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); | 
|  1105        it != check->full_hashes.end(); ++it) { |  1112        it != check->full_hashes.end(); ++it) { | 
|  1106     prefixes.push_back((*it).prefix); |  1113     prefixes.push_back((*it).prefix); | 
|  1107   } |  1114   } | 
|  1108   database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); |  1115   database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); | 
|  1109  |  1116  | 
|  1110   if (check->prefix_hits.empty()) { |  1117   if (check->prefix_hits.empty()) { | 
|  1111     // No matches for any extensions. |  1118     // No matches for any extensions. | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1162 } |  1169 } | 
|  1163  |  1170  | 
|  1164 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( |  1171 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( | 
|  1165     SafeBrowsingCheck* check, |  1172     SafeBrowsingCheck* check, | 
|  1166     const base::Closure& task) { |  1173     const base::Closure& task) { | 
|  1167   DCHECK_CURRENTLY_ON(BrowserThread::IO); |  1174   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|  1168   check->timeout_factory_.reset( |  1175   check->timeout_factory_.reset( | 
|  1169       new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |  1176       new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 
|  1170   checks_.insert(check); |  1177   checks_.insert(check); | 
|  1171  |  1178  | 
|  1172   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |  1179   safe_browsing_task_runner_->PostTask(FROM_HERE, task); | 
|  1173  |  1180  | 
|  1174   base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |  1181   base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 
|  1175       base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |  1182       base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 
|  1176                  check->timeout_factory_->GetWeakPtr(), check), |  1183                  check->timeout_factory_->GetWeakPtr(), check), | 
|  1177       check_timeout_); |  1184       check_timeout_); | 
|  1178 } |  1185 } | 
| OLD | NEW |