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

Side by Side Diff: chrome/browser/download/download_request_manager.cc

Issue 353015: Last patch in removing MessageLoop* caching. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/download/download_request_manager.h" 5 #include "chrome/browser/download/download_request_manager.h"
6 6
7 #include "base/message_loop.h" 7 #include "chrome/browser/chrome_thread.h"
8 #include "base/thread.h"
9 #include "chrome/browser/download/download_request_infobar_delegate.h" 8 #include "chrome/browser/download/download_request_infobar_delegate.h"
10 #include "chrome/browser/tab_contents/navigation_controller.h" 9 #include "chrome/browser/tab_contents/navigation_controller.h"
11 #include "chrome/browser/tab_contents/navigation_entry.h" 10 #include "chrome/browser/tab_contents/navigation_entry.h"
12 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 11 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 12 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
16 15
17 // TabDownloadState ------------------------------------------------------------ 16 // TabDownloadState ------------------------------------------------------------
18 17
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 DownloadRequestManager::ALLOW_ALL_DOWNLOADS : 144 DownloadRequestManager::ALLOW_ALL_DOWNLOADS :
146 DownloadRequestManager::DOWNLOADS_NOT_ALLOWED; 145 DownloadRequestManager::DOWNLOADS_NOT_ALLOWED;
147 std::vector<DownloadRequestManager::Callback*> callbacks; 146 std::vector<DownloadRequestManager::Callback*> callbacks;
148 callbacks.swap(callbacks_); 147 callbacks.swap(callbacks_);
149 for (size_t i = 0; i < callbacks.size(); ++i) 148 for (size_t i = 0; i < callbacks.size(); ++i)
150 host_->ScheduleNotification(callbacks[i], allow); 149 host_->ScheduleNotification(callbacks[i], allow);
151 } 150 }
152 151
153 // DownloadRequestManager ------------------------------------------------------ 152 // DownloadRequestManager ------------------------------------------------------
154 153
155 DownloadRequestManager::DownloadRequestManager(MessageLoop* io_loop, 154 DownloadRequestManager::DownloadRequestManager() {
156 MessageLoop* ui_loop)
157 : io_loop_(io_loop),
158 ui_loop_(ui_loop) {
159 } 155 }
160 156
161 DownloadRequestManager::~DownloadRequestManager() { 157 DownloadRequestManager::~DownloadRequestManager() {
162 // All the tabs should have closed before us, which sends notification and 158 // All the tabs should have closed before us, which sends notification and
163 // removes from state_map_. As such, there should be no pending callbacks. 159 // removes from state_map_. As such, there should be no pending callbacks.
164 DCHECK(state_map_.empty()); 160 DCHECK(state_map_.empty());
165 } 161 }
166 162
167 DownloadRequestManager::DownloadStatus 163 DownloadRequestManager::DownloadStatus
168 DownloadRequestManager::GetDownloadStatus(TabContents* tab) { 164 DownloadRequestManager::GetDownloadStatus(TabContents* tab) {
169 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false); 165 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false);
170 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD; 166 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD;
171 } 167 }
172 168
173 void DownloadRequestManager::CanDownloadOnIOThread(int render_process_host_id, 169 void DownloadRequestManager::CanDownloadOnIOThread(int render_process_host_id,
174 int render_view_id, 170 int render_view_id,
175 Callback* callback) { 171 Callback* callback) {
176 // This is invoked on the IO thread. Schedule the task to run on the UI 172 // This is invoked on the IO thread. Schedule the task to run on the UI
177 // thread so that we can query UI state. 173 // thread so that we can query UI state.
178 DCHECK(!io_loop_ || io_loop_ == MessageLoop::current()); 174 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
179 ui_loop_->PostTask(FROM_HERE, 175 ChromeThread::PostTask(
176 ChromeThread::UI, FROM_HERE,
180 NewRunnableMethod(this, &DownloadRequestManager::CanDownload, 177 NewRunnableMethod(this, &DownloadRequestManager::CanDownload,
181 render_process_host_id, render_view_id, callback)); 178 render_process_host_id, render_view_id, callback));
182 } 179 }
183 180
184 void DownloadRequestManager::OnUserGesture(TabContents* tab) { 181 void DownloadRequestManager::OnUserGesture(TabContents* tab) {
185 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false); 182 TabDownloadState* state = GetDownloadState(&tab->controller(), NULL, false);
186 if (!state) 183 if (!state)
187 return; 184 return;
188 185
189 state->OnUserGesture(); 186 state->OnUserGesture();
(...skipping 18 matching lines...) Expand all
208 205
209 TabDownloadState* state = 206 TabDownloadState* state =
210 new TabDownloadState(this, controller, originating_controller); 207 new TabDownloadState(this, controller, originating_controller);
211 state_map_[controller] = state; 208 state_map_[controller] = state;
212 return state; 209 return state;
213 } 210 }
214 211
215 void DownloadRequestManager::CanDownload(int render_process_host_id, 212 void DownloadRequestManager::CanDownload(int render_process_host_id,
216 int render_view_id, 213 int render_view_id,
217 Callback* callback) { 214 Callback* callback) {
218 DCHECK(!ui_loop_ || MessageLoop::current() == ui_loop_); 215 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
219 216
220 TabContents* originating_tab = 217 TabContents* originating_tab =
221 tab_util::GetTabContentsByID(render_process_host_id, render_view_id); 218 tab_util::GetTabContentsByID(render_process_host_id, render_view_id);
222 if (!originating_tab) { 219 if (!originating_tab) {
223 // The tab was closed, don't allow the download. 220 // The tab was closed, don't allow the download.
224 ScheduleNotification(callback, false); 221 ScheduleNotification(callback, false);
225 return; 222 return;
226 } 223 }
227 CanDownloadImpl(originating_tab, callback); 224 CanDownloadImpl(originating_tab, callback);
228 } 225 }
(...skipping 29 matching lines...) Expand all
258 state->PromptUserForDownload(effective_tab, callback); 255 state->PromptUserForDownload(effective_tab, callback);
259 break; 256 break;
260 257
261 default: 258 default:
262 NOTREACHED(); 259 NOTREACHED();
263 } 260 }
264 } 261 }
265 262
266 void DownloadRequestManager::ScheduleNotification(Callback* callback, 263 void DownloadRequestManager::ScheduleNotification(Callback* callback,
267 bool allow) { 264 bool allow) {
268 if (io_loop_) { 265 ChromeThread::PostTask(
269 io_loop_->PostTask(FROM_HERE, 266 ChromeThread::IO, FROM_HERE,
270 NewRunnableMethod(this, &DownloadRequestManager::NotifyCallback, 267 NewRunnableMethod(
271 callback, allow)); 268 this, &DownloadRequestManager::NotifyCallback, callback, allow));
272 } else {
273 NotifyCallback(callback, allow);
274 }
275 } 269 }
276 270
277 void DownloadRequestManager::NotifyCallback(Callback* callback, bool allow) { 271 void DownloadRequestManager::NotifyCallback(Callback* callback, bool allow) {
278 // We better be on the IO thread now. 272 // We better be on the IO thread now.
279 DCHECK(!io_loop_ || MessageLoop::current() == io_loop_); 273 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
280 if (allow) 274 if (allow)
281 callback->ContinueDownload(); 275 callback->ContinueDownload();
282 else 276 else
283 callback->CancelDownload(); 277 callback->CancelDownload();
284 } 278 }
285 279
286 void DownloadRequestManager::Remove(TabDownloadState* state) { 280 void DownloadRequestManager::Remove(TabDownloadState* state) {
287 DCHECK(state_map_.find(state->controller()) != state_map_.end()); 281 DCHECK(state_map_.find(state->controller()) != state_map_.end());
288 state_map_.erase(state->controller()); 282 state_map_.erase(state->controller());
289 delete state; 283 delete state;
290 } 284 }
291 285
292 // static 286 // static
293 DownloadRequestManager::TestingDelegate* DownloadRequestManager::delegate_ = 287 DownloadRequestManager::TestingDelegate* DownloadRequestManager::delegate_ =
294 NULL; 288 NULL;
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_manager.h ('k') | chrome/browser/download/download_request_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698