| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_file.h" | 5 #include "chrome/browser/download/download_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/download/download_manager.h" | 13 #include "chrome/browser/download/download_manager.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/browser/tab_contents/web_contents.h" | 17 #include "chrome/browser/tab_contents/web_contents.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/platform_util.h" |
| 19 #include "chrome/common/stl_util-inl.h" | 20 #include "chrome/common/stl_util-inl.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 23 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 24 | 25 |
| 25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 26 #include "chrome/common/win_util.h" | 27 #include "chrome/common/win_util.h" |
| 27 #include "chrome/common/win_safe_util.h" | 28 #include "chrome/common/win_safe_util.h" |
| 28 #endif | 29 #endif |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 DCHECK(MessageLoop::current() == io_loop_); | 511 DCHECK(MessageLoop::current() == io_loop_); |
| 511 resource_dispatcher_host_->BeginDownload(url, | 512 resource_dispatcher_host_->BeginDownload(url, |
| 512 referrer, | 513 referrer, |
| 513 render_process_host_id, | 514 render_process_host_id, |
| 514 render_view_id, | 515 render_view_id, |
| 515 request_context); | 516 request_context); |
| 516 } | 517 } |
| 517 | 518 |
| 518 // Actions from the UI thread and run on the download thread | 519 // Actions from the UI thread and run on the download thread |
| 519 | 520 |
| 520 // Open a download, or show it in a Windows Explorer window. We run on this | 521 // Open a download, or show it in a file explorer window. We run on this |
| 521 // thread to avoid blocking the UI with (potentially) slow Shell operations. | 522 // thread to avoid blocking the UI with (potentially) slow Shell operations. |
| 522 // TODO(paulg): File 'stat' operations. | 523 // TODO(paulg): File 'stat' operations. |
| 523 void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { | 524 void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { |
| 524 #if defined(OS_WIN) | |
| 525 DCHECK(MessageLoop::current() == file_loop_); | 525 DCHECK(MessageLoop::current() == file_loop_); |
| 526 win_util::ShowItemInFolder(full_path.value()); | 526 platform_util::ShowItemInFolder(full_path); |
| 527 #else | |
| 528 // TODO(port) implement me. | |
| 529 NOTREACHED(); | |
| 530 #endif | |
| 531 } | 527 } |
| 532 | 528 |
| 533 // Launches the selected download using ShellExecute 'open' verb. If there is | 529 // Launches the selected download using ShellExecute 'open' verb. If there is |
| 534 // a valid parent window, the 'safer' version will be used which can | 530 // a valid parent window, the 'safer' version will be used which can |
| 535 // display a modal dialog asking for user consent on dangerous files. | 531 // display a modal dialog asking for user consent on dangerous files. |
| 536 void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, | 532 void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, |
| 537 const GURL& url, | 533 const GURL& url, |
| 538 gfx::NativeView parent_window) { | 534 gfx::NativeView parent_window) { |
| 539 #if defined(OS_WIN) | 535 #if defined(OS_WIN) |
| 540 DCHECK(MessageLoop::current() == file_loop_); | 536 DCHECK(MessageLoop::current() == file_loop_); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 588 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 593 this, &DownloadFileManager::StopUpdateTimer)); | 589 this, &DownloadFileManager::StopUpdateTimer)); |
| 594 } | 590 } |
| 595 | 591 |
| 596 // static | 592 // static |
| 597 void DownloadFileManager::DeleteFile(const FilePath& path) { | 593 void DownloadFileManager::DeleteFile(const FilePath& path) { |
| 598 // Make sure we only delete files. | 594 // Make sure we only delete files. |
| 599 if (!file_util::DirectoryExists(path)) | 595 if (!file_util::DirectoryExists(path)) |
| 600 file_util::Delete(path, false); | 596 file_util::Delete(path, false); |
| 601 } | 597 } |
| OLD | NEW |