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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 165 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
166 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); | 166 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); |
167 if (!utility_process_host_->StartBatchMode()) { | 167 if (!utility_process_host_->StartBatchMode()) { |
168 utility_process_host_.reset(); | 168 utility_process_host_.reset(); |
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 { |
| 176 // Check for outstanding requests and wait for them to finish. |
| 177 base::AutoLock lock(map_lock_); |
| 178 if (!image_request_id_map_.empty()) { |
| 179 batch_mode_timer_->Reset(); |
| 180 return; |
| 181 } |
| 182 } |
| 183 |
175 if (utility_process_host_) { | 184 if (utility_process_host_) { |
176 utility_process_host_->EndBatchMode(); | 185 utility_process_host_->EndBatchMode(); |
177 utility_process_host_.reset(); | 186 utility_process_host_.reset(); |
178 } | 187 } |
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 } | 188 } |
184 | 189 |
185 void ImageDecoder::FailAllRequests() { | 190 void ImageDecoder::FailAllRequests() { |
186 RequestMap requests; | 191 RequestMap requests; |
187 { | 192 { |
188 base::AutoLock lock(map_lock_); | 193 base::AutoLock lock(map_lock_); |
189 requests = image_request_id_map_; | 194 requests = image_request_id_map_; |
190 } | 195 } |
191 | 196 |
192 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously | 197 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 auto it = image_request_id_map_.find(request_id); | 281 auto it = image_request_id_map_.find(request_id); |
277 if (it == image_request_id_map_.end()) | 282 if (it == image_request_id_map_.end()) |
278 return; | 283 return; |
279 image_request = it->second; | 284 image_request = it->second; |
280 image_request_id_map_.erase(it); | 285 image_request_id_map_.erase(it); |
281 } | 286 } |
282 | 287 |
283 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); | 288 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); |
284 image_request->OnDecodeImageFailed(); | 289 image_request->OnDecodeImageFailed(); |
285 } | 290 } |
OLD | NEW |