| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "chrome/browser/ui/browser.h" | 50 #include "chrome/browser/ui/browser.h" |
| 51 #include "chrome/browser/ui/browser_finder.h" | 51 #include "chrome/browser/ui/browser_finder.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 55 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 55 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
| 56 #include "chrome/browser/download/download_file_picker_chromeos.h" | 56 #include "chrome/browser/download/download_file_picker_chromeos.h" |
| 57 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 57 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 using content::BrowserContext; |
| 60 using content::BrowserThread; | 61 using content::BrowserThread; |
| 61 using content::DownloadId; | 62 using content::DownloadId; |
| 62 using content::DownloadItem; | 63 using content::DownloadItem; |
| 63 using content::DownloadManager; | 64 using content::DownloadManager; |
| 64 using content::WebContents; | 65 using content::WebContents; |
| 65 using safe_browsing::DownloadProtectionService; | 66 using safe_browsing::DownloadProtectionService; |
| 66 | 67 |
| 67 namespace { | 68 namespace { |
| 68 | 69 |
| 69 // String pointer used for identifying safebrowing data associated with | 70 // String pointer used for identifying safebrowing data associated with |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 103 |
| 103 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 104 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| 104 : profile_(profile), | 105 : profile_(profile), |
| 105 next_download_id_(0), | 106 next_download_id_(0), |
| 106 download_prefs_(new DownloadPrefs(profile->GetPrefs())) { | 107 download_prefs_(new DownloadPrefs(profile->GetPrefs())) { |
| 107 } | 108 } |
| 108 | 109 |
| 109 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 110 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| 110 } | 111 } |
| 111 | 112 |
| 113 void ChromeDownloadManagerDelegate::ProfileShutdown() { |
| 114 download_history_.reset(); |
| 115 download_prefs_.reset(); |
| 116 } |
| 117 |
| 112 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 118 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| 119 AddRef(); // Will be balanced in Shutdown(). |
| 113 download_manager_ = dm; | 120 download_manager_ = dm; |
| 114 download_history_.reset(new DownloadHistory(profile_)); | 121 download_history_.reset(new DownloadHistory(profile_)); |
| 115 download_history_->Load( | 122 download_history_->Load( |
| 116 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 123 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
| 117 base::Unretained(dm))); | 124 base::Unretained(dm))); |
| 118 } | 125 } |
| 119 | 126 |
| 120 void ChromeDownloadManagerDelegate::Shutdown() { | 127 void ChromeDownloadManagerDelegate::Shutdown() { |
| 121 download_history_.reset(); | 128 Release(); // Balance the AddRef in SetDownloadManager. |
| 122 download_prefs_.reset(); | |
| 123 } | 129 } |
| 124 | 130 |
| 125 DownloadId ChromeDownloadManagerDelegate::GetNextId() { | 131 DownloadId ChromeDownloadManagerDelegate::GetNextId() { |
| 126 if (!profile_->IsOffTheRecord()) | 132 if (!profile_->IsOffTheRecord()) |
| 127 return DownloadId(this, next_download_id_++); | 133 return DownloadId(this, next_download_id_++); |
| 128 | 134 |
| 129 return profile_->GetOriginalProfile()->GetDownloadManager()->delegate()-> | 135 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> |
| 130 GetNextId(); | 136 delegate()->GetNextId(); |
| 131 } | 137 } |
| 132 | 138 |
| 133 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { | 139 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { |
| 134 // We create a download item and store it in our download map, and inform the | 140 // We create a download item and store it in our download map, and inform the |
| 135 // history system of a new download. Since this method can be called while the | 141 // history system of a new download. Since this method can be called while the |
| 136 // history service thread is still reading the persistent state, we do not | 142 // history service thread is still reading the persistent state, we do not |
| 137 // insert the new DownloadItem into 'history_downloads_' or inform our | 143 // insert the new DownloadItem into 'history_downloads_' or inform our |
| 138 // observers at this point. OnCreateDownloadEntryComplete() handles that | 144 // observers at this point. OnCreateDownloadEntryComplete() handles that |
| 139 // finalization of the the download creation as a callback from the history | 145 // finalization of the the download creation as a callback from the history |
| 140 // thread. | 146 // thread. |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 int32 download_id, int64 db_handle) { | 809 int32 download_id, int64 db_handle) { |
| 804 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 810 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 805 // call this function with an invalid |db_handle|. For instance, this can | 811 // call this function with an invalid |db_handle|. For instance, this can |
| 806 // happen when the history database is offline. We cannot have multiple | 812 // happen when the history database is offline. We cannot have multiple |
| 807 // DownloadItems with the same invalid db_handle, so we need to assign a | 813 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 808 // unique |db_handle| here. | 814 // unique |db_handle| here. |
| 809 if (db_handle == DownloadItem::kUninitializedHandle) | 815 if (db_handle == DownloadItem::kUninitializedHandle) |
| 810 db_handle = download_history_->GetNextFakeDbHandle(); | 816 db_handle = download_history_->GetNextFakeDbHandle(); |
| 811 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 817 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 812 } | 818 } |
| OLD | NEW |