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