Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 #include "chrome/browser/download/download_file_picker.h" 22 #include "chrome/browser/download/download_file_picker.h"
23 #include "chrome/browser/download/download_history.h" 23 #include "chrome/browser/download/download_history.h"
24 #include "chrome/browser/download/download_path_reservation_tracker.h" 24 #include "chrome/browser/download/download_path_reservation_tracker.h"
25 #include "chrome/browser/download/download_prefs.h" 25 #include "chrome/browser/download/download_prefs.h"
26 #include "chrome/browser/download/download_status_updater.h" 26 #include "chrome/browser/download/download_status_updater.h"
27 #include "chrome/browser/download/download_util.h" 27 #include "chrome/browser/download/download_util.h"
28 #include "chrome/browser/download/save_package_file_picker.h" 28 #include "chrome/browser/download/save_package_file_picker.h"
29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
30 #include "chrome/browser/extensions/crx_installer.h" 30 #include "chrome/browser/extensions/crx_installer.h"
31 #include "chrome/browser/extensions/extension_service.h" 31 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/history/history_service_factory.h"
32 #include "chrome/browser/prefs/pref_service.h" 33 #include "chrome/browser/prefs/pref_service.h"
33 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
35 #include "chrome/browser/ui/browser_tabstrip.h" 36 #include "chrome/browser/ui/browser_tabstrip.h"
36 #include "chrome/common/chrome_notification_types.h" 37 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/extensions/extension_switch_utils.h" 38 #include "chrome/common/extensions/extension_switch_utils.h"
38 #include "chrome/common/extensions/user_script.h" 39 #include "chrome/common/extensions/user_script.h"
39 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "content/public/browser/download_item.h" 41 #include "content/public/browser/download_item.h"
41 #include "content/public/browser/download_manager.h" 42 #include "content/public/browser/download_manager.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 : profile_(profile), 125 : profile_(profile),
125 next_download_id_(0), 126 next_download_id_(0),
126 download_prefs_(new DownloadPrefs(profile)) { 127 download_prefs_(new DownloadPrefs(profile)) {
127 } 128 }
128 129
129 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { 130 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
130 } 131 }
131 132
132 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { 133 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
133 download_manager_ = dm; 134 download_manager_ = dm;
134 download_history_.reset(new DownloadHistory(profile_));
135 if (!profile_->IsOffTheRecord()) {
136 // DownloadManager should not be RefCountedThreadSafe.
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 }
146 #if !defined(OS_ANDROID) 135 #if !defined(OS_ANDROID)
147 extension_event_router_.reset(new ExtensionDownloadsEventRouter( 136 extension_event_router_.reset(new ExtensionDownloadsEventRouter(
148 profile_, download_manager_)); 137 profile_, download_manager_));
149 #endif 138 #endif
139
140 if (!profile_->IsOffTheRecord()) {
141 HistoryService* hs = HistoryServiceFactory::GetForProfile(
142 profile_, Profile::EXPLICIT_ACCESS);
143 if (hs) {
144 download_history_.reset(new DownloadHistory(
145 download_manager_, scoped_ptr<HistoryServiceDownloadAdapter>(
146 new HistoryServiceDownloadAdapter(hs))));
147 }
148 }
150 } 149 }
151 150
152 void ChromeDownloadManagerDelegate::Shutdown() { 151 void ChromeDownloadManagerDelegate::Shutdown() {
153 download_history_.reset(); 152 download_history_.reset();
154 download_prefs_.reset(); 153 download_prefs_.reset();
155 #if !defined(OS_ANDROID) 154 #if !defined(OS_ANDROID)
156 extension_event_router_.reset(); 155 extension_event_router_.reset();
157 #endif 156 #endif
158 } 157 }
159 158
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 443
445 bool ChromeDownloadManagerDelegate::GenerateFileHash() { 444 bool ChromeDownloadManagerDelegate::GenerateFileHash() {
446 #if defined(ENABLE_SAFE_BROWSING) 445 #if defined(ENABLE_SAFE_BROWSING)
447 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && 446 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
448 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); 447 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded();
449 #else 448 #else
450 return false; 449 return false;
451 #endif 450 #endif
452 } 451 }
453 452
454 void ChromeDownloadManagerDelegate::AddItemToPersistentStore(
455 DownloadItem* item) {
456 if (profile_->IsOffTheRecord()) {
457 OnItemAddedToPersistentStore(
458 item->GetId(), download_history_->GetNextFakeDbHandle());
459 return;
460 }
461 download_history_->AddEntry(item,
462 base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore,
463 this));
464 }
465
466 void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore(
467 DownloadItem* item) {
468 download_history_->UpdateEntry(item);
469 }
470
471 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore(
472 DownloadItem* item,
473 const FilePath& new_path) {
474 download_history_->UpdateDownloadPath(item, new_path);
475 }
476
477 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore(
478 DownloadItem* item) {
479 download_history_->RemoveEntry(item);
480 }
481
482 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween(
483 base::Time remove_begin,
484 base::Time remove_end) {
485 if (profile_->IsOffTheRecord())
486 return;
487 download_history_->RemoveEntriesBetween(remove_begin, remove_end);
488 }
489
490 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, 453 void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents,
491 FilePath* website_save_dir, 454 FilePath* website_save_dir,
492 FilePath* download_save_dir, 455 FilePath* download_save_dir,
493 bool* skip_dir_check) { 456 bool* skip_dir_check) {
494 Profile* profile = 457 Profile* profile =
495 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 458 Profile::FromBrowserContext(web_contents->GetBrowserContext());
496 PrefService* prefs = profile->GetPrefs(); 459 PrefService* prefs = profile->GetPrefs();
497 460
498 // Check whether the preference has the preferred directory for saving file. 461 // Check whether the preference has the preferred directory for saving file.
499 // If not, initialize it with default directory. 462 // If not, initialize it with default directory.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 download_manager_->GetActiveDownloadItem(download_id); 567 download_manager_->GetActiveDownloadItem(download_id);
605 if (!download) 568 if (!download)
606 return; 569 return;
607 570
608 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) 571 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false)
609 << " verdict = " << result; 572 << " verdict = " << result;
610 content::DownloadDangerType danger_type = download->GetDangerType(); 573 content::DownloadDangerType danger_type = download->GetDangerType();
611 if (result != DownloadProtectionService::SAFE) 574 if (result != DownloadProtectionService::SAFE)
612 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; 575 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL;
613 576
614 download_history_->CheckVisitedReferrerBefore( 577 if (download_history_.get()) {
615 download_id, download->GetReferrerUrl(), 578 download_history_->CheckVisitedReferrerBefore(
616 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, 579 download_id, download->GetReferrerUrl(), base::Bind(
617 this, download_id, callback, danger_type)); 580 &ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone,
581 this, download_id, callback, danger_type));
582 } else {
583 CheckVisitedReferrerBeforeDone(download_id, callback, danger_type, false);
584 }
618 } 585 }
619 586
620 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( 587 void ChromeDownloadManagerDelegate::CheckClientDownloadDone(
621 int32 download_id, 588 int32 download_id,
622 DownloadProtectionService::DownloadCheckResult result) { 589 DownloadProtectionService::DownloadCheckResult result) {
623 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); 590 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id);
624 if (!item) 591 if (!item)
625 return; 592 return;
626 593
627 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) 594 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a 811 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
845 // directory to persist. Or perhaps, if the GData path 812 // directory to persist. Or perhaps, if the GData path
846 // substitution logic is moved here, then we would have a 813 // substitution logic is moved here, then we would have a
847 // persistable path after the DownloadFilePicker is done. 814 // persistable path after the DownloadFilePicker is done.
848 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && 815 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT &&
849 !download->IsTemporary()) 816 !download->IsTemporary())
850 last_download_path_ = target_path.DirName(); 817 last_download_path_ = target_path.DirName();
851 } 818 }
852 callback.Run(target_path, disposition, danger_type, intermediate_path); 819 callback.Run(target_path, disposition, danger_type, intermediate_path);
853 } 820 }
854
855 void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore(
856 int32 download_id, int64 db_handle) {
857 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
858 // call this function with an invalid |db_handle|. For instance, this can
859 // happen when the history database is offline. We cannot have multiple
860 // DownloadItems with the same invalid db_handle, so we need to assign a
861 // unique |db_handle| here.
862 if (db_handle == DownloadItem::kUninitializedHandle)
863 db_handle = download_history_->GetNextFakeDbHandle();
864 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
865 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698