Chromium Code Reviews| 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_->GetOriginalProfile() == profile_) { |
|
Randy Smith (Not in Mondays)
2012/08/02 17:52:17
Did you consider doing this at the DownloadHistory
benjhayden
2012/08/13 15:08:09
I think we agreed to keep the conditionals in CDMD
Randy Smith (Not in Mondays)
2012/08/13 18:52:58
Yep, that's my memory too.
| |
| 136 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 136 download_history_->Load( |
| 137 base::Unretained(dm))); | 137 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
| 138 download_manager_)); | |
|
Randy Smith (Not in Mondays)
2012/08/02 17:52:17
I'm somewhat uncomfortable here. I'll agree in ad
benjhayden
2012/08/13 15:08:09
This call is disappearing in my DownloadHistory CL
Randy Smith (Not in Mondays)
2012/08/13 18:52:58
The problem is someone (say a poor idealistic new
benjhayden
2012/08/13 20:26:24
Done.
| |
| 139 } | |
| 138 #if !defined(OS_ANDROID) | 140 #if !defined(OS_ANDROID) |
| 139 extension_event_router_.reset(new ExtensionDownloadsEventRouter( | 141 extension_event_router_.reset(new ExtensionDownloadsEventRouter( |
| 140 profile_, download_manager_)); | 142 profile_, download_manager_)); |
| 141 #endif | 143 #endif |
| 142 } | 144 } |
| 143 | 145 |
| 144 void ChromeDownloadManagerDelegate::Shutdown() { | 146 void ChromeDownloadManagerDelegate::Shutdown() { |
| 145 download_history_.reset(); | 147 download_history_.reset(); |
| 146 download_prefs_.reset(); | 148 download_prefs_.reset(); |
| 147 #if !defined(OS_ANDROID) | 149 #if !defined(OS_ANDROID) |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 #if defined(ENABLE_SAFE_BROWSING) | 419 #if defined(ENABLE_SAFE_BROWSING) |
| 418 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 420 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 419 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 421 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
| 420 #else | 422 #else |
| 421 return false; | 423 return false; |
| 422 #endif | 424 #endif |
| 423 } | 425 } |
| 424 | 426 |
| 425 void ChromeDownloadManagerDelegate::AddItemToPersistentStore( | 427 void ChromeDownloadManagerDelegate::AddItemToPersistentStore( |
| 426 DownloadItem* item) { | 428 DownloadItem* item) { |
| 429 if (profile_->IsOffTheRecord()) { | |
| 430 OnItemAddedToPersistentStore( | |
| 431 item->GetId(), download_history_->GetNextFakeDbHandle()); | |
| 432 return; | |
| 433 } | |
| 427 download_history_->AddEntry(item, | 434 download_history_->AddEntry(item, |
| 428 base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, | 435 base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, |
| 429 base::Unretained(this))); | 436 this)); |
| 430 } | 437 } |
| 431 | 438 |
| 432 void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore( | 439 void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore( |
| 433 DownloadItem* item) { | 440 DownloadItem* item) { |
| 434 download_history_->UpdateEntry(item); | 441 download_history_->UpdateEntry(item); |
| 435 } | 442 } |
| 436 | 443 |
| 437 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( | 444 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( |
| 438 DownloadItem* item, | 445 DownloadItem* item, |
| 439 const FilePath& new_path) { | 446 const FilePath& new_path) { |
| 440 download_history_->UpdateDownloadPath(item, new_path); | 447 download_history_->UpdateDownloadPath(item, new_path); |
| 441 } | 448 } |
| 442 | 449 |
| 443 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( | 450 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( |
| 444 DownloadItem* item) { | 451 DownloadItem* item) { |
| 445 download_history_->RemoveEntry(item); | 452 download_history_->RemoveEntry(item); |
| 446 } | 453 } |
| 447 | 454 |
| 448 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( | 455 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( |
| 449 base::Time remove_begin, | 456 base::Time remove_begin, |
| 450 base::Time remove_end) { | 457 base::Time remove_end) { |
| 458 if (profile_->IsOffTheRecord()) | |
| 459 return; | |
| 451 download_history_->RemoveEntriesBetween(remove_begin, remove_end); | 460 download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
| 452 } | 461 } |
| 453 | 462 |
| 454 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, | 463 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, |
| 455 FilePath* website_save_dir, | 464 FilePath* website_save_dir, |
| 456 FilePath* download_save_dir, | 465 FilePath* download_save_dir, |
| 457 bool* skip_dir_check) { | 466 bool* skip_dir_check) { |
| 458 Profile* profile = | 467 Profile* profile = |
| 459 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 468 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 460 PrefService* prefs = profile->GetPrefs(); | 469 PrefService* prefs = profile->GetPrefs(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 | 580 |
| 572 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) | 581 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) |
| 573 << " verdict = " << result; | 582 << " verdict = " << result; |
| 574 content::DownloadDangerType danger_type = download->GetDangerType(); | 583 content::DownloadDangerType danger_type = download->GetDangerType(); |
| 575 if (result != DownloadProtectionService::SAFE) | 584 if (result != DownloadProtectionService::SAFE) |
| 576 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; | 585 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
| 577 | 586 |
| 578 download_history_->CheckVisitedReferrerBefore( | 587 download_history_->CheckVisitedReferrerBefore( |
| 579 download_id, download->GetReferrerUrl(), | 588 download_id, download->GetReferrerUrl(), |
| 580 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, | 589 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| 581 base::Unretained(this), download_id, callback, danger_type)); | 590 this, download_id, callback, danger_type)); |
| 582 } | 591 } |
| 583 | 592 |
| 584 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 593 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| 585 int32 download_id, | 594 int32 download_id, |
| 586 DownloadProtectionService::DownloadCheckResult result) { | 595 DownloadProtectionService::DownloadCheckResult result) { |
| 587 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 596 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 588 if (!item) | 597 if (!item) |
| 589 return; | 598 return; |
| 590 | 599 |
| 591 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 600 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) { | 829 int32 download_id, int64 db_handle) { |
| 821 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 830 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 822 // call this function with an invalid |db_handle|. For instance, this can | 831 // call this function with an invalid |db_handle|. For instance, this can |
| 823 // happen when the history database is offline. We cannot have multiple | 832 // 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 | 833 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 825 // unique |db_handle| here. | 834 // unique |db_handle| here. |
| 826 if (db_handle == DownloadItem::kUninitializedHandle) | 835 if (db_handle == DownloadItem::kUninitializedHandle) |
| 827 db_handle = download_history_->GetNextFakeDbHandle(); | 836 db_handle = download_history_->GetNextFakeDbHandle(); |
| 828 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 837 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 829 } | 838 } |
| OLD | NEW |