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 "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/common/chrome_utility_messages.h" | 9 #include "chrome/common/chrome_utility_messages.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 void ImageDecoder::DecodeImageInSandbox( | 74 void ImageDecoder::DecodeImageInSandbox( |
75 ImageRequest* image_request, | 75 ImageRequest* image_request, |
76 const std::vector<unsigned char>& image_data, | 76 const std::vector<unsigned char>& image_data, |
77 ImageCodec image_codec, | 77 ImageCodec image_codec, |
78 bool shrink_to_fit) { | 78 bool shrink_to_fit) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 if (!utility_process_host_) { | 80 if (!utility_process_host_) { |
81 StartBatchMode(); | 81 StartBatchMode(); |
82 } | 82 } |
| 83 if (!utility_process_host_) { |
| 84 // Utility process failed to start; notify delegate and return. |
| 85 // Without this check, we were seeing crashes on startup. Further |
| 86 // investigation is needed to determine why the utility process |
| 87 // is failing to start. See crbug.com/472272 |
| 88 image_request->task_runner()->PostTask( |
| 89 FROM_HERE, base::Bind(&ImageRequest::OnDecodeImageFailed, |
| 90 base::Unretained(image_request))); |
| 91 return; |
| 92 } |
83 | 93 |
84 last_request_ = base::TimeTicks::Now(); | 94 last_request_ = base::TimeTicks::Now(); |
85 base::AutoLock lock(map_lock_); | 95 base::AutoLock lock(map_lock_); |
86 image_request_id_map_.insert( | 96 image_request_id_map_.insert( |
87 std::make_pair(image_request_id_counter_, image_request)); | 97 std::make_pair(image_request_id_counter_, image_request)); |
88 | 98 |
89 switch (image_codec) { | 99 switch (image_codec) { |
90 case ROBUST_JPEG_CODEC: | 100 case ROBUST_JPEG_CODEC: |
91 utility_process_host_->Send(new ChromeUtilityMsg_RobustJPEGDecodeImage( | 101 utility_process_host_->Send(new ChromeUtilityMsg_RobustJPEGDecodeImage( |
92 image_data, image_request_id_counter_)); | 102 image_data, image_request_id_counter_)); |
(...skipping 17 matching lines...) Expand all Loading... |
110 ++it; | 120 ++it; |
111 } | 121 } |
112 } | 122 } |
113 } | 123 } |
114 | 124 |
115 void ImageDecoder::StartBatchMode() { | 125 void ImageDecoder::StartBatchMode() { |
116 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
117 utility_process_host_ = | 127 utility_process_host_ = |
118 UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get()) | 128 UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get()) |
119 ->AsWeakPtr(); | 129 ->AsWeakPtr(); |
120 utility_process_host_->StartBatchMode(); | 130 if (!utility_process_host_->StartBatchMode()) { |
| 131 utility_process_host_.reset(); |
| 132 return; |
| 133 } |
121 batch_mode_timer_.Start( | 134 batch_mode_timer_.Start( |
122 FROM_HERE, base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds), | 135 FROM_HERE, base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds), |
123 this, &ImageDecoder::StopBatchMode); | 136 this, &ImageDecoder::StopBatchMode); |
124 } | 137 } |
125 | 138 |
126 void ImageDecoder::StopBatchMode() { | 139 void ImageDecoder::StopBatchMode() { |
127 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
128 if ((base::TimeTicks::Now() - last_request_) | 141 if ((base::TimeTicks::Now() - last_request_) |
129 < base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds)) { | 142 < base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds)) { |
130 return; | 143 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 auto it = image_request_id_map_.find(request_id); | 185 auto it = image_request_id_map_.find(request_id); |
173 if (it != image_request_id_map_.end()) { | 186 if (it != image_request_id_map_.end()) { |
174 ImageRequest* image_request = it->second; | 187 ImageRequest* image_request = it->second; |
175 image_request->task_runner()->PostTask( | 188 image_request->task_runner()->PostTask( |
176 FROM_HERE, base::Bind(&ImageRequest::OnDecodeImageFailed, | 189 FROM_HERE, base::Bind(&ImageRequest::OnDecodeImageFailed, |
177 base::Unretained(image_request))); | 190 base::Unretained(image_request))); |
178 | 191 |
179 image_request_id_map_.erase(it); | 192 image_request_id_map_.erase(it); |
180 } | 193 } |
181 } | 194 } |
OLD | NEW |