| 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 "content/browser/download/drag_download_file.h" | 5 #include "content/browser/download/drag_download_file.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "content/browser/download/download_stats.h" | 10 #include "content/browser/download/download_stats.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 15 #include "content/public/browser/download_save_info.h" | 15 #include "content/public/browser/download_save_info.h" |
| 16 #include "content/public/browser/download_url_parameters.h" |
| 16 #include "net/base/file_stream.h" | 17 #include "net/base/file_stream.h" |
| 17 | 18 |
| 18 using content::BrowserThread; | 19 using content::BrowserThread; |
| 19 using content::DownloadItem; | 20 using content::DownloadItem; |
| 20 using content::DownloadManager; | 21 using content::DownloadManager; |
| 22 using content::DownloadUrlParameters; |
| 21 using content::WebContents; | 23 using content::WebContents; |
| 22 | 24 |
| 23 DragDownloadFile::DragDownloadFile( | 25 DragDownloadFile::DragDownloadFile( |
| 24 const FilePath& file_name_or_path, | 26 const FilePath& file_name_or_path, |
| 25 linked_ptr<net::FileStream> file_stream, | 27 linked_ptr<net::FileStream> file_stream, |
| 26 const GURL& url, | 28 const GURL& url, |
| 27 const GURL& referrer, | 29 const GURL& referrer, |
| 28 const std::string& referrer_encoding, | 30 const std::string& referrer_encoding, |
| 29 WebContents* web_contents) | 31 WebContents* web_contents) |
| 30 : file_stream_(file_stream), | 32 : file_stream_(file_stream), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 download_manager_ = web_contents_->GetBrowserContext()->GetDownloadManager(); | 130 download_manager_ = web_contents_->GetBrowserContext()->GetDownloadManager(); |
| 129 download_manager_observer_added_ = true; | 131 download_manager_observer_added_ = true; |
| 130 download_manager_->AddObserver(this); | 132 download_manager_->AddObserver(this); |
| 131 | 133 |
| 132 content::DownloadSaveInfo save_info; | 134 content::DownloadSaveInfo save_info; |
| 133 save_info.file_path = file_path_; | 135 save_info.file_path = file_path_; |
| 134 save_info.file_stream = file_stream_; | 136 save_info.file_stream = file_stream_; |
| 135 | 137 |
| 136 download_stats::RecordDownloadSource( | 138 download_stats::RecordDownloadSource( |
| 137 download_stats::INITIATED_BY_DRAG_N_DROP); | 139 download_stats::INITIATED_BY_DRAG_N_DROP); |
| 138 download_manager_->DownloadUrl(url_, | 140 scoped_ptr<DownloadUrlParameters> params( |
| 139 referrer_, | 141 DownloadUrlParameters::FromWebContents(web_contents_, url_, save_info)); |
| 140 referrer_encoding_, | 142 params->set_referrer(referrer_); |
| 141 false, | 143 params->set_referrer_encoding(referrer_encoding_); |
| 142 -1, | 144 download_manager_->DownloadUrl(params.Pass()); |
| 143 save_info, | |
| 144 web_contents_, | |
| 145 DownloadManager::OnStartedCallback()); | |
| 146 } | 145 } |
| 147 | 146 |
| 148 void DragDownloadFile::DownloadCompleted(bool is_successful) { | 147 void DragDownloadFile::DownloadCompleted(bool is_successful) { |
| 149 #if defined(OS_WIN) | 148 #if defined(OS_WIN) |
| 150 // If not in drag-and-drop thread, defer the running to it. | 149 // If not in drag-and-drop thread, defer the running to it. |
| 151 if (drag_message_loop_ != MessageLoop::current()) { | 150 if (drag_message_loop_ != MessageLoop::current()) { |
| 152 drag_message_loop_->PostTask( | 151 drag_message_loop_->PostTask( |
| 153 FROM_HERE, | 152 FROM_HERE, |
| 154 base::Bind(&DragDownloadFile::DownloadCompleted, this, is_successful)); | 153 base::Bind(&DragDownloadFile::DownloadCompleted, this, is_successful)); |
| 155 return; | 154 return; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 231 |
| 233 void DragDownloadFile::QuitNestedMessageLoop() { | 232 void DragDownloadFile::QuitNestedMessageLoop() { |
| 234 AssertCurrentlyOnDragThread(); | 233 AssertCurrentlyOnDragThread(); |
| 235 | 234 |
| 236 if (is_running_nested_message_loop_) { | 235 if (is_running_nested_message_loop_) { |
| 237 is_running_nested_message_loop_ = false; | 236 is_running_nested_message_loop_ = false; |
| 238 MessageLoop::current()->Quit(); | 237 MessageLoop::current()->Quit(); |
| 239 } | 238 } |
| 240 } | 239 } |
| 241 #endif | 240 #endif |
| OLD | NEW |