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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // thread depending on the platform, but DragDownloadFileUI strictly always runs | 30 // thread depending on the platform, but DragDownloadFileUI strictly always runs |
31 // on the UI thread. On platforms where DragDownloadFile runs on the UI thread, | 31 // on the UI thread. On platforms where DragDownloadFile runs on the UI thread, |
32 // none of the PostTasks are necessary, but it simplifies the code to do them | 32 // none of the PostTasks are necessary, but it simplifies the code to do them |
33 // anyway. | 33 // anyway. |
34 class DragDownloadFile::DragDownloadFileUI : public DownloadItem::Observer { | 34 class DragDownloadFile::DragDownloadFileUI : public DownloadItem::Observer { |
35 public: | 35 public: |
36 DragDownloadFileUI(const GURL& url, | 36 DragDownloadFileUI(const GURL& url, |
37 const Referrer& referrer, | 37 const Referrer& referrer, |
38 const std::string& referrer_encoding, | 38 const std::string& referrer_encoding, |
39 WebContents* web_contents, | 39 WebContents* web_contents, |
40 MessageLoop* on_completed_loop, | 40 base::MessageLoop* on_completed_loop, |
41 const OnCompleted& on_completed) | 41 const OnCompleted& on_completed) |
42 : on_completed_loop_(on_completed_loop), | 42 : on_completed_loop_(on_completed_loop), |
43 on_completed_(on_completed), | 43 on_completed_(on_completed), |
44 url_(url), | 44 url_(url), |
45 referrer_(referrer), | 45 referrer_(referrer), |
46 referrer_encoding_(referrer_encoding), | 46 referrer_encoding_(referrer_encoding), |
47 web_contents_(web_contents), | 47 web_contents_(web_contents), |
48 download_item_(NULL), | 48 download_item_(NULL), |
49 weak_ptr_factory_(this) { | 49 weak_ptr_factory_(this) { |
50 DCHECK(on_completed_loop_); | 50 DCHECK(on_completed_loop_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 DCHECK_EQ(download_item_, item); | 125 DCHECK_EQ(download_item_, item); |
126 if (!on_completed_.is_null()) { | 126 if (!on_completed_.is_null()) { |
127 on_completed_loop_->PostTask(FROM_HERE, base::Bind( | 127 on_completed_loop_->PostTask(FROM_HERE, base::Bind( |
128 on_completed_, download_item_->IsComplete())); | 128 on_completed_, download_item_->IsComplete())); |
129 on_completed_.Reset(); | 129 on_completed_.Reset(); |
130 } | 130 } |
131 download_item_->RemoveObserver(this); | 131 download_item_->RemoveObserver(this); |
132 download_item_ = NULL; | 132 download_item_ = NULL; |
133 } | 133 } |
134 | 134 |
135 MessageLoop* on_completed_loop_; | 135 base::MessageLoop* on_completed_loop_; |
136 OnCompleted on_completed_; | 136 OnCompleted on_completed_; |
137 GURL url_; | 137 GURL url_; |
138 Referrer referrer_; | 138 Referrer referrer_; |
139 std::string referrer_encoding_; | 139 std::string referrer_encoding_; |
140 WebContents* web_contents_; | 140 WebContents* web_contents_; |
141 DownloadItem* download_item_; | 141 DownloadItem* download_item_; |
142 | 142 |
143 // Only used in the callback from DownloadManager::DownloadUrl(). | 143 // Only used in the callback from DownloadManager::DownloadUrl(). |
144 base::WeakPtrFactory<DragDownloadFileUI> weak_ptr_factory_; | 144 base::WeakPtrFactory<DragDownloadFileUI> weak_ptr_factory_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileUI); | 146 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileUI); |
147 }; | 147 }; |
148 | 148 |
149 DragDownloadFile::DragDownloadFile(const base::FilePath& file_path, | 149 DragDownloadFile::DragDownloadFile(const base::FilePath& file_path, |
150 scoped_ptr<net::FileStream> file_stream, | 150 scoped_ptr<net::FileStream> file_stream, |
151 const GURL& url, | 151 const GURL& url, |
152 const Referrer& referrer, | 152 const Referrer& referrer, |
153 const std::string& referrer_encoding, | 153 const std::string& referrer_encoding, |
154 WebContents* web_contents) | 154 WebContents* web_contents) |
155 : file_path_(file_path), | 155 : file_path_(file_path), |
156 file_stream_(file_stream.Pass()), | 156 file_stream_(file_stream.Pass()), |
157 drag_message_loop_(MessageLoop::current()), | 157 drag_message_loop_(base::MessageLoop::current()), |
158 state_(INITIALIZED), | 158 state_(INITIALIZED), |
159 drag_ui_(NULL), | 159 drag_ui_(NULL), |
160 weak_ptr_factory_(this) { | 160 weak_ptr_factory_(this) { |
161 drag_ui_ = new DragDownloadFileUI( | 161 drag_ui_ = new DragDownloadFileUI( |
162 url, | 162 url, |
163 referrer, | 163 referrer, |
164 referrer_encoding, | 164 referrer_encoding, |
165 web_contents, | 165 web_contents, |
166 drag_message_loop_, | 166 drag_message_loop_, |
167 base::Bind(&DragDownloadFile::DownloadCompleted, | 167 base::Bind(&DragDownloadFile::DownloadCompleted, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 // Release the observer since we do not need it any more. | 225 // Release the observer since we do not need it any more. |
226 observer_ = NULL; | 226 observer_ = NULL; |
227 | 227 |
228 if (nested_loop_.running()) | 228 if (nested_loop_.running()) |
229 nested_loop_.Quit(); | 229 nested_loop_.Quit(); |
230 } | 230 } |
231 | 231 |
232 void DragDownloadFile::CheckThread() { | 232 void DragDownloadFile::CheckThread() { |
233 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
234 DCHECK(drag_message_loop_ == MessageLoop::current()); | 234 DCHECK(drag_message_loop_ == base::MessageLoop::current()); |
235 #else | 235 #else |
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
237 #endif | 237 #endif |
238 } | 238 } |
239 | 239 |
240 } // namespace content | 240 } // namespace content |
OLD | NEW |