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

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

Issue 1418663010: Adding WebContent-free Download (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing Mock for GetBrowserContext. Created 5 years 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
OLDNEW
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/download_resource_handler.h" 5 #include "content/browser/download/download_resource_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return; 55 return;
56 started_cb.Run(item, interrupt_reason); 56 started_cb.Run(item, interrupt_reason);
57 } 57 }
58 58
59 // Static function in order to prevent any accidental accesses to 59 // Static function in order to prevent any accidental accesses to
60 // DownloadResourceHandler members from the UI thread. 60 // DownloadResourceHandler members from the UI thread.
61 static void StartOnUIThread( 61 static void StartOnUIThread(
62 scoped_ptr<DownloadCreateInfo> info, 62 scoped_ptr<DownloadCreateInfo> info,
63 scoped_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info, 63 scoped_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info,
64 scoped_ptr<ByteStreamReader> stream, 64 scoped_ptr<ByteStreamReader> stream,
65 DownloadManager* download_manager,
65 const DownloadUrlParameters::OnStartedCallback& started_cb) { 66 const DownloadUrlParameters::OnStartedCallback& started_cb) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI); 67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
67 68
68 DownloadManager* download_manager = info->request_handle.GetDownloadManager(); 69 if (!download_manager)
70 download_manager = info->request_handle.GetDownloadManager();
69 if (!download_manager) { 71 if (!download_manager) {
70 // NULL in unittests or if the page closed right after starting the 72 // NULL in unittests or if the page closed right after starting the
71 // download. 73 // download.
72 if (!started_cb.is_null()) 74 if (!started_cb.is_null())
73 started_cb.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); 75 started_cb.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED);
74 76
75 // |stream| gets deleted on non-FILE thread, but it's ok since 77 // |stream| gets deleted on non-FILE thread, but it's ok since
76 // we're not using stream_writer_ yet. 78 // we're not using stream_writer_ yet.
77 79
78 return; 80 return;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Blink verifies that the requester of this download is allowed to set a 243 // Blink verifies that the requester of this download is allowed to set a
242 // suggested name for the security origin of the downlaod URL. However, this 244 // suggested name for the security origin of the downlaod URL. However, this
243 // assumption doesn't hold if there were cross origin redirects. Therefore, 245 // assumption doesn't hold if there were cross origin redirects. Therefore,
244 // clear the suggested_name for such requests. 246 // clear the suggested_name for such requests.
245 if (info->url_chain.size() > 1 && 247 if (info->url_chain.size() > 1 &&
246 info->url_chain.front().GetOrigin() != info->url_chain.back().GetOrigin()) 248 info->url_chain.front().GetOrigin() != info->url_chain.back().GetOrigin())
247 info->save_info->suggested_name.clear(); 249 info->save_info->suggested_name.clear();
248 250
249 BrowserThread::PostTask( 251 BrowserThread::PostTask(
250 BrowserThread::UI, FROM_HERE, 252 BrowserThread::UI, FROM_HERE,
251 base::Bind(&StartOnUIThread, 253 base::Bind(&StartOnUIThread, base::Passed(&info),
252 base::Passed(&info), 254 base::Passed(&tab_info_), base::Passed(&stream_reader),
253 base::Passed(&tab_info_), 255 download_manager_.get(),
asanka 2015/11/25 15:53:57 Can't de-reference a WeakPtr on a thread other tha
svaldez 2015/11/25 17:53:28 Yeah, found that out when testing. SHould be fixed
254 base::Passed(&stream_reader),
255 // Pass to StartOnUIThread so that variable 256 // Pass to StartOnUIThread so that variable
256 // access is always on IO thread but function 257 // access is always on IO thread but function
257 // is called on UI thread. 258 // is called on UI thread.
258 started_cb_)); 259 started_cb_));
259 // Guaranteed to be called in StartOnUIThread 260 // Guaranteed to be called in StartOnUIThread
260 started_cb_.Reset(); 261 started_cb_.Reset();
261 262
262 return true; 263 return true;
263 } 264 }
264 265
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 BrowserThread::PostTask( 543 BrowserThread::PostTask(
543 BrowserThread::UI, FROM_HERE, 544 BrowserThread::UI, FROM_HERE,
544 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); 545 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_)));
545 } 546 }
546 547
547 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", 548 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration",
548 base::TimeTicks::Now() - download_start_time_); 549 base::TimeTicks::Now() - download_start_time_);
549 } 550 }
550 551
551 } // namespace content 552 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698