 Chromium Code Reviews
 Chromium Code Reviews Issue 2251643003:
  Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2251643003:
  Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/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/callback_helpers.h" | 10 #include "base/callback_helpers.h" | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 99 | 
| 100 void DeleteOnUIThread( | 100 void DeleteOnUIThread( | 
| 101 std::unique_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info) {} | 101 std::unique_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info) {} | 
| 102 | 102 | 
| 103 } // namespace | 103 } // namespace | 
| 104 | 104 | 
| 105 DownloadResourceHandler::DownloadResourceHandler(net::URLRequest* request) | 105 DownloadResourceHandler::DownloadResourceHandler(net::URLRequest* request) | 
| 106 : ResourceHandler(request), | 106 : ResourceHandler(request), | 
| 107 tab_info_(new DownloadTabInfo()), | 107 tab_info_(new DownloadTabInfo()), | 
| 108 core_(request, this) { | 108 core_(request, this) { | 
| 109 // Do UI thread initialization for tab_info_ asap after | |
| 110 // DownloadResourceHandler creation since the tab could be navigated | |
| 111 // before StartOnUIThread gets called. This is safe because deletion | |
| 112 // will occur via PostTask() as well, which will serialized behind this | |
| 113 // PostTask() | |
| 114 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); | |
| 115 BrowserThread::PostTask( | |
| 116 BrowserThread::UI, FROM_HERE, | |
| 117 base::Bind( | |
| 118 &InitializeDownloadTabInfoOnUIThread, | |
| 119 DownloadRequestHandle(AsWeakPtr(), | |
| 120 request_info->GetWebContentsGetterForRequest()), | |
| 121 tab_info_.get())); | |
| 122 } | 109 } | 
| 123 | 110 | 
| 124 DownloadResourceHandler::~DownloadResourceHandler() { | 111 DownloadResourceHandler::~DownloadResourceHandler() { | 
| 125 if (tab_info_) { | 112 if (tab_info_) { | 
| 126 BrowserThread::PostTask( | 113 BrowserThread::PostTask( | 
| 127 BrowserThread::UI, FROM_HERE, | 114 BrowserThread::UI, FROM_HERE, | 
| 128 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); | 115 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); | 
| 129 } | 116 } | 
| 130 } | 117 } | 
| 131 | 118 | 
| 132 bool DownloadResourceHandler::OnRequestRedirected( | 119 bool DownloadResourceHandler::OnRequestRedirected( | 
| 133 const net::RedirectInfo& redirect_info, | 120 const net::RedirectInfo& redirect_info, | 
| 134 ResourceResponse* response, | 121 ResourceResponse* response, | 
| 135 bool* defer) { | 122 bool* defer) { | 
| 136 return core_.OnRequestRedirected(); | 123 return core_.OnRequestRedirected(); | 
| 137 } | 124 } | 
| 138 | 125 | 
| 139 // Send the download creation information to the download thread. | 126 // Send the download creation information to the download thread. | 
| 140 bool DownloadResourceHandler::OnResponseStarted( | 127 bool DownloadResourceHandler::OnResponseStarted( | 
| 141 ResourceResponse* response, | 128 ResourceResponse* response, | 
| 142 bool* defer) { | 129 bool* defer) { | 
| 143 // The MIME type in ResourceResponse is the product of | 130 // The MIME type in ResourceResponse is the product of | 
| 144 // MimeTypeResourceHandler. | 131 // MimeTypeResourceHandler. | 
| 145 return core_.OnResponseStarted(response->head.mime_type); | 132 return core_.OnResponseStarted(response->head.mime_type); | 
| 146 } | 133 } | 
| 147 | 134 | 
| 148 bool DownloadResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 135 bool DownloadResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 
| 136 // Do UI thread initialization for tab_info_ asap after | |
| 
svaldez
2016/08/19 17:05:14
Comment should be updated.
 
ananta
2016/08/19 19:02:14
Done.
 | |
| 137 // DownloadResourceHandler creation since the tab could be navigated | |
| 138 // before StartOnUIThread gets called. This is safe because deletion | |
| 139 // will occur via PostTask() as well, which will serialized behind this | |
| 140 // PostTask() | |
| 141 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); | |
| 142 BrowserThread::PostTask( | |
| 143 BrowserThread::UI, FROM_HERE, | |
| 144 base::Bind( | |
| 145 &InitializeDownloadTabInfoOnUIThread, | |
| 146 DownloadRequestHandle(AsWeakPtr(), | |
| 147 request_info->GetWebContentsGetterForRequest()), | |
| 148 tab_info_.get())); | |
| 149 return true; | 149 return true; | 
| 150 } | 150 } | 
| 151 | 151 | 
| 152 // Create a new buffer, which will be handed to the download thread for file | 152 // Create a new buffer, which will be handed to the download thread for file | 
| 153 // writing and deletion. | 153 // writing and deletion. | 
| 154 bool DownloadResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 154 bool DownloadResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 
| 155 int* buf_size, | 155 int* buf_size, | 
| 156 int min_size) { | 156 int min_size) { | 
| 157 return core_.OnWillRead(buf, buf_size, min_size); | 157 return core_.OnWillRead(buf, buf_size, min_size); | 
| 158 } | 158 } | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 " }", | 242 " }", | 
| 243 request() ? | 243 request() ? | 
| 244 request()->url().spec().c_str() : | 244 request()->url().spec().c_str() : | 
| 245 "<NULL request>", | 245 "<NULL request>", | 
| 246 info->GetChildID(), | 246 info->GetChildID(), | 
| 247 info->GetRequestID(), | 247 info->GetRequestID(), | 
| 248 info->GetRouteID()); | 248 info->GetRouteID()); | 
| 249 } | 249 } | 
| 250 | 250 | 
| 251 } // namespace content | 251 } // namespace content | 
| OLD | NEW |