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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 167 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
168 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); | 168 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); |
169 if (!utility_process_host_->StartBatchMode()) { | 169 if (!utility_process_host_->StartBatchMode()) { |
170 utility_process_host_.reset(); | 170 utility_process_host_.reset(); |
171 return; | 171 return; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void ImageDecoder::StopBatchMode() { | 175 void ImageDecoder::StopBatchMode() { |
176 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 176 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 177 { |
| 178 // Check for outstanding requests and wait for them to finish. |
| 179 base::AutoLock lock(map_lock_); |
| 180 if (!image_request_id_map_.empty()) { |
| 181 batch_mode_timer_->Reset(); |
| 182 return; |
| 183 } |
| 184 } |
| 185 |
177 if (utility_process_host_) { | 186 if (utility_process_host_) { |
178 utility_process_host_->EndBatchMode(); | 187 utility_process_host_->EndBatchMode(); |
179 utility_process_host_.reset(); | 188 utility_process_host_.reset(); |
180 } | 189 } |
181 | |
182 // There could be outstanding request that are taking too long. Fail these so | |
183 // that there aren't any dangling requests. | |
184 FailAllRequests(); | |
185 } | 190 } |
186 | 191 |
187 void ImageDecoder::FailAllRequests() { | 192 void ImageDecoder::FailAllRequests() { |
188 RequestMap requests; | 193 RequestMap requests; |
189 { | 194 { |
190 base::AutoLock lock(map_lock_); | 195 base::AutoLock lock(map_lock_); |
191 requests = image_request_id_map_; | 196 requests = image_request_id_map_; |
192 } | 197 } |
193 | 198 |
194 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously | 199 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 auto it = image_request_id_map_.find(request_id); | 283 auto it = image_request_id_map_.find(request_id); |
279 if (it == image_request_id_map_.end()) | 284 if (it == image_request_id_map_.end()) |
280 return; | 285 return; |
281 image_request = it->second; | 286 image_request = it->second; |
282 image_request_id_map_.erase(it); | 287 image_request_id_map_.erase(it); |
283 } | 288 } |
284 | 289 |
285 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); | 290 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); |
286 image_request->OnDecodeImageFailed(); | 291 image_request->OnDecodeImageFailed(); |
287 } | 292 } |
OLD | NEW |