OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/download/download_safe_browsing_client.h" | 27 #include "chrome/browser/download/download_safe_browsing_client.h" |
28 #include "chrome/browser/download/download_status_updater.h" | 28 #include "chrome/browser/download/download_status_updater.h" |
29 #include "chrome/browser/download/download_util.h" | 29 #include "chrome/browser/download/download_util.h" |
30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/history/download_history_info.h" | 31 #include "chrome/browser/history/download_history_info.h" |
32 #include "chrome/browser/platform_util.h" | 32 #include "chrome/browser/platform_util.h" |
33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/tab_contents/tab_util.h" | 34 #include "chrome/browser/tab_contents/tab_util.h" |
35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
36 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
37 #include "chrome/browser/ui/download/download_tab_helper.h" | |
38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
39 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
40 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
41 #include "content/browser/browser_thread.h" | 39 #include "content/browser/browser_thread.h" |
42 #include "content/browser/renderer_host/render_process_host.h" | 40 #include "content/browser/renderer_host/render_process_host.h" |
43 #include "content/browser/renderer_host/render_view_host.h" | 41 #include "content/browser/renderer_host/render_view_host.h" |
44 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 42 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
45 #include "content/browser/tab_contents/tab_contents.h" | 43 #include "content/browser/tab_contents/tab_contents.h" |
46 #include "content/common/content_notification_types.h" | 44 #include "content/common/content_notification_types.h" |
47 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
48 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 download_history_->UpdateEntry(download); | 1241 download_history_->UpdateEntry(download); |
1244 download->UpdateObservers(); | 1242 download->UpdateObservers(); |
1245 } | 1243 } |
1246 } | 1244 } |
1247 | 1245 |
1248 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) { | 1246 void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) { |
1249 // The 'contents' may no longer exist if the user closed the tab before we | 1247 // The 'contents' may no longer exist if the user closed the tab before we |
1250 // get this start completion event. If it does, tell the origin TabContents | 1248 // get this start completion event. If it does, tell the origin TabContents |
1251 // to display its download shelf. | 1249 // to display its download shelf. |
1252 DownloadRequestHandle request_handle = download->request_handle(); | 1250 DownloadRequestHandle request_handle = download->request_handle(); |
1253 TabContents* contents = request_handle.GetTabContents(); | 1251 TabContents* content = request_handle.GetTabContents(); |
1254 TabContentsWrapper* wrapper = NULL; | |
1255 if (contents) | |
1256 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(contents); | |
1257 | |
1258 // If the contents no longer exists, we start the download in the last active | 1252 // If the contents no longer exists, we start the download in the last active |
1259 // browser. This is not ideal but better than fully hiding the download from | 1253 // browser. This is not ideal but better than fully hiding the download from |
1260 // the user. | 1254 // the user. |
1261 if (!wrapper) { | 1255 if (!content) { |
1262 Browser* last_active = BrowserList::GetLastActiveWithProfile(profile_); | 1256 Browser* last_active = BrowserList::GetLastActiveWithProfile(profile_); |
1263 if (last_active) | 1257 if (last_active) |
1264 wrapper = last_active->GetSelectedTabContentsWrapper(); | 1258 content = last_active->GetSelectedTabContents(); |
1265 } | 1259 } |
1266 | 1260 |
1267 if (!wrapper) | 1261 if (!content) |
1268 return; | 1262 return; |
1269 | 1263 |
1270 wrapper->download_tab_helper()->OnStartDownload(download); | 1264 content->OnStartDownload(download); |
1271 } | 1265 } |
1272 | 1266 |
1273 // Clears the last download path, used to initialize "save as" dialogs. | 1267 // Clears the last download path, used to initialize "save as" dialogs. |
1274 void DownloadManager::ClearLastDownloadPath() { | 1268 void DownloadManager::ClearLastDownloadPath() { |
1275 last_download_path_ = FilePath(); | 1269 last_download_path_ = FilePath(); |
1276 } | 1270 } |
1277 | 1271 |
1278 void DownloadManager::NotifyModelChanged() { | 1272 void DownloadManager::NotifyModelChanged() { |
1279 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); | 1273 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); |
1280 } | 1274 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 observed_download_manager_->RemoveObserver(this); | 1358 observed_download_manager_->RemoveObserver(this); |
1365 } | 1359 } |
1366 | 1360 |
1367 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1361 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1368 observing_download_manager_->NotifyModelChanged(); | 1362 observing_download_manager_->NotifyModelChanged(); |
1369 } | 1363 } |
1370 | 1364 |
1371 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1365 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1372 observed_download_manager_ = NULL; | 1366 observed_download_manager_ = NULL; |
1373 } | 1367 } |
OLD | NEW |