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/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 next_download_id_(0), | 125 next_download_id_(0), |
126 download_prefs_(new DownloadPrefs(profile)) { | 126 download_prefs_(new DownloadPrefs(profile)) { |
127 } | 127 } |
128 | 128 |
129 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 129 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
130 } | 130 } |
131 | 131 |
132 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 132 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
133 download_manager_ = dm; | 133 download_manager_ = dm; |
134 download_history_.reset(new DownloadHistory(profile_)); | 134 download_history_.reset(new DownloadHistory(profile_)); |
135 download_history_->Load( | 135 if (!profile_->IsOffTheRecord()) { |
136 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 136 // DownloadManager should not be RefCountedThreadSafe. |
137 base::Unretained(dm))); | 137 // ChromeDownloadManagerDelegate outlives DownloadManager, and |
| 138 // DownloadHistory uses a scoped canceller to cancel tasks when it is |
| 139 // deleted. Almost all callbacks to DownloadManager should use weak pointers |
| 140 // or bounce off a container object that uses ManagerGoingDown() to simulate |
| 141 // a weak pointer. |
| 142 download_history_->Load( |
| 143 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
| 144 download_manager_)); |
| 145 } |
138 #if !defined(OS_ANDROID) | 146 #if !defined(OS_ANDROID) |
139 extension_event_router_.reset(new ExtensionDownloadsEventRouter( | 147 extension_event_router_.reset(new ExtensionDownloadsEventRouter( |
140 profile_, download_manager_)); | 148 profile_, download_manager_)); |
141 #endif | 149 #endif |
142 } | 150 } |
143 | 151 |
144 void ChromeDownloadManagerDelegate::Shutdown() { | 152 void ChromeDownloadManagerDelegate::Shutdown() { |
145 download_history_.reset(); | 153 download_history_.reset(); |
146 download_prefs_.reset(); | 154 download_prefs_.reset(); |
147 #if !defined(OS_ANDROID) | 155 #if !defined(OS_ANDROID) |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 #if defined(ENABLE_SAFE_BROWSING) | 425 #if defined(ENABLE_SAFE_BROWSING) |
418 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 426 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
419 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 427 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
420 #else | 428 #else |
421 return false; | 429 return false; |
422 #endif | 430 #endif |
423 } | 431 } |
424 | 432 |
425 void ChromeDownloadManagerDelegate::AddItemToPersistentStore( | 433 void ChromeDownloadManagerDelegate::AddItemToPersistentStore( |
426 DownloadItem* item) { | 434 DownloadItem* item) { |
| 435 if (profile_->IsOffTheRecord()) { |
| 436 OnItemAddedToPersistentStore( |
| 437 item->GetId(), download_history_->GetNextFakeDbHandle()); |
| 438 return; |
| 439 } |
427 download_history_->AddEntry(item, | 440 download_history_->AddEntry(item, |
428 base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, | 441 base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, |
429 base::Unretained(this))); | 442 this)); |
430 } | 443 } |
431 | 444 |
432 void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore( | 445 void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore( |
433 DownloadItem* item) { | 446 DownloadItem* item) { |
434 download_history_->UpdateEntry(item); | 447 download_history_->UpdateEntry(item); |
435 } | 448 } |
436 | 449 |
437 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( | 450 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( |
438 DownloadItem* item, | 451 DownloadItem* item, |
439 const FilePath& new_path) { | 452 const FilePath& new_path) { |
440 download_history_->UpdateDownloadPath(item, new_path); | 453 download_history_->UpdateDownloadPath(item, new_path); |
441 } | 454 } |
442 | 455 |
443 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( | 456 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( |
444 DownloadItem* item) { | 457 DownloadItem* item) { |
445 download_history_->RemoveEntry(item); | 458 download_history_->RemoveEntry(item); |
446 } | 459 } |
447 | 460 |
448 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( | 461 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( |
449 base::Time remove_begin, | 462 base::Time remove_begin, |
450 base::Time remove_end) { | 463 base::Time remove_end) { |
| 464 if (profile_->IsOffTheRecord()) |
| 465 return; |
451 download_history_->RemoveEntriesBetween(remove_begin, remove_end); | 466 download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
452 } | 467 } |
453 | 468 |
454 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, | 469 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, |
455 FilePath* website_save_dir, | 470 FilePath* website_save_dir, |
456 FilePath* download_save_dir, | 471 FilePath* download_save_dir, |
457 bool* skip_dir_check) { | 472 bool* skip_dir_check) { |
458 Profile* profile = | 473 Profile* profile = |
459 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 474 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
460 PrefService* prefs = profile->GetPrefs(); | 475 PrefService* prefs = profile->GetPrefs(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 586 |
572 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) | 587 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) |
573 << " verdict = " << result; | 588 << " verdict = " << result; |
574 content::DownloadDangerType danger_type = download->GetDangerType(); | 589 content::DownloadDangerType danger_type = download->GetDangerType(); |
575 if (result != DownloadProtectionService::SAFE) | 590 if (result != DownloadProtectionService::SAFE) |
576 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; | 591 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
577 | 592 |
578 download_history_->CheckVisitedReferrerBefore( | 593 download_history_->CheckVisitedReferrerBefore( |
579 download_id, download->GetReferrerUrl(), | 594 download_id, download->GetReferrerUrl(), |
580 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, | 595 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
581 base::Unretained(this), download_id, callback, danger_type)); | 596 this, download_id, callback, danger_type)); |
582 } | 597 } |
583 | 598 |
584 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 599 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
585 int32 download_id, | 600 int32 download_id, |
586 DownloadProtectionService::DownloadCheckResult result) { | 601 DownloadProtectionService::DownloadCheckResult result) { |
587 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 602 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
588 if (!item) | 603 if (!item) |
589 return; | 604 return; |
590 | 605 |
591 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 606 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 int32 download_id, int64 db_handle) { | 835 int32 download_id, int64 db_handle) { |
821 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 836 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
822 // call this function with an invalid |db_handle|. For instance, this can | 837 // call this function with an invalid |db_handle|. For instance, this can |
823 // happen when the history database is offline. We cannot have multiple | 838 // happen when the history database is offline. We cannot have multiple |
824 // DownloadItems with the same invalid db_handle, so we need to assign a | 839 // DownloadItems with the same invalid db_handle, so we need to assign a |
825 // unique |db_handle| here. | 840 // unique |db_handle| here. |
826 if (db_handle == DownloadItem::kUninitializedHandle) | 841 if (db_handle == DownloadItem::kUninitializedHandle) |
827 db_handle = download_history_->GetNextFakeDbHandle(); | 842 db_handle = download_history_->GetNextFakeDbHandle(); |
828 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 843 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
829 } | 844 } |
OLD | NEW |