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 "content/public/browser/download_url_parameters.h" |
17 #include "net/base/file_stream.h" | 17 #include "net/base/file_stream.h" |
18 | 18 |
19 using content::BrowserContext; | 19 using content::BrowserContext; |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using content::DownloadItem; | 21 using content::DownloadItem; |
22 using content::DownloadManager; | 22 using content::DownloadManager; |
23 using content::DownloadUrlParameters; | 23 using content::DownloadUrlParameters; |
24 using content::WebContents; | 24 using content::WebContents; |
25 | 25 |
26 DragDownloadFile::DragDownloadFile( | 26 DragDownloadFile::DragDownloadFile( |
27 const FilePath& file_name_or_path, | 27 const FilePath& file_name_or_path, |
28 linked_ptr<net::FileStream> file_stream, | 28 scoped_ptr<net::FileStream> file_stream, |
29 const GURL& url, | 29 const GURL& url, |
30 const content::Referrer& referrer, | 30 const content::Referrer& referrer, |
31 const std::string& referrer_encoding, | 31 const std::string& referrer_encoding, |
32 WebContents* web_contents) | 32 WebContents* web_contents) |
33 : file_stream_(file_stream), | 33 : file_stream_(file_stream.Pass()), |
34 url_(url), | 34 url_(url), |
35 referrer_(referrer), | 35 referrer_(referrer), |
36 referrer_encoding_(referrer_encoding), | 36 referrer_encoding_(referrer_encoding), |
37 web_contents_(web_contents), | 37 web_contents_(web_contents), |
38 drag_message_loop_(MessageLoop::current()), | 38 drag_message_loop_(MessageLoop::current()), |
39 is_started_(false), | 39 is_started_(false), |
40 is_successful_(false), | 40 is_successful_(false), |
41 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
42 is_running_nested_message_loop_(false), | 42 is_running_nested_message_loop_(false), |
43 #endif | 43 #endif |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 base::Bind(&DragDownloadFile::InitiateDownload, this)); | 126 base::Bind(&DragDownloadFile::InitiateDownload, this)); |
127 return; | 127 return; |
128 } | 128 } |
129 #endif | 129 #endif |
130 | 130 |
131 download_manager_ = BrowserContext::GetDownloadManager( | 131 download_manager_ = BrowserContext::GetDownloadManager( |
132 web_contents_->GetBrowserContext()); | 132 web_contents_->GetBrowserContext()); |
133 download_manager_observer_added_ = true; | 133 download_manager_observer_added_ = true; |
134 download_manager_->AddObserver(this); | 134 download_manager_->AddObserver(this); |
135 | 135 |
136 content::DownloadSaveInfo save_info; | 136 scoped_ptr<content::DownloadSaveInfo> save_info; |
137 save_info.file_path = file_path_; | 137 save_info->file_path = file_path_; |
138 save_info.file_stream = file_stream_; | 138 save_info->file_stream = file_stream_.Pass(); // Nulls file_stream_ |
139 | 139 |
140 download_stats::RecordDownloadSource( | 140 download_stats::RecordDownloadSource( |
141 download_stats::INITIATED_BY_DRAG_N_DROP); | 141 download_stats::INITIATED_BY_DRAG_N_DROP); |
142 scoped_ptr<DownloadUrlParameters> params( | 142 scoped_ptr<DownloadUrlParameters> params( |
143 DownloadUrlParameters::FromWebContents(web_contents_, url_, save_info)); | 143 DownloadUrlParameters::FromWebContents( |
| 144 web_contents_, url_, save_info.Pass())); |
144 params->set_referrer(referrer_); | 145 params->set_referrer(referrer_); |
145 params->set_referrer_encoding(referrer_encoding_); | 146 params->set_referrer_encoding(referrer_encoding_); |
146 download_manager_->DownloadUrl(params.Pass()); | 147 download_manager_->DownloadUrl(params.Pass()); |
147 } | 148 } |
148 | 149 |
149 void DragDownloadFile::DownloadCompleted(bool is_successful) { | 150 void DragDownloadFile::DownloadCompleted(bool is_successful) { |
150 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
151 // If not in drag-and-drop thread, defer the running to it. | 152 // If not in drag-and-drop thread, defer the running to it. |
152 if (drag_message_loop_ != MessageLoop::current()) { | 153 if (drag_message_loop_ != MessageLoop::current()) { |
153 drag_message_loop_->PostTask( | 154 drag_message_loop_->PostTask( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 247 |
247 void DragDownloadFile::QuitNestedMessageLoop() { | 248 void DragDownloadFile::QuitNestedMessageLoop() { |
248 AssertCurrentlyOnDragThread(); | 249 AssertCurrentlyOnDragThread(); |
249 | 250 |
250 if (is_running_nested_message_loop_) { | 251 if (is_running_nested_message_loop_) { |
251 is_running_nested_message_loop_ = false; | 252 is_running_nested_message_loop_ = false; |
252 MessageLoop::current()->Quit(); | 253 MessageLoop::current()->Quit(); |
253 } | 254 } |
254 } | 255 } |
255 #endif | 256 #endif |
OLD | NEW |