Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/image_decoder.cc

Issue 1071453002: Fail all started requests if the utility process crashes or fails to start. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@racy-image-decoder
Patch Set: Maybe fix windows. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if ((base::TimeTicks::Now() - last_request_) 170 if ((base::TimeTicks::Now() - last_request_)
171 < base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds)) { 171 < base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds)) {
172 return; 172 return;
173 } 173 }
174 174
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 batch_mode_timer_.Stop(); 179 batch_mode_timer_.Stop();
180
181 // There could be outstanding request that are taking too long. Fail these so
182 // that there aren't any dangling requests.
183 FailAllRequests();
184 }
185
186 void ImageDecoder::FailAllRequests() {
187 RequestMap requests;
188 {
189 base::AutoLock lock(map_lock_);
190 requests = image_request_id_map_;
191 }
192
193 // Since |OnProcessCrashed| and |OnProcessLaunchFailed| are run asynchronously
194 // from the actual event, it's possible for a new utility process to have been
195 // created and sent requests by the time these functions are run. This results
196 // in failing requests that are unaffected by the crash. Although not ideal,
197 // this is valid and simpler than tracking which request is sent to which
198 // utility process, and whether the request has been sent at all.
199 for (const auto& request : requests)
200 OnDecodeImageFailed(request.first);
201 }
202
203 void ImageDecoder::OnProcessCrashed(int exit_code) {
204 DCHECK_CURRENTLY_ON(BrowserThread::IO);
205 FailAllRequests();
206 }
207
208 void ImageDecoder::OnProcessLaunchFailed() {
209 DCHECK_CURRENTLY_ON(BrowserThread::IO);
210 FailAllRequests();
180 } 211 }
181 212
182 bool ImageDecoder::OnMessageReceived( 213 bool ImageDecoder::OnMessageReceived(
183 const IPC::Message& message) { 214 const IPC::Message& message) {
184 bool handled = true; 215 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message) 216 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message)
186 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded, 217 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded,
187 OnDecodeImageSucceeded) 218 OnDecodeImageSucceeded)
188 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed, 219 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed,
189 OnDecodeImageFailed) 220 OnDecodeImageFailed)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 auto it = image_request_id_map_.find(request_id); 277 auto it = image_request_id_map_.find(request_id);
247 if (it == image_request_id_map_.end()) 278 if (it == image_request_id_map_.end())
248 return; 279 return;
249 image_request = it->second; 280 image_request = it->second;
250 image_request_id_map_.erase(it); 281 image_request_id_map_.erase(it);
251 } 282 }
252 283
253 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); 284 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread());
254 image_request->OnDecodeImageFailed(); 285 image_request->OnDecodeImageFailed();
255 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698