Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Side by Side Diff: content/browser/download/drag_download_file.cc

Issue 8556001: Convert NewRunnableFunction/NewRunnableMethod calls to use base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_util.h" 8 #include "base/file_util.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "content/browser/browser_context.h" 10 #include "content/browser/browser_context.h"
10 #include "content/browser/download/download_item.h" 11 #include "content/browser/download/download_item.h"
11 #include "content/browser/download/download_stats.h" 12 #include "content/browser/download/download_stats.h"
12 #include "content/browser/tab_contents/tab_contents.h" 13 #include "content/browser/tab_contents/tab_contents.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "net/base/file_stream.h" 15 #include "net/base/file_stream.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 void DragDownloadFile::Stop() { 107 void DragDownloadFile::Stop() {
107 } 108 }
108 109
109 void DragDownloadFile::InitiateDownload() { 110 void DragDownloadFile::InitiateDownload() {
110 #if defined(OS_WIN) 111 #if defined(OS_WIN)
111 // DownloadManager could only be invoked from the UI thread. 112 // DownloadManager could only be invoked from the UI thread.
112 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 113 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
113 BrowserThread::PostTask( 114 BrowserThread::PostTask(
114 BrowserThread::UI, FROM_HERE, 115 BrowserThread::UI, FROM_HERE,
115 NewRunnableMethod(this, 116 base::Bind(&DragDownloadFile::InitiateDownload, this));
116 &DragDownloadFile::InitiateDownload));
117 return; 117 return;
118 } 118 }
119 #endif 119 #endif
120 120
121 download_manager_ = tab_contents_->browser_context()->GetDownloadManager(); 121 download_manager_ = tab_contents_->browser_context()->GetDownloadManager();
122 download_manager_observer_added_ = true; 122 download_manager_observer_added_ = true;
123 download_manager_->AddObserver(this); 123 download_manager_->AddObserver(this);
124 124
125 DownloadSaveInfo save_info; 125 DownloadSaveInfo save_info;
126 save_info.file_path = file_path_; 126 save_info.file_path = file_path_;
127 save_info.file_stream = file_stream_; 127 save_info.file_stream = file_stream_;
128 download_manager_->DownloadUrlToFile(url_, 128 download_manager_->DownloadUrlToFile(url_,
129 referrer_, 129 referrer_,
130 referrer_encoding_, 130 referrer_encoding_,
131 save_info, 131 save_info,
132 tab_contents_); 132 tab_contents_);
133 download_stats::RecordDownloadCount( 133 download_stats::RecordDownloadCount(
134 download_stats::INITIATED_BY_DRAG_N_DROP_COUNT); 134 download_stats::INITIATED_BY_DRAG_N_DROP_COUNT);
135 } 135 }
136 136
137 void DragDownloadFile::DownloadCompleted(bool is_successful) { 137 void DragDownloadFile::DownloadCompleted(bool is_successful) {
138 #if defined(OS_WIN) 138 #if defined(OS_WIN)
139 // If not in drag-and-drop thread, defer the running to it. 139 // If not in drag-and-drop thread, defer the running to it.
140 if (drag_message_loop_ != MessageLoop::current()) { 140 if (drag_message_loop_ != MessageLoop::current()) {
141 drag_message_loop_->PostTask( 141 drag_message_loop_->PostTask(
142 FROM_HERE, 142 FROM_HERE,
143 NewRunnableMethod(this, 143 base::Bind(&DragDownloadFile::DownloadCompleted, this, is_successful));
144 &DragDownloadFile::DownloadCompleted,
145 is_successful));
146 return; 144 return;
147 } 145 }
148 #endif 146 #endif
149 147
150 is_successful_ = is_successful; 148 is_successful_ = is_successful;
151 149
152 // Call the observer. 150 // Call the observer.
153 DCHECK(observer_); 151 DCHECK(observer_);
154 if (is_successful) 152 if (is_successful)
155 observer_->OnDownloadCompleted(file_path_); 153 observer_->OnDownloadCompleted(file_path_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 220
223 void DragDownloadFile::QuitNestedMessageLoop() { 221 void DragDownloadFile::QuitNestedMessageLoop() {
224 AssertCurrentlyOnDragThread(); 222 AssertCurrentlyOnDragThread();
225 223
226 if (is_running_nested_message_loop_) { 224 if (is_running_nested_message_loop_) {
227 is_running_nested_message_loop_ = false; 225 is_running_nested_message_loop_ = false;
228 MessageLoop::current()->Quit(); 226 MessageLoop::current()->Quit();
229 } 227 }
230 } 228 }
231 #endif 229 #endif
OLDNEW
« no previous file with comments | « content/browser/device_orientation/provider_impl.cc ('k') | content/browser/download/drag_download_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698