| 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   DCHECK(!safe_browsing_task_runner_); | 
|   654   safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |   659   // Use the blocking pool instead of a dedicated thread for safe browsing work, | 
|   655   if (!safe_browsing_thread_->Start()) |   660   // if specified by an experiment. | 
|   656     return; |   661   const bool use_blocking_pool = | 
 |   662       variations::GetVariationParamValue("LightSpeed", "SBThreadingMode") == | 
 |   663       "BlockingPool"; | 
 |   664   if (use_blocking_pool) { | 
 |   665     base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 
 |   666     safe_browsing_task_runner_ = | 
 |   667         pool->GetSequencedTaskRunnerWithShutdownBehavior( | 
 |   668             pool->GetSequenceToken(), | 
 |   669             base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 
 |   670   } else { | 
 |   671     DCHECK(!safe_browsing_thread_.get()); | 
 |   672     safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 
 |   673     if (!safe_browsing_thread_->Start()) | 
 |   674       return; | 
 |   675     safe_browsing_task_runner_ = safe_browsing_thread_->task_runner(); | 
 |   676   } | 
|   657   enabled_ = true; |   677   enabled_ = true; | 
|   658  |   678  | 
|   659   MakeDatabaseAvailable(); |   679   MakeDatabaseAvailable(); | 
|   660 } |   680 } | 
|   661  |   681  | 
|   662 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |   682 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 
|   663   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   683   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   664  |   684  | 
|   665   DoStopOnIOThread(); |   685   DoStopOnIOThread(); | 
|   666   if (shutdown) { |   686   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 |   742   //    could start using it on the IO thread and then have the second request | 
|   723   //    handler delete it out from under us. |   743   //    handler delete it out from under us. | 
|   724   //  * If |database_| is NULL, then either no creation request is in flight, in |   744   //  * 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 |   745   //    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 |   746   //    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 |   747   //    handled, and could be used on the IO thread in that time period, leading | 
|   728   //    to the same problem as above. |   748   //    to the same problem as above. | 
|   729   // Checking DatabaseAvailable() avoids both of these. |   749   // Checking DatabaseAvailable() avoids both of these. | 
|   730   if (DatabaseAvailable()) { |   750   if (DatabaseAvailable()) { | 
|   731     closing_database_ = true; |   751     closing_database_ = true; | 
|   732     safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |   752     safe_browsing_task_runner_->PostTask( | 
 |   753         FROM_HERE, | 
|   733         base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); |   754         base::Bind(&SafeBrowsingDatabaseManager::OnCloseDatabase, this)); | 
|   734   } |   755   } | 
|   735  |   756  | 
|   736   // Flush the database thread. Any in-progress database check results will be |   757   // Flush the database thread. Any in-progress database check results will be | 
|   737   // ignored and cleaned up below. |   758   // ignored and cleaned up below. | 
|   738   // |   759   // | 
|   739   // Note that to avoid leaking the database, we rely on the fact that no new |   760   // 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. |   761   // 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_|. |   762   // See comments on the declaration of |safe_browsing_thread_|. | 
|   742   { |   763   if (safe_browsing_thread_) { | 
|   743     // A ScopedAllowIO object is required to join the thread when calling Stop. |   764     // 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 |   765     // See http://crbug.com/72696. Note that we call Stop() first to clear out | 
|   745     // any remaining tasks before clearing safe_browsing_thread_. |   766     // any remaining tasks before clearing safe_browsing_thread_. | 
|   746     base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |   767     base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; | 
|   747     safe_browsing_thread_->Stop(); |   768     safe_browsing_thread_->Stop(); | 
|   748     safe_browsing_thread_.reset(); |   769     safe_browsing_thread_.reset(); | 
|   749   } |   770   } | 
|   750  |   771  | 
|   751   // Delete pending checks, calling back any clients with 'SB_THREAT_TYPE_SAFE'. |   772   // 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 |   773   // 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 { |   787 bool SafeBrowsingDatabaseManager::DatabaseAvailable() const { | 
|   767   base::AutoLock lock(database_lock_); |   788   base::AutoLock lock(database_lock_); | 
|   768   return !closing_database_ && (database_ != NULL); |   789   return !closing_database_ && (database_ != NULL); | 
|   769 } |   790 } | 
|   770  |   791  | 
|   771 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { |   792 bool SafeBrowsingDatabaseManager::MakeDatabaseAvailable() { | 
|   772   DCHECK_CURRENTLY_ON(BrowserThread::IO); |   793   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|   773   DCHECK(enabled_); |   794   DCHECK(enabled_); | 
|   774   if (DatabaseAvailable()) |   795   if (DatabaseAvailable()) | 
|   775     return true; |   796     return true; | 
|   776   safe_browsing_thread_->message_loop()->PostTask( |   797   safe_browsing_task_runner_->PostTask( | 
|   777       FROM_HERE, |   798       FROM_HERE, | 
|   778       base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), |   799       base::Bind(base::IgnoreResult(&SafeBrowsingDatabaseManager::GetDatabase), | 
|   779                  this)); |   800                  this)); | 
|   780   return false; |   801   return false; | 
|   781 } |   802 } | 
|   782  |   803  | 
|   783 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { |   804 SafeBrowsingDatabase* SafeBrowsingDatabaseManager::GetDatabase() { | 
|   784   DCHECK_EQ(base::MessageLoop::current(), |   805   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   785             safe_browsing_thread_->message_loop()); |   806  | 
|   786   if (database_) |   807   if (database_) | 
|   787     return database_; |   808     return database_; | 
|   788   startup_metric_utils::ScopedSlowStartupUMA |   809   startup_metric_utils::ScopedSlowStartupUMA | 
|   789       scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); |   810       scoped_timer("Startup.SlowStartupSafeBrowsingGetDatabase"); | 
|   790   const base::TimeTicks before = base::TimeTicks::Now(); |   811   const base::TimeTicks before = base::TimeTicks::Now(); | 
|   791  |   812  | 
|   792   SafeBrowsingDatabase* database = |   813   SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create( | 
|   793       SafeBrowsingDatabase::Create(enable_download_protection_, |   814       safe_browsing_task_runner_, enable_download_protection_, | 
|   794                                    enable_csd_whitelist_, |   815       enable_csd_whitelist_, enable_download_whitelist_, | 
|   795                                    enable_download_whitelist_, |   816       enable_extension_blacklist_, enable_side_effect_free_whitelist_, | 
|   796                                    enable_extension_blacklist_, |   817       enable_ip_blacklist_, enable_unwanted_software_blacklist_); | 
|   797                                    enable_side_effect_free_whitelist_, |  | 
|   798                                    enable_ip_blacklist_, |  | 
|   799                                    enable_unwanted_software_blacklist_); |  | 
|   800  |   818  | 
|   801   database->Init(SafeBrowsingService::GetBaseFilename()); |   819   database->Init(SafeBrowsingService::GetBaseFilename()); | 
|   802   { |   820   { | 
|   803     // Acquiring the lock here guarantees correct ordering between the writes to |   821     // Acquiring the lock here guarantees correct ordering between the writes to | 
|   804     // the new database object above, and the setting of |database_| below. |   822     // the new database object above, and the setting of |database_| below. | 
|   805     base::AutoLock lock(database_lock_); |   823     base::AutoLock lock(database_lock_); | 
|   806     database_ = database; |   824     database_ = database; | 
|   807   } |   825   } | 
|   808  |   826  | 
|   809   BrowserThread::PostTask( |   827   BrowserThread::PostTask( | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   861         is_download); |   879         is_download); | 
|   862   } else { |   880   } else { | 
|   863     // We may have cached results for previous GetHash queries.  Since |   881     // We may have cached results for previous GetHash queries.  Since | 
|   864     // this data comes from cache, don't histogram hits. |   882     // this data comes from cache, don't histogram hits. | 
|   865     HandleOneCheck(check, check->cache_hits); |   883     HandleOneCheck(check, check->cache_hits); | 
|   866   } |   884   } | 
|   867 } |   885 } | 
|   868  |   886  | 
|   869 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( |   887 void SafeBrowsingDatabaseManager::GetAllChunksFromDatabase( | 
|   870     GetChunksCallback callback) { |   888     GetChunksCallback callback) { | 
|   871   DCHECK_EQ(base::MessageLoop::current(), |   889   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   872             safe_browsing_thread_->message_loop()); |  | 
|   873  |   890  | 
|   874   bool database_error = true; |   891   bool database_error = true; | 
|   875   std::vector<SBListChunkRanges> lists; |   892   std::vector<SBListChunkRanges> lists; | 
|   876   DCHECK(!database_update_in_progress_); |   893   DCHECK(!database_update_in_progress_); | 
|   877   database_update_in_progress_ = true; |   894   database_update_in_progress_ = true; | 
|   878   GetDatabase();  // This guarantees that |database_| is non-NULL. |   895   GetDatabase();  // This guarantees that |database_| is non-NULL. | 
|   879   if (database_->UpdateStarted(&lists)) { |   896   if (database_->UpdateStarted(&lists)) { | 
|   880     database_error = false; |   897     database_error = false; | 
|   881   } else { |   898   } else { | 
|   882     database_->UpdateFinished(false); |   899     database_->UpdateFinished(false); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   932       check.client->OnSafeBrowsingResult(sb_check); |   949       check.client->OnSafeBrowsingResult(sb_check); | 
|   933     } |   950     } | 
|   934     queued_checks_.pop_front(); |   951     queued_checks_.pop_front(); | 
|   935   } |   952   } | 
|   936 } |   953 } | 
|   937  |   954  | 
|   938 void SafeBrowsingDatabaseManager::AddDatabaseChunks( |   955 void SafeBrowsingDatabaseManager::AddDatabaseChunks( | 
|   939     const std::string& list_name, |   956     const std::string& list_name, | 
|   940     scoped_ptr<ScopedVector<SBChunkData> > chunks, |   957     scoped_ptr<ScopedVector<SBChunkData> > chunks, | 
|   941     AddChunksCallback callback) { |   958     AddChunksCallback callback) { | 
|   942   DCHECK_EQ(base::MessageLoop::current(), |   959   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   943             safe_browsing_thread_->message_loop()); |  | 
|   944   if (chunks) |   960   if (chunks) | 
|   945     GetDatabase()->InsertChunks(list_name, chunks->get()); |   961     GetDatabase()->InsertChunks(list_name, chunks->get()); | 
|   946   BrowserThread::PostTask( |   962   BrowserThread::PostTask( | 
|   947       BrowserThread::IO, FROM_HERE, |   963       BrowserThread::IO, FROM_HERE, | 
|   948       base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, |   964       base::Bind(&SafeBrowsingDatabaseManager::OnAddChunksComplete, this, | 
|   949                  callback)); |   965                  callback)); | 
|   950 } |   966 } | 
|   951  |   967  | 
|   952 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( |   968 void SafeBrowsingDatabaseManager::DeleteDatabaseChunks( | 
|   953     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |   969     scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 
|   954   DCHECK_EQ(base::MessageLoop::current(), |   970   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   955             safe_browsing_thread_->message_loop()); |  | 
|   956   if (chunk_deletes) |   971   if (chunk_deletes) | 
|   957     GetDatabase()->DeleteChunks(*chunk_deletes); |   972     GetDatabase()->DeleteChunks(*chunk_deletes); | 
|   958 } |   973 } | 
|   959  |   974  | 
|   960 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( |   975 void SafeBrowsingDatabaseManager::DatabaseUpdateFinished( | 
|   961     bool update_succeeded) { |   976     bool update_succeeded) { | 
|   962   DCHECK_EQ(base::MessageLoop::current(), |   977   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   963             safe_browsing_thread_->message_loop()); |  | 
|   964   GetDatabase()->UpdateFinished(update_succeeded); |   978   GetDatabase()->UpdateFinished(update_succeeded); | 
|   965   DCHECK(database_update_in_progress_); |   979   DCHECK(database_update_in_progress_); | 
|   966   database_update_in_progress_ = false; |   980   database_update_in_progress_ = false; | 
|   967   BrowserThread::PostTask( |   981   BrowserThread::PostTask( | 
|   968       BrowserThread::UI, FROM_HERE, |   982       BrowserThread::UI, FROM_HERE, | 
|   969       base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, |   983       base::Bind(&SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished, | 
|   970                  this, update_succeeded)); |   984                  this, update_succeeded)); | 
|   971 } |   985 } | 
|   972  |   986  | 
|   973 void SafeBrowsingDatabaseManager::OnCloseDatabase() { |   987 void SafeBrowsingDatabaseManager::OnCloseDatabase() { | 
|   974   DCHECK_EQ(base::MessageLoop::current(), |   988   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   975             safe_browsing_thread_->message_loop()); |  | 
|   976   DCHECK(closing_database_); |   989   DCHECK(closing_database_); | 
|   977  |   990  | 
|   978   // Because |closing_database_| is true, nothing on the IO thread will be |   991   // 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. |   992   // accessing the database, so it's safe to delete and then NULL the pointer. | 
|   980   delete database_; |   993   delete database_; | 
|   981   database_ = NULL; |   994   database_ = NULL; | 
|   982  |   995  | 
|   983   // Acquiring the lock here guarantees correct ordering between the resetting |   996   // Acquiring the lock here guarantees correct ordering between the resetting | 
|   984   // of |database_| above and of |closing_database_| below, which ensures there |   997   // 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 |   998   // won't be a window during which the IO thread falsely believes the database | 
|   986   // is available. |   999   // is available. | 
|   987   base::AutoLock lock(database_lock_); |  1000   base::AutoLock lock(database_lock_); | 
|   988   closing_database_ = false; |  1001   closing_database_ = false; | 
|   989 } |  1002 } | 
|   990  |  1003  | 
|   991 void SafeBrowsingDatabaseManager::OnResetDatabase() { |  1004 void SafeBrowsingDatabaseManager::OnResetDatabase() { | 
|   992   DCHECK_EQ(base::MessageLoop::current(), |  1005   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|   993             safe_browsing_thread_->message_loop()); |  1006  | 
|   994   GetDatabase()->ResetDatabase(); |  1007   GetDatabase()->ResetDatabase(); | 
|   995 } |  1008 } | 
|   996  |  1009  | 
|   997 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( |  1010 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( | 
|   998     SafeBrowsingCheck* check, |  1011     SafeBrowsingCheck* check, | 
|   999     const std::vector<SBFullHashResult>& full_hashes) { |  1012     const std::vector<SBFullHashResult>& full_hashes) { | 
|  1000   DCHECK_CURRENTLY_ON(BrowserThread::IO); |  1013   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|  1001   safe_browsing_util::ListType check_type = check->check_type; |  1014   safe_browsing_util::ListType check_type = check->check_type; | 
|  1002   SBPrefix prefix = check->prefix_hits[0]; |  1015   SBPrefix prefix = check->prefix_hits[0]; | 
|  1003   GetHashRequests::iterator it = gethash_requests_.find(prefix); |  1016   GetHashRequests::iterator it = gethash_requests_.find(prefix); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1065       is_threat = true; |  1078       is_threat = true; | 
|  1066     } |  1079     } | 
|  1067   } |  1080   } | 
|  1068  |  1081  | 
|  1069   SafeBrowsingCheckDone(check); |  1082   SafeBrowsingCheckDone(check); | 
|  1070   return is_threat; |  1083   return is_threat; | 
|  1071 } |  1084 } | 
|  1072  |  1085  | 
|  1073 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( |  1086 void SafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread( | 
|  1074     SafeBrowsingCheck* check) { |  1087     SafeBrowsingCheck* check) { | 
|  1075   DCHECK_EQ(base::MessageLoop::current(), |  1088   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|  1076             safe_browsing_thread_->message_loop()); |  | 
|  1077   DCHECK(enable_download_protection_); |  1089   DCHECK(enable_download_protection_); | 
|  1078  |  1090  | 
|  1079   std::vector<SBPrefix> prefix_hits; |  1091   std::vector<SBPrefix> prefix_hits; | 
|  1080  |  1092  | 
|  1081   if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { |  1093   if (!database_->ContainsDownloadUrl(check->urls, &prefix_hits)) { | 
|  1082     // Good, we don't have hash for this url prefix. |  1094     // Good, we don't have hash for this url prefix. | 
|  1083     BrowserThread::PostTask( |  1095     BrowserThread::PostTask( | 
|  1084         BrowserThread::IO, FROM_HERE, |  1096         BrowserThread::IO, FROM_HERE, | 
|  1085         base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, |  1097         base::Bind(&SafeBrowsingDatabaseManager::CheckDownloadUrlDone, this, | 
|  1086                    check)); |  1098                    check)); | 
|  1087     return; |  1099     return; | 
|  1088   } |  1100   } | 
|  1089  |  1101  | 
|  1090   check->need_get_hash = true; |  1102   check->need_get_hash = true; | 
|  1091   check->prefix_hits.clear(); |  1103   check->prefix_hits.clear(); | 
|  1092   check->prefix_hits = prefix_hits; |  1104   check->prefix_hits = prefix_hits; | 
|  1093   BrowserThread::PostTask( |  1105   BrowserThread::PostTask( | 
|  1094       BrowserThread::IO, FROM_HERE, |  1106       BrowserThread::IO, FROM_HERE, | 
|  1095       base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); |  1107       base::Bind(&SafeBrowsingDatabaseManager::OnCheckDone, this, check)); | 
|  1096 } |  1108 } | 
|  1097  |  1109  | 
|  1098 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( |  1110 void SafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread( | 
|  1099     SafeBrowsingCheck* check) { |  1111     SafeBrowsingCheck* check) { | 
|  1100   DCHECK_EQ(base::MessageLoop::current(), |  1112   DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); | 
|  1101             safe_browsing_thread_->message_loop()); |  | 
|  1102  |  1113  | 
|  1103   std::vector<SBPrefix> prefixes; |  1114   std::vector<SBPrefix> prefixes; | 
|  1104   for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); |  1115   for (std::vector<SBFullHash>::iterator it = check->full_hashes.begin(); | 
|  1105        it != check->full_hashes.end(); ++it) { |  1116        it != check->full_hashes.end(); ++it) { | 
|  1106     prefixes.push_back((*it).prefix); |  1117     prefixes.push_back((*it).prefix); | 
|  1107   } |  1118   } | 
|  1108   database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); |  1119   database_->ContainsExtensionPrefixes(prefixes, &check->prefix_hits); | 
|  1109  |  1120  | 
|  1110   if (check->prefix_hits.empty()) { |  1121   if (check->prefix_hits.empty()) { | 
|  1111     // No matches for any extensions. |  1122     // No matches for any extensions. | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1162 } |  1173 } | 
|  1163  |  1174  | 
|  1164 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( |  1175 void SafeBrowsingDatabaseManager::StartSafeBrowsingCheck( | 
|  1165     SafeBrowsingCheck* check, |  1176     SafeBrowsingCheck* check, | 
|  1166     const base::Closure& task) { |  1177     const base::Closure& task) { | 
|  1167   DCHECK_CURRENTLY_ON(BrowserThread::IO); |  1178   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
|  1168   check->timeout_factory_.reset( |  1179   check->timeout_factory_.reset( | 
|  1169       new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |  1180       new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 
|  1170   checks_.insert(check); |  1181   checks_.insert(check); | 
|  1171  |  1182  | 
|  1172   safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |  1183   safe_browsing_task_runner_->PostTask(FROM_HERE, task); | 
|  1173  |  1184  | 
|  1174   base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |  1185   base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 
|  1175       base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |  1186       base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 
|  1176                  check->timeout_factory_->GetWeakPtr(), check), |  1187                  check->timeout_factory_->GetWeakPtr(), check), | 
|  1177       check_timeout_); |  1188       check_timeout_); | 
|  1178 } |  1189 } | 
| OLD | NEW |