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 "chrome/browser/image_decoder.h" | 5 #include "chrome/browser/image_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/common/chrome_utility_messages.h" | 10 #include "chrome/common/chrome_utility_messages.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return; | 169 return; |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void ImageDecoder::StopBatchMode() { | 173 void ImageDecoder::StopBatchMode() { |
174 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
175 if (utility_process_host_) { | 175 if (utility_process_host_) { |
176 utility_process_host_->EndBatchMode(); | 176 utility_process_host_->EndBatchMode(); |
177 utility_process_host_.reset(); | 177 utility_process_host_.reset(); |
178 } | 178 } |
| 179 |
| 180 // There could be outstanding request that are taking too long. Fail these so |
| 181 // that there aren't any dangling requests. |
| 182 FailAllRequests(); |
| 183 } |
| 184 |
| 185 void ImageDecoder::FailAllRequests() { |
| 186 RequestMap requests; |
| 187 { |
| 188 base::AutoLock lock(map_lock_); |
| 189 requests = image_request_id_map_; |
| 190 } |
| 191 |
| 192 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously |
| 193 // from the actual event, it's possible for a new utility process to have been |
| 194 // created and sent requests by the time these functions are run. This results |
| 195 // in failing requests that are unaffected by the crash. Although not ideal, |
| 196 // this is valid and simpler than tracking which request is sent to which |
| 197 // utility process, and whether the request has been sent at all. |
| 198 for (const auto& request : requests) |
| 199 OnDecodeImageFailed(request.first); |
| 200 } |
| 201 |
| 202 void ImageDecoder::OnProcessCrashed(int exit_code) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 204 FailAllRequests(); |
| 205 } |
| 206 |
| 207 void ImageDecoder::OnProcessLaunchFailed() { |
| 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 209 FailAllRequests(); |
179 } | 210 } |
180 | 211 |
181 bool ImageDecoder::OnMessageReceived( | 212 bool ImageDecoder::OnMessageReceived( |
182 const IPC::Message& message) { | 213 const IPC::Message& message) { |
183 bool handled = true; | 214 bool handled = true; |
184 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message) | 215 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message) |
185 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded, | 216 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded, |
186 OnDecodeImageSucceeded) | 217 OnDecodeImageSucceeded) |
187 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed, | 218 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed, |
188 OnDecodeImageFailed) | 219 OnDecodeImageFailed) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 auto it = image_request_id_map_.find(request_id); | 276 auto it = image_request_id_map_.find(request_id); |
246 if (it == image_request_id_map_.end()) | 277 if (it == image_request_id_map_.end()) |
247 return; | 278 return; |
248 image_request = it->second; | 279 image_request = it->second; |
249 image_request_id_map_.erase(it); | 280 image_request_id_map_.erase(it); |
250 } | 281 } |
251 | 282 |
252 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); | 283 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); |
253 image_request->OnDecodeImageFailed(); | 284 image_request->OnDecodeImageFailed(); |
254 } | 285 } |
OLD | NEW |