| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/download/download_completion_blocker.h" | 19 #include "chrome/browser/download/download_completion_blocker.h" |
| 20 #include "chrome/browser/download/download_crx_util.h" | 20 #include "chrome/browser/download/download_crx_util.h" |
| 21 #include "chrome/browser/download/download_extensions.h" | 21 #include "chrome/browser/download/download_extensions.h" |
| 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_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
| 25 #include "chrome/browser/download/download_status_updater.h" | 25 #include "chrome/browser/download/download_status_updater.h" |
| 26 #include "chrome/browser/download/download_util.h" | 26 #include "chrome/browser/download/download_util.h" |
| 27 #include "chrome/browser/download/save_package_file_picker.h" | 27 #include "chrome/browser/download/save_package_file_picker.h" |
| 28 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 28 #include "chrome/browser/extensions/crx_installer.h" | 29 #include "chrome/browser/extensions/crx_installer.h" |
| 29 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 30 #include "chrome/browser/prefs/pref_member.h" | 31 #include "chrome/browser/prefs/pref_member.h" |
| 31 #include "chrome/browser/prefs/pref_service.h" | 32 #include "chrome/browser/prefs/pref_service.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 35 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/extensions/extension_switch_utils.h" | 37 #include "chrome/common/extensions/extension_switch_utils.h" |
| 37 #include "chrome/common/extensions/user_script.h" | 38 #include "chrome/common/extensions/user_script.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 download_prefs_.reset(); | 117 download_prefs_.reset(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 120 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| 120 AddRef(); // Will be balanced in Shutdown(). | 121 AddRef(); // Will be balanced in Shutdown(). |
| 121 download_manager_ = dm; | 122 download_manager_ = dm; |
| 122 download_history_.reset(new DownloadHistory(profile_)); | 123 download_history_.reset(new DownloadHistory(profile_)); |
| 123 download_history_->Load( | 124 download_history_->Load( |
| 124 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 125 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
| 125 base::Unretained(dm))); | 126 base::Unretained(dm))); |
| 127 extension_event_router_.reset(new ExtensionDownloadsEventRouter(profile_)); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void ChromeDownloadManagerDelegate::Shutdown() { | 130 void ChromeDownloadManagerDelegate::Shutdown() { |
| 129 Release(); // Balance the AddRef in SetDownloadManager. | 131 Release(); // Balance the AddRef in SetDownloadManager. |
| 130 } | 132 } |
| 131 | 133 |
| 132 DownloadId ChromeDownloadManagerDelegate::GetNextId() { | 134 DownloadId ChromeDownloadManagerDelegate::GetNextId() { |
| 133 if (!profile_->IsOffTheRecord()) | 135 if (!profile_->IsOffTheRecord()) |
| 134 return DownloadId(this, next_download_id_++); | 136 return DownloadId(this, next_download_id_++); |
| 135 | 137 |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 int32 download_id, int64 db_handle) { | 846 int32 download_id, int64 db_handle) { |
| 845 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 847 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 846 // call this function with an invalid |db_handle|. For instance, this can | 848 // call this function with an invalid |db_handle|. For instance, this can |
| 847 // happen when the history database is offline. We cannot have multiple | 849 // happen when the history database is offline. We cannot have multiple |
| 848 // DownloadItems with the same invalid db_handle, so we need to assign a | 850 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 849 // unique |db_handle| here. | 851 // unique |db_handle| here. |
| 850 if (db_handle == DownloadItem::kUninitializedHandle) | 852 if (db_handle == DownloadItem::kUninitializedHandle) |
| 851 db_handle = download_history_->GetNextFakeDbHandle(); | 853 db_handle = download_history_->GetNextFakeDbHandle(); |
| 852 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 854 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 853 } | 855 } |
| OLD | NEW |