diff options
-rw-r--r-- | chrome/browser/download/download_manager.cc | 94 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 8 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.cc | 207 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.h | 30 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 33 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 49 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/renderer_host/save_file_resource_handler.cc | 10 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.cc | 12 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.h | 6 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.cc | 86 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.h | 12 |
13 files changed, 239 insertions, 315 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 3ded94e..eef8b04 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -18,6 +18,7 @@ #include "base/timer.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_file.h" #include "chrome/browser/download/download_util.h" #include "chrome/browser/extensions/crx_installer.h" @@ -347,9 +348,7 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { DownloadManager::DownloadManager() : shutdown_needed_(false), profile_(NULL), - file_manager_(NULL), - ui_loop_(MessageLoop::current()), - file_loop_(NULL) { + file_manager_(NULL) { } DownloadManager::~DownloadManager() { @@ -494,12 +493,6 @@ bool DownloadManager::Init(Profile* profile) { return false; } - file_loop_ = g_browser_process->file_thread()->message_loop(); - if (!file_loop_) { - NOTREACHED(); - return false; - } - // Get our user preference state. PrefService* prefs = profile_->GetPrefs(); DCHECK(prefs); @@ -513,8 +506,9 @@ bool DownloadManager::Init(Profile* profile) { // get rid of |CreateDirectoryPtr|. bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; // Ensure that the download directory specified in the preferences exists. - file_loop_->PostTask(FROM_HERE, NewRunnableFunction( - CreateDirectoryPtr, download_path())); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableFunction(CreateDirectoryPtr, download_path())); // We use this to determine possibly dangerous downloads. download_util::InitializeExeTypes(&exe_types_); @@ -551,7 +545,7 @@ void DownloadManager::QueryHistoryForDownloads() { // point. OnCreateDatabaseEntryComplete() handles that finalization of the the // download creation as a callback from the history thread. void DownloadManager::StartDownload(DownloadCreateInfo* info) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DCHECK(info); // Freeze the user's preference for showing a Save As dialog. We're going to @@ -590,10 +584,10 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { // We need to move over to the download thread because we don't want to stat // the suggested path on the UI thread. - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadManager::CheckIfSuggestedPathExists, - info)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &DownloadManager::CheckIfSuggestedPathExists, info)); } void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { @@ -647,14 +641,15 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) { } // Now we return to the UI thread. - ui_loop_->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &DownloadManager::OnPathExistenceAvailable, info)); } void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DCHECK(info); if (info->save_as) { @@ -713,12 +708,11 @@ void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info, // Called before DownloadFinished in order to avoid a race condition where we // attempt to open a completed download before it has been renamed. - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(file_manager_, - &DownloadFileManager::OnFinalDownloadName, - download->id(), - target_path, - this)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + file_manager_, &DownloadFileManager::OnFinalDownloadName, + download->id(), target_path, this)); // If the download already completed by the time we reached this point, then // notify observers that it did. @@ -836,7 +830,8 @@ void DownloadManager::DownloadFinished(int32 download_id, int64 size) { if (download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { // We first need to rename the downloaded file from its temporary name to // its final name before we can continue. - file_loop_->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod( this, &DownloadManager::ProceedWithFinishedDangerousDownload, download->db_handle(), @@ -896,7 +891,8 @@ void DownloadManager::ProceedWithFinishedDangerousDownload( NOTREACHED(); } - ui_loop_->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &DownloadManager::DangerousDownloadRenamed, download_handle, success, new_path, uniquifier)); } @@ -964,10 +960,10 @@ void DownloadManager::DownloadCancelledInternal(int download_id, // Tell the file manager to cancel the download. file_manager_->RemoveDownload(download_id, this); // On the UI thread - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(file_manager_, - &DownloadFileManager::CancelDownload, - download_id)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + file_manager_, &DownloadFileManager::CancelDownload, download_id)); } void DownloadManager::PauseDownload(int32 download_id, bool pause) { @@ -1212,15 +1208,16 @@ void DownloadManager::RemoveObserver(Observer* observer) { // user interface. void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { DCHECK(file_manager_); - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); #if defined(OS_MACOSX) // Mac needs to run this operation on the UI thread. platform_util::ShowItemInFolder(download->full_path()); #else - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(file_manager_, - &DownloadFileManager::OnShowDownloadInShell, - FilePath(download->full_path()))); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + file_manager_, &DownloadFileManager::OnShowDownloadInShell, + FilePath(download->full_path()))); #endif } @@ -1260,15 +1257,16 @@ void DownloadManager::OpenChromeExtension(const FilePath& full_path, void DownloadManager::OpenDownloadInShell(const DownloadItem* download, gfx::NativeView parent_window) { DCHECK(file_manager_); - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); #if defined(OS_MACOSX) // Mac OS X requires opening downloads on the UI thread. platform_util::OpenItem(download->full_path()); #else - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(file_manager_, - &DownloadFileManager::OnOpenDownloadInShell, - download->full_path(), download->url(), parent_window)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + file_manager_, &DownloadFileManager::OnOpenDownloadInShell, + download->full_path(), download->url(), parent_window)); #endif } @@ -1407,8 +1405,9 @@ void DownloadManager::FileSelectionCanceled(void* params) { } void DownloadManager::DeleteDownload(const FilePath& path) { - file_loop_->PostTask(FROM_HERE, NewRunnableFunction( - &DownloadFileManager::DeleteFile, FilePath(path))); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableFunction(&DownloadFileManager::DeleteFile, FilePath(path))); } @@ -1422,11 +1421,12 @@ void DownloadManager::DangerousDownloadValidated(DownloadItem* download) { if (download->state() != DownloadItem::COMPLETE) return; - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadManager::ProceedWithFinishedDangerousDownload, - download->db_handle(), download->full_path(), - download->original_name())); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &DownloadManager::ProceedWithFinishedDangerousDownload, + download->db_handle(), download->full_path(), + download->original_name())); } void DownloadManager::GenerateSafeFilename(const std::string& mime_type, diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 5f613a8..3974df6 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -59,7 +59,6 @@ class DownloadFileManager; class DownloadItemView; class DownloadManager; class GURL; -class MessageLoop; class PrefService; class Profile; class ResourceDispatcherHost; @@ -592,13 +591,6 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // Non-owning pointer for handling file writing on the download_thread_. DownloadFileManager* file_manager_; - // A pointer to the main UI loop. - MessageLoop* ui_loop_; - - // A pointer to the file thread's loop. The file thread lives longer than - // the DownloadManager, so this is safe to cache. - MessageLoop* file_loop_; - // User preferences BooleanPrefMember prompt_for_download_; StringPrefMember download_path_; diff --git a/chrome/browser/download/save_file_manager.cc b/chrome/browser/download/save_file_manager.cc index 3289799..a985071 100644 --- a/chrome/browser/download/save_file_manager.cc +++ b/chrome/browser/download/save_file_manager.cc @@ -12,7 +12,7 @@ #include "base/string_util.h" #include "base/task.h" #include "base/thread.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/save_file.h" #include "chrome/browser/download/save_package.h" #include "chrome/browser/net/url_request_context_getter.h" @@ -27,25 +27,9 @@ #include "net/url_request/url_request_context.h" -SaveFileManager::SaveFileManager(MessageLoop* ui_loop, - MessageLoop* io_loop, - ResourceDispatcherHost* rdh) +SaveFileManager::SaveFileManager(ResourceDispatcherHost* rdh) : next_id_(0), - ui_loop_(ui_loop), - io_loop_(io_loop), resource_dispatcher_host_(rdh) { - DCHECK(ui_loop_); - // Need to make sure that we are in UI thread because using g_browser_process - // on a non-UI thread can cause crashes during shutdown. - DCHECK_EQ(ui_loop_, MessageLoop::current()); - // Cache the message loop of file thread. - base::Thread* thread = g_browser_process->file_thread(); - if (thread) - file_loop_ = thread->message_loop(); - else - // It could be NULL when it is created in unit test of - // ResourceDispatcherHost. - file_loop_ = NULL; DCHECK(resource_dispatcher_host_); } @@ -57,16 +41,14 @@ SaveFileManager::~SaveFileManager() { // Called during the browser shutdown process to clean up any state (open files, // timers) that live on the saving thread (file thread). void SaveFileManager::Shutdown() { - MessageLoop* loop = file_loop(); - if (loop) { - loop->PostTask(FROM_HERE, - NewRunnableMethod(this, &SaveFileManager::OnShutdown)); - } + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(this, &SaveFileManager::OnShutdown)); } // Stop file thread operations. void SaveFileManager::OnShutdown() { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); STLDeleteValues(&save_file_map_); } @@ -82,14 +64,14 @@ SaveFile* SaveFileManager::LookupSaveFile(int save_id) { // file a request from the file thread to the IO thread to generate a // unique save ID. int SaveFileManager::GetNextId() { - DCHECK_EQ(MessageLoop::current(), io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); return next_id_++; } void SaveFileManager::RegisterStartingRequest(const GURL& save_url, SavePackage* save_package) { // Make sure it runs in the UI thread. - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); int tab_id = save_package->tab_id(); // Register this starting request. @@ -102,7 +84,7 @@ void SaveFileManager::RegisterStartingRequest(const GURL& save_url, SavePackage* SaveFileManager::UnregisterStartingRequest( const GURL& save_url, int tab_id) { // Make sure it runs in UI thread. - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); TabToStartingRequestsMap::iterator it = tab_starting_requests_.find(tab_id); if (it != tab_starting_requests_.end()) { @@ -123,24 +105,9 @@ SavePackage* SaveFileManager::UnregisterStartingRequest( return NULL; } -void SaveFileManager::RequireSaveJobFromOtherSource(SaveFileCreateInfo* info) { - // This function must be called on the UI thread, because the io_loop_ - // pointer may be junk when we use it on file thread. We can only rely on the - // io_loop_ pointer being valid when we run code on the UI thread (or on - // the IO thread. - DCHECK_EQ(MessageLoop::current(), ui_loop_); - DCHECK_EQ(info->save_id, -1); - // Since the data will come from render process, so we need to start - // this kind of save job by ourself. - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnRequireSaveJobFromOtherSource, - info)); -} - // Look up a SavePackage according to a save id. SavePackage* SaveFileManager::LookupPackage(int save_id) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackageMap::iterator it = packages_.find(save_id); if (it != packages_.end()) return it->second; @@ -156,18 +123,15 @@ void SaveFileManager::SaveURL(const GURL& url, const FilePath& file_full_path, URLRequestContextGetter* request_context_getter, SavePackage* save_package) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); - if (!io_loop_) { - NOTREACHED(); // Net IO thread must exist. - return; - } + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); // Register a saving job. RegisterStartingRequest(url, save_package); if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { DCHECK(url.is_valid()); - io_loop_->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &SaveFileManager::OnSaveURL, url, @@ -183,7 +147,13 @@ void SaveFileManager::SaveURL(const GURL& url, -1); info->render_process_id = render_process_host_id; info->render_view_id = render_view_id; - RequireSaveJobFromOtherSource(info); + + // Since the data will come from render process, so we need to start + // this kind of save job by ourself. + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnRequireSaveJobFromOtherSource, info)); } } @@ -196,7 +166,7 @@ void SaveFileManager::SaveURL(const GURL& url, void SaveFileManager::RemoveSaveFile(int save_id, const GURL& save_url, SavePackage* package) { DCHECK(package); - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); // A save page job(SavePackage) can only have one manager, // so remove it if it exists. if (save_id == -1) { @@ -226,25 +196,19 @@ SavePackage* SaveFileManager::GetSavePackageFromRenderIds( // Utility function for deleting specified file. void SaveFileManager::DeleteDirectoryOrFile(const FilePath& full_path, bool is_dir) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); - MessageLoop* loop = file_loop(); - DCHECK(loop); - loop->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnDeleteDirectoryOrFile, - full_path, - is_dir)); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnDeleteDirectoryOrFile, full_path, is_dir)); } void SaveFileManager::SendCancelRequest(int save_id) { // Cancel the request which has specific save id. DCHECK_GT(save_id, -1); - MessageLoop* loop = file_loop(); - DCHECK(loop); - loop->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::CancelSave, - save_id)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(this, &SaveFileManager::CancelSave, save_id)); } // Notifications sent from the IO thread and run on the file thread: @@ -253,17 +217,16 @@ void SaveFileManager::SendCancelRequest(int save_id) { // to create a SaveFile which will hold and finally destroy |info|. It will // then passes |info| to the UI thread for reporting saving status. void SaveFileManager::StartSave(SaveFileCreateInfo* info) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DCHECK(info); SaveFile* save_file = new SaveFile(info); DCHECK(!LookupSaveFile(info->save_id)); save_file_map_[info->save_id] = save_file; info->path = save_file->full_path(); - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnStartSave, - info)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &SaveFileManager::OnStartSave, info)); } // We do forward an update to the UI thread here, since we do not use timer to @@ -273,16 +236,15 @@ void SaveFileManager::StartSave(SaveFileCreateInfo* info) { void SaveFileManager::UpdateSaveProgress(int save_id, net::IOBuffer* data, int data_len) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); SaveFile* save_file = LookupSaveFile(save_id); if (save_file) { bool write_success = save_file->AppendDataToFile(data->data(), data_len); - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnUpdateSaveProgress, - save_file->save_id(), - save_file->bytes_so_far(), - write_success)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnUpdateSaveProgress, save_file->save_id(), + save_file->bytes_so_far(), write_success)); } data->Release(); } @@ -297,33 +259,32 @@ void SaveFileManager::SaveFinished(int save_id, GURL save_url, int render_process_id, bool is_success) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); SaveFileMap::iterator it = save_file_map_.find(save_id); if (it != save_file_map_.end()) { SaveFile* save_file = it->second; - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnSaveFinished, - save_id, - save_file->bytes_so_far(), - is_success)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnSaveFinished, save_id, + save_file->bytes_so_far(), is_success)); save_file->Finish(); } else if (save_id == -1) { // Before saving started, we got error. We still call finish process. DCHECK(!save_url.is_empty()); - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnErrorFinished, - save_url, - render_process_id)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnErrorFinished, save_url, + render_process_id)); } } // Notifications sent from the file thread and run on the UI thread. void SaveFileManager::OnStartSave(const SaveFileCreateInfo* info) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackage* save_package = GetSavePackageFromRenderIds(info->render_process_id, info->render_view_id); @@ -357,7 +318,7 @@ void SaveFileManager::OnStartSave(const SaveFileCreateInfo* info) { void SaveFileManager::OnUpdateSaveProgress(int save_id, int64 bytes_so_far, bool write_success) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackage* package = LookupPackage(save_id); if (package) package->UpdateSaveProgress(save_id, bytes_so_far, write_success); @@ -368,30 +329,19 @@ void SaveFileManager::OnUpdateSaveProgress(int save_id, int64 bytes_so_far, void SaveFileManager::OnSaveFinished(int save_id, int64 bytes_so_far, bool is_success) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackage* package = LookupPackage(save_id); if (package) package->SaveFinished(save_id, bytes_so_far, is_success); } void SaveFileManager::OnErrorFinished(GURL save_url, int tab_id) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackage* save_package = UnregisterStartingRequest(save_url, tab_id); if (save_package) save_package->SaveFailed(save_url); } -void SaveFileManager::OnCancelSaveRequest(int render_process_id, - int request_id) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); - DCHECK(io_loop_); - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::ExecuteCancelSaveRequest, - render_process_id, - request_id)); -} - // Notifications sent from the UI thread and run on the IO thread. void SaveFileManager::OnSaveURL( @@ -400,7 +350,7 @@ void SaveFileManager::OnSaveURL( int render_process_host_id, int render_view_id, URLRequestContextGetter* request_context_getter) { - DCHECK_EQ(MessageLoop::current(), io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); URLRequestContext* context = request_context_getter->GetURLRequestContext(); resource_dispatcher_host_->BeginSaveFile(url, referrer, @@ -411,22 +361,19 @@ void SaveFileManager::OnSaveURL( void SaveFileManager::OnRequireSaveJobFromOtherSource( SaveFileCreateInfo* info) { - DCHECK_EQ(MessageLoop::current(), io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK_EQ(info->save_id, -1); // Generate a unique save id. info->save_id = GetNextId(); // Start real saving action. - MessageLoop* loop = file_loop(); - DCHECK(loop); - loop->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::StartSave, - info)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(this, &SaveFileManager::StartSave, info)); } void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, int request_id) { - DCHECK_EQ(MessageLoop::current(), io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); resource_dispatcher_host_->CancelRequest(render_process_id, request_id, false); @@ -440,7 +387,7 @@ void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, // sent from the UI thread, the saving job may have already completed and // won't exist in our map. void SaveFileManager::CancelSave(int save_id) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); SaveFileMap::iterator it = save_file_map_.find(save_id); if (it != save_file_map_.end()) { SaveFile* save_file = it->second; @@ -449,11 +396,11 @@ void SaveFileManager::CancelSave(int save_id) { // message to IO thread. If the data comes from other sources, just // ignore the cancel message. if (save_file->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnCancelSaveRequest, - save_file->render_process_id(), - save_file->request_id())); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::ExecuteCancelSaveRequest, + save_file->render_process_id(), save_file->request_id())); // UI thread will notify the render process to stop sending data, // so in here, we need not to do anything, just close the save file. @@ -477,7 +424,7 @@ void SaveFileManager::CancelSave(int save_id) { void SaveFileManager::SaveLocalFile(const GURL& original_file_url, int save_id, int render_process_id) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); SaveFile* save_file = LookupSaveFile(save_id); if (!save_file) return; @@ -507,7 +454,7 @@ void SaveFileManager::SaveLocalFile(const GURL& original_file_url, void SaveFileManager::OnDeleteDirectoryOrFile(const FilePath& full_path, bool is_dir) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DCHECK(!full_path.empty()); file_util::Delete(full_path, is_dir); @@ -517,7 +464,7 @@ void SaveFileManager::OnDeleteDirectoryOrFile(const FilePath& full_path, // We run on this thread to avoid blocking the UI with slow Shell operations. #if !defined(OS_MACOSX) void SaveFileManager::OnShowSavedFileInShell(const FilePath full_path) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); platform_util::ShowItemInFolder(full_path); } #endif @@ -527,7 +474,7 @@ void SaveFileManager::RenameAllFiles( const FilePath& resource_dir, int render_process_id, int render_view_id) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); if (!resource_dir.empty() && !file_util::PathExists(resource_dir)) file_util::CreateDirectory(resource_dir); @@ -544,16 +491,16 @@ void SaveFileManager::RenameAllFiles( } } - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &SaveFileManager::OnFinishSavePageJob, - render_process_id, - render_view_id)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &SaveFileManager::OnFinishSavePageJob, render_process_id, + render_view_id)); } void SaveFileManager::OnFinishSavePageJob(int render_process_id, int render_view_id) { - DCHECK_EQ(MessageLoop::current(), ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); SavePackage* save_package = GetSavePackageFromRenderIds(render_process_id, render_view_id); @@ -566,7 +513,7 @@ void SaveFileManager::OnFinishSavePageJob(int render_process_id, void SaveFileManager::RemoveSavedFileFromFileMap( const SaveIDList& save_ids) { - DCHECK_EQ(MessageLoop::current(), file_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); for (SaveIDList::const_iterator i = save_ids.begin(); i != save_ids.end(); ++i) { diff --git a/chrome/browser/download/save_file_manager.h b/chrome/browser/download/save_file_manager.h index 5f3d564..a77f052 100644 --- a/chrome/browser/download/save_file_manager.h +++ b/chrome/browser/download/save_file_manager.h @@ -72,7 +72,6 @@ class IOBuffer; class GURL; class SaveFile; class SavePackage; -class MessageLoop; class ResourceDispatcherHost; class Task; class URLRequestContextGetter; @@ -80,9 +79,7 @@ class URLRequestContextGetter; class SaveFileManager : public base::RefCountedThreadSafe<SaveFileManager> { public: - SaveFileManager(MessageLoop* ui_loop, - MessageLoop* io_loop, - ResourceDispatcherHost* rdh); + SaveFileManager(ResourceDispatcherHost* rdh); ~SaveFileManager(); // Lifetime management. @@ -127,10 +124,6 @@ class SaveFileManager // Helper function for deleting specified file. void DeleteDirectoryOrFile(const FilePath& full_path, bool is_dir); - // For posting notifications from the UI and file threads. - MessageLoop* ui_loop() const { return ui_loop_; } - MessageLoop* file_loop() const { return file_loop_; } - // Runs on file thread to save a file by copying from file system when // original url is using file scheme. void SaveLocalFile(const GURL& original_file_url, @@ -154,12 +147,6 @@ class SaveFileManager // A cleanup helper that runs on the file thread. void OnShutdown(); - // The resource does not come from the network, but we still needs to call - // this function for getting unique save ID by calling - // OnRequireSaveJobFromOtherSource in the net IO thread and start saving - // operation. This function is called on the UI thread. - void RequireSaveJobFromOtherSource(SaveFileCreateInfo* info); - // Called only on UI thread to get the SavePackage for a tab's profile. static SavePackage* GetSavePackageFromRenderIds(int render_process_id, int review_view_id); @@ -199,10 +186,6 @@ class SaveFileManager // For those requests that do not have valid save id, use // map:(url, SavePackage) to find the request and remove it. void OnErrorFinished(GURL save_url, int tab_id); - // Handler for a notification sent to the UI thread. - // The user has requested a cancel in the UI thread, so send a cancel request - // to stop the network requests in net IO thread. - void OnCancelSaveRequest(int render_process_id, int request_id); // Notifies SavePackage that the whole page saving job is finished. void OnFinishSavePageJob(int render_process_id, int render_view_id); @@ -232,17 +215,6 @@ class SaveFileManager typedef base::hash_map<int, SaveFile*> SaveFileMap; SaveFileMap save_file_map_; - // Message loop that the SavePackages live on. - MessageLoop* ui_loop_; - - // We cache the IO loop, we will use it to request resources from network. - MessageLoop* io_loop_; - - // We cache the file loop, we will use it to do real file operation. - // We guarantee that we won't access them incorrectly during the shutdown - // process - MessageLoop* file_loop_; - ResourceDispatcherHost* resource_dispatcher_host_; // Tracks which SavePackage to send data to, called only on UI thread. diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 20cb15b..15e4787 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -14,6 +14,7 @@ #include "base/task.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_shelf.h" @@ -478,7 +479,8 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) { // If the save source is from file system, inform SaveFileManager to copy // corresponding file to the file path which this SaveItem specifies. if (info->save_source == SaveFileCreateInfo::SAVE_FILE_FROM_FILE) { - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::SaveLocalFile, save_item->url(), @@ -584,7 +586,8 @@ void SavePackage::Stop() { it != saved_failed_items_.end(); ++it) save_ids.push_back(it->second->save_id()); - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::RemoveSavedFileFromFileMap, save_ids)); @@ -613,7 +616,8 @@ void SavePackage::CheckFinish() { final_names.push_back(std::make_pair(it->first, it->second->full_path())); - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::RenameAllFiles, final_names, @@ -638,7 +642,8 @@ void SavePackage::Finish() { it != saved_failed_items_.end(); ++it) save_ids.push_back(it->second->save_id()); - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::RemoveSavedFileFromFileMap, save_ids)); @@ -734,7 +739,8 @@ void SavePackage::SaveCanceled(SaveItem* save_item) { save_item->url(), this); if (save_item->save_id() != -1) - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::CancelSave, save_item->save_id())); @@ -776,12 +782,13 @@ void SavePackage::SaveNextFile(bool process_all_remaining_items) { void SavePackage::ShowDownloadInShell() { DCHECK(file_manager_); DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); - DCHECK(MessageLoop::current() == file_manager_->ui_loop()); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); #if defined(OS_MACOSX) // Mac OS X requires opening downloads on the UI thread. platform_util::ShowItemInFolder(saved_main_file_path_); #else - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::OnShowSavedFileInShell, saved_main_file_path_)); @@ -902,7 +909,8 @@ void SavePackage::OnReceivedSerializedHtmlData(const GURL& frame_url, if (flag == webkit_glue::DomSerializerDelegate::ALL_FRAMES_ARE_FINISHED) { for (SaveUrlItemMap::iterator it = in_progress_items_.begin(); it != in_progress_items_.end(); ++it) { - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::SaveFinished, it->second->save_id(), @@ -926,7 +934,8 @@ void SavePackage::OnReceivedSerializedHtmlData(const GURL& frame_url, memcpy(new_data->data(), data.data(), data.size()); // Call write file functionality in file thread. - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::UpdateSaveProgress, save_item->save_id(), @@ -936,7 +945,8 @@ void SavePackage::OnReceivedSerializedHtmlData(const GURL& frame_url, // Current frame is completed saving, call finish in file thread. if (flag == webkit_glue::DomSerializerDelegate::CURRENT_FRAME_IS_FINISHED) { - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(file_manager_, &SaveFileManager::SaveFinished, save_item->save_id(), @@ -1081,7 +1091,8 @@ void SavePackage::GetSaveInfo() { FilePath save_dir = GetSaveDirPreference(tab_contents_->profile()->GetPrefs()); - file_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, new CreateDownloadDirectoryTask(save_dir, method_factory_.NewRunnableMethod( &SavePackage::ContinueGetSaveInfo, save_dir), diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index b1c7129..77d71c4 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -257,7 +257,7 @@ ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) download_file_manager_(new DownloadFileManager(this))), download_request_manager_(new DownloadRequestManager(io_loop, ui_loop_)), ALLOW_THIS_IN_INITIALIZER_LIST( - save_file_manager_(new SaveFileManager(ui_loop_, io_loop, this))), + save_file_manager_(new SaveFileManager(this))), ALLOW_THIS_IN_INITIALIZER_LIST(user_script_listener_( new UserScriptListener(this))), safe_browsing_(new SafeBrowsingService), @@ -295,16 +295,16 @@ ResourceDispatcherHost::~ResourceDispatcherHost() { } void ResourceDispatcherHost::Initialize() { - DCHECK(MessageLoop::current() == ui_loop_); - safe_browsing_->Initialize(io_loop_); - io_loop_->PostTask( - FROM_HERE, + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + safe_browsing_->Initialize(); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); } void ResourceDispatcherHost::Shutdown() { - DCHECK(MessageLoop::current() == ui_loop_); - io_loop_->PostTask(FROM_HERE, new ShutdownTask(this)); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, new ShutdownTask(this)); } void ResourceDispatcherHost::SetRequestInfo( @@ -314,7 +314,7 @@ void ResourceDispatcherHost::SetRequestInfo( } void ResourceDispatcherHost::OnShutdown() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); is_shutdown_ = true; STLDeleteValues(&pending_requests_); // Make sure we shutdown the timer now, otherwise by the time our destructor @@ -332,8 +332,10 @@ bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, if (!ResourceType::IsFrame(type) || URLRequest::IsHandledURL(url)) return false; - ui_loop_->PostTask(FROM_HERE, NewRunnableFunction( - &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableFunction( + &ExternalProtocolHandler::LaunchUrl, url, child_id, route_id)); handler->OnResponseCompleted(request_id, URLRequestStatus( URLRequestStatus::FAILED, @@ -677,8 +679,8 @@ void ResourceDispatcherHost::OnClosePageACK( // This is a tab close, so just forward the message to close it. DCHECK(params.new_render_process_host_id == -1); DCHECK(params.new_request_id == -1); - ui_loop_->PostTask( - FROM_HERE, + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, new RVHCloseNotificationTask(params.closing_process_id, params.closing_route_id)); } @@ -1517,9 +1519,8 @@ void ResourceDispatcherHost::RemoveObserver(Observer* obs) { URLRequest* ResourceDispatcherHost::GetURLRequest( GlobalRequestID request_id) const { - // This should be running in the IO loop. io_loop_ can be NULL during the - // unit_tests. - DCHECK(MessageLoop::current() == io_loop_ && io_loop_); + // This should be running in the IO loop. + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); PendingRequestList::const_iterator i = pending_requests_.find(request_id); if (i == pending_requests_.end()) @@ -1551,9 +1552,12 @@ void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request, FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request)); // Notify the observers on the UI thread. - ui_loop_->PostTask(FROM_HERE, new RVHDelegateNotificationTask(request, - &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, - new ResourceRequestDetails(request, GetCertID(request, child_id)))); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + new RVHDelegateNotificationTask( + request, + &RenderViewHostDelegate::Resource::DidStartReceivingResourceResponse, + new ResourceRequestDetails(request, GetCertID(request, child_id)))); } void ResourceDispatcherHost::NotifyResponseCompleted(URLRequest* request, @@ -1573,9 +1577,10 @@ void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request, int cert_id = GetCertID(request, child_id); // Notify the observers on the UI thread. - ui_loop_->PostTask(FROM_HERE, - new RVHDelegateNotificationTask(request, - &RenderViewHostDelegate::Resource::DidRedirectResource, + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + new RVHDelegateNotificationTask( + request, &RenderViewHostDelegate::Resource::DidRedirectResource, new ResourceRedirectDetails(request, cert_id, new_url))); } @@ -1696,7 +1701,7 @@ void ResourceDispatcherHost::UpdateLoadStates() { LoadInfoUpdateTask* task = new LoadInfoUpdateTask; task->info_map.swap(info_map); - ui_loop_->PostTask(FROM_HERE, task); + ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, task); } // Calls the ResourceHandler to send upload progress messages to the renderer. diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index 1cfe9a8..147a7f9 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -105,6 +105,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { } }; + // TODO(jam): take the parameter out once 25354 is done. explicit ResourceDispatcherHost(MessageLoop* io_loop); ~ResourceDispatcherHost(); diff --git a/chrome/browser/renderer_host/save_file_resource_handler.cc b/chrome/browser/renderer_host/save_file_resource_handler.cc index bb426ce..b6584f0 100644 --- a/chrome/browser/renderer_host/save_file_resource_handler.cc +++ b/chrome/browser/renderer_host/save_file_resource_handler.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/save_file_manager.h" #include "net/base/io_buffer.h" @@ -44,7 +45,8 @@ bool SaveFileResourceHandler::OnResponseStarted(int request_id, info->request_id = request_id; info->content_disposition = content_disposition_; info->save_source = SaveFileCreateInfo::SAVE_FILE_FROM_NET; - save_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(save_manager_, &SaveFileManager::StartSave, info)); @@ -69,7 +71,8 @@ bool SaveFileResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { // We are passing ownership of this buffer to the save file manager. net::IOBuffer* buffer = NULL; read_buffer_.swap(&buffer); - save_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(save_manager_, &SaveFileManager::UpdateSaveProgress, save_id_, @@ -82,7 +85,8 @@ bool SaveFileResourceHandler::OnResponseCompleted( int request_id, const URLRequestStatus& status, const std::string& security_info) { - save_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(save_manager_, &SaveFileManager::SaveFinished, save_id_, diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index 99249e1..aeef7b2 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -7,13 +7,13 @@ #include "base/file_version_info.h" #include "base/histogram.h" #include "base/logging.h" -#include "base/message_loop.h" #include "base/rand_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/sys_info.h" #include "base/task.h" #include "base/timer.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/profile.h" #include "chrome/browser/safe_browsing/protocol_parser.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" @@ -67,7 +67,6 @@ static const int kSbMaxBackOff = 8; SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( SafeBrowsingService* sb_service, - MessageLoop* notify_loop, const std::string& client_key, const std::string& wrapped_key) : sb_service_(sb_service), @@ -80,7 +79,6 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( update_state_(FIRST_REQUEST), initial_request_(true), chunk_pending_to_write_(false), - notify_loop_(notify_loop), client_key_(client_key), wrapped_key_(wrapped_key), update_size_(0) { @@ -423,9 +421,11 @@ bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, client_key_ = client_key; wrapped_key_ = wrapped_key; - notify_loop_->PostTask(FROM_HERE, NewRunnableMethod( - sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_, - wrapped_key_)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_, + wrapped_key_)); break; } diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h index e9d0408..e267bcb 100644 --- a/chrome/browser/safe_browsing/protocol_manager.h +++ b/chrome/browser/safe_browsing/protocol_manager.h @@ -24,7 +24,6 @@ #include "chrome/browser/safe_browsing/safe_browsing_util.h" #include "testing/gtest/include/gtest/gtest_prod.h" -class MessageLoop; class Task; class Timer; class URLRequestStatus; @@ -50,7 +49,6 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate { public: SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, - MessageLoop* notify_loop, const std::string& client_key, const std::string& wrapped_key); ~SafeBrowsingProtocolManager(); @@ -212,10 +210,6 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate { // added to the database yet. bool chunk_pending_to_write_; - // Message loop for forwarding MAC keys to the SafeBrowsingService for - // storage. - MessageLoop* notify_loop_; - // The keys used for MAC. Empty keys mean we aren't using MAC. std::string client_key_; std::string wrapped_key_; diff --git a/chrome/browser/safe_browsing/protocol_manager_unittest.cc b/chrome/browser/safe_browsing/protocol_manager_unittest.cc index 8af7a1b..40b8b77 100644 --- a/chrome/browser/safe_browsing/protocol_manager_unittest.cc +++ b/chrome/browser/safe_browsing/protocol_manager_unittest.cc @@ -16,7 +16,7 @@ class SafeBrowsingProtocolManagerTest : public testing::Test { // Ensure that we respect section 5 of the SafeBrowsing protocol specification. TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { - SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", ""); pm.next_update_sec_ = 1800; DCHECK(pm.back_off_fuzz_ >= 0.0 && pm.back_off_fuzz_ <= 1.0); @@ -54,7 +54,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { // Test string combinations with and without MAC. TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { - SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", ""); // Add and Sub chunks. SBListChunkRanges phish("goog-phish-shavar"); @@ -87,7 +87,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { } TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { - SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", ""); // No errors or back off time yet. EXPECT_EQ(pm.gethash_error_count_, 0); diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 260c592..2dddb60 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -31,8 +31,7 @@ using base::Time; using base::TimeDelta; SafeBrowsingService::SafeBrowsingService() - : io_loop_(NULL), - database_(NULL), + : database_(NULL), protocol_manager_(NULL), enabled_(false), resetting_(false), @@ -44,9 +43,7 @@ SafeBrowsingService::~SafeBrowsingService() { } // Only called on the UI thread. -void SafeBrowsingService::Initialize(MessageLoop* io_loop) { - io_loop_ = io_loop; - +void SafeBrowsingService::Initialize() { // Get the profile's preference for SafeBrowsing. FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); @@ -75,26 +72,26 @@ void SafeBrowsingService::Start() { WideToASCII(local_state->GetString(prefs::kSafeBrowsingWrappedKey)); } - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnIOInitialize, MessageLoop::current(), - client_key, wrapped_key)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, &SafeBrowsingService::OnIOInitialize, client_key, wrapped_key)); safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( this, &SafeBrowsingService::OnDBInitialize)); } void SafeBrowsingService::ShutDown() { - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnIOShutdown)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown)); } -void SafeBrowsingService::OnIOInitialize(MessageLoop* notify_loop, - const std::string& client_key, +void SafeBrowsingService::OnIOInitialize(const std::string& client_key, const std::string& wrapped_key) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); enabled_ = true; protocol_manager_ = new SafeBrowsingProtocolManager(this, - notify_loop, client_key, wrapped_key); // We want to initialize the protocol manager only after the database has @@ -111,7 +108,7 @@ void SafeBrowsingService::OnDBInitialize() { } void SafeBrowsingService::OnIOShutdown() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!enabled_) return; @@ -166,7 +163,7 @@ bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { } bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!enabled_ || !database_) return true; @@ -202,8 +199,9 @@ bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) { check->full_hits.swap(full_hits); checks_.insert(check); - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnCheckDone, check)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &SafeBrowsingService::OnCheckDone, check)); return false; } @@ -278,7 +276,8 @@ void SafeBrowsingService::DoDisplayBlockingPage( NavigationEntry* entry = wc->controller().GetActiveEntry(); if (entry) referrer_url = entry->referrer(); - io_loop_->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &SafeBrowsingService::ReportMalware, resource.url, @@ -290,7 +289,7 @@ void SafeBrowsingService::DoDisplayBlockingPage( } void SafeBrowsingService::CancelCheck(Client* client) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) { if ((*i)->client == client) @@ -309,7 +308,7 @@ void SafeBrowsingService::CancelCheck(Client* client) { } void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); // If we've been shutdown during the database lookup, this check will already // have been deleted (in OnIOShutdown). @@ -367,8 +366,9 @@ SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() { database->Init(path, chunk_callback); database_ = database; - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::DatabaseLoadComplete)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &SafeBrowsingService::DatabaseLoadComplete)); TimeDelta open_time = Time::Now() - before; SB_DLOG(INFO) << "SafeBrowsing database open took " << @@ -445,7 +445,7 @@ void SafeBrowsingService::HandleOneCheck( } void SafeBrowsingService::UpdateStarted() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(enabled_); DCHECK(!update_in_progress_); update_in_progress_ = true; @@ -454,7 +454,7 @@ void SafeBrowsingService::UpdateStarted() { } void SafeBrowsingService::UpdateFinished(bool update_succeeded) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(enabled_); if (update_in_progress_) { update_in_progress_ = false; @@ -509,18 +509,19 @@ void SafeBrowsingService::OnNewMacKeys(const std::string& client_key, void SafeBrowsingService::ChunkInserted() { DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnChunkInserted)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &SafeBrowsingService::OnChunkInserted)); } void SafeBrowsingService::OnChunkInserted() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (enabled_) protocol_manager_->OnChunkInserted(); } void SafeBrowsingService::DatabaseLoadComplete() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!enabled_) return; @@ -541,7 +542,7 @@ void SafeBrowsingService::RegisterPrefs(PrefService* prefs) { } void SafeBrowsingService::ResetDatabase() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); resetting_ = true; safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( this, &SafeBrowsingService::OnResetDatabase)); @@ -550,12 +551,13 @@ void SafeBrowsingService::ResetDatabase() { void SafeBrowsingService::OnResetDatabase() { DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop()); GetDatabase()->ResetDatabase(); - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnResetComplete)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &SafeBrowsingService::OnResetComplete)); } void SafeBrowsingService::OnResetComplete() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (enabled_) { resetting_ = false; database_loaded_ = true; @@ -565,7 +567,7 @@ void SafeBrowsingService::OnResetComplete() { void SafeBrowsingService::HandleChunk(const std::string& list, std::deque<SBChunk>* chunks) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(enabled_); safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( this, &SafeBrowsingService::HandleChunkForDatabase, list, chunks)); @@ -581,7 +583,7 @@ void SafeBrowsingService::HandleChunkForDatabase( void SafeBrowsingService::HandleChunkDelete( std::vector<SBChunkDelete>* chunk_deletes) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(enabled_); safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( this, &SafeBrowsingService::DeleteChunks, chunk_deletes)); @@ -608,15 +610,17 @@ void SafeBrowsingService::GetAllChunksFromDatabase() { } } - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists, - database_error)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists, + database_error)); } // Called on the io thread with the results of all chunks. void SafeBrowsingService::OnGetAllChunksFromDatabase( const std::vector<SBListChunkRanges>& lists, bool database_error) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (enabled_) protocol_manager_->OnGetChunksComplete(lists, database_error); } @@ -647,7 +651,7 @@ void SafeBrowsingService::CacheHashResults( } void SafeBrowsingService::RunQueuedClients() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size()); while (!queued_checks_.empty()) { QueuedCheck check = queued_checks_.front(); @@ -660,7 +664,7 @@ void SafeBrowsingService::RunQueuedClients() { void SafeBrowsingService::ReportMalware(const GURL& malware_url, const GURL& page_url, const GURL& referrer_url) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (!enabled_ || !database_) return; diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h index 95417b7..d5cca6b 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.h +++ b/chrome/browser/safe_browsing/safe_browsing_service.h @@ -23,7 +23,6 @@ #include "webkit/glue/resource_type.h" class BloomFilter; -class MessageLoop; class PrefService; class SafeBrowsingBlockingPage; class SafeBrowsingDatabase; @@ -68,14 +67,11 @@ class SafeBrowsingService SafeBrowsingService(); ~SafeBrowsingService(); - // Initializes the service. io_loop is the message loop that the - // caller of this service (ResourceDispatcherHost) wants to be notified on - // for check results. - void Initialize(MessageLoop* io_loop); + // Initializes the service. + void Initialize(); // Called to initialize objects that are used on the io_thread. - void OnIOInitialize(MessageLoop* notify_loop, - const std::string& client_key, + void OnIOInitialize(const std::string& client_key, const std::string& wrapped_key); // Called to initialize objects that are used on the db_thread. @@ -234,8 +230,6 @@ class SafeBrowsingService void OnUpdateComplete(bool update_succeeded); - MessageLoop* io_loop_; - typedef std::set<SafeBrowsingCheck*> CurrentChecks; CurrentChecks checks_; |