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/android/download_controller_android_impl.h" | 5 #include "content/browser/android/download_controller_android_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 render_view_host->GetRoutingID())); | 103 render_view_host->GetRoutingID())); |
104 } | 104 } |
105 | 105 |
106 void DownloadControllerAndroidImpl::PrepareDownloadInfo( | 106 void DownloadControllerAndroidImpl::PrepareDownloadInfo( |
107 const GlobalRequestID& global_id, | 107 const GlobalRequestID& global_id, |
108 int render_process_id, int render_view_id) { | 108 int render_process_id, int render_view_id) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
110 | 110 |
111 net::URLRequest* request = | 111 net::URLRequest* request = |
112 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 112 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
113 DCHECK(request) << "Request to download not found."; | 113 if (!request) { |
| 114 LOG(ERROR) << "Request to download not found."; |
| 115 return; |
| 116 } |
114 | 117 |
115 DownloadInfoAndroid info_android(request); | 118 DownloadInfoAndroid info_android(request); |
116 | 119 |
117 net::CookieStore* cookie_store = request->context()->cookie_store(); | 120 net::CookieStore* cookie_store = request->context()->cookie_store(); |
118 if (cookie_store) { | 121 if (cookie_store) { |
119 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); | 122 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
120 if (cookie_monster) { | 123 if (cookie_monster) { |
121 cookie_monster->GetAllCookiesForURLAsync( | 124 cookie_monster->GetAllCookiesForURLAsync( |
122 request->url(), | 125 request->url(), |
123 base::Bind(&DownloadControllerAndroidImpl::CheckPolicyAndLoadCookies, | 126 base::Bind(&DownloadControllerAndroidImpl::CheckPolicyAndLoadCookies, |
124 base::Unretained(this), info_android, render_process_id, | 127 base::Unretained(this), info_android, render_process_id, |
125 render_view_id, global_id)); | 128 render_view_id, global_id)); |
126 } else { | 129 } else { |
127 DoLoadCookies( | 130 DoLoadCookies( |
128 info_android, render_process_id, render_view_id, global_id); | 131 info_android, render_process_id, render_view_id, global_id); |
129 } | 132 } |
130 } else { | 133 } else { |
131 // Can't get any cookies, start android download. | 134 // Can't get any cookies, start android download. |
132 StartAndroidDownload(info_android, render_process_id, render_view_id); | 135 StartAndroidDownload(info_android, render_process_id, render_view_id); |
133 } | 136 } |
134 } | 137 } |
135 | 138 |
136 void DownloadControllerAndroidImpl::CheckPolicyAndLoadCookies( | 139 void DownloadControllerAndroidImpl::CheckPolicyAndLoadCookies( |
137 const DownloadInfoAndroid& info, int render_process_id, | 140 const DownloadInfoAndroid& info, int render_process_id, |
138 int render_view_id, const GlobalRequestID& global_id, | 141 int render_view_id, const GlobalRequestID& global_id, |
139 const net::CookieList& cookie_list) { | 142 const net::CookieList& cookie_list) { |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 144 |
140 net::URLRequest* request = | 145 net::URLRequest* request = |
141 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 146 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
142 DCHECK(request) << "Request to download not found."; | 147 if (!request) { |
| 148 LOG(ERROR) << "Request to download not found."; |
| 149 return; |
| 150 } |
143 | 151 |
144 if (request->context()->network_delegate()->CanGetCookies( | 152 if (request->context()->network_delegate()->CanGetCookies( |
145 *request, cookie_list)) { | 153 *request, cookie_list)) { |
146 DoLoadCookies(info, render_process_id, render_view_id, global_id); | 154 DoLoadCookies(info, render_process_id, render_view_id, global_id); |
147 } else { | 155 } else { |
148 StartAndroidDownload(info, render_process_id, render_view_id); | 156 StartAndroidDownload(info, render_process_id, render_view_id); |
149 } | 157 } |
150 } | 158 } |
151 | 159 |
152 void DownloadControllerAndroidImpl::DoLoadCookies( | 160 void DownloadControllerAndroidImpl::DoLoadCookies( |
153 const DownloadInfoAndroid& info, int render_process_id, | 161 const DownloadInfoAndroid& info, int render_process_id, |
154 int render_view_id, const GlobalRequestID& global_id) { | 162 int render_view_id, const GlobalRequestID& global_id) { |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 164 |
155 net::CookieOptions options; | 165 net::CookieOptions options; |
156 options.set_include_httponly(); | 166 options.set_include_httponly(); |
157 | 167 |
158 net::URLRequest* request = | 168 net::URLRequest* request = |
159 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 169 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
160 DCHECK(request) << "Request to download not found."; | 170 if (!request) { |
| 171 LOG(ERROR) << "Request to download not found."; |
| 172 return; |
| 173 } |
161 | 174 |
162 request->context()->cookie_store()->GetCookiesWithOptionsAsync( | 175 request->context()->cookie_store()->GetCookiesWithOptionsAsync( |
163 info.url, options, | 176 info.url, options, |
164 base::Bind(&DownloadControllerAndroidImpl::OnCookieResponse, | 177 base::Bind(&DownloadControllerAndroidImpl::OnCookieResponse, |
165 base::Unretained(this), info, render_process_id, | 178 base::Unretained(this), info, render_process_id, |
166 render_view_id)); | 179 render_view_id)); |
167 } | 180 } |
168 | 181 |
169 void DownloadControllerAndroidImpl::OnCookieResponse( | 182 void DownloadControllerAndroidImpl::OnCookieResponse( |
170 DownloadInfoAndroid download_info, | 183 DownloadInfoAndroid download_info, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 referer = referer_url.spec(); | 347 referer = referer_url.spec(); |
335 if (!request->url_chain().empty()) { | 348 if (!request->url_chain().empty()) { |
336 original_url = request->url_chain().front(); | 349 original_url = request->url_chain().front(); |
337 url = request->url_chain().back(); | 350 url = request->url_chain().back(); |
338 } | 351 } |
339 } | 352 } |
340 | 353 |
341 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 354 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
342 | 355 |
343 } // namespace content | 356 } // namespace content |
OLD | NEW |