| 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/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/common/image_decoder.mojom.h" | 11 #include "chrome/common/image_decoder.mojom.h" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/utility_process_host.h" | 14 #include "content/public/browser/utility_process_host.h" |
| 15 #include "content/public/common/service_registry.h" | 15 #include "content/public/common/service_registry.h" |
| 16 #include "services/shell/public/cpp/interface_provider.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 using content::UtilityProcessHost; | 21 using content::UtilityProcessHost; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // static, Leaky to allow access from any thread. | 25 // static, Leaky to allow access from any thread. |
| 25 base::LazyInstance<ImageDecoder>::Leaky g_decoder = LAZY_INSTANCE_INITIALIZER; | 26 base::LazyInstance<ImageDecoder>::Leaky g_decoder = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 180 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 180 utility_process_host_ = | 181 utility_process_host_ = |
| 181 UtilityProcessHost::Create( | 182 UtilityProcessHost::Create( |
| 182 this, base::ThreadTaskRunnerHandle::Get().get())->AsWeakPtr(); | 183 this, base::ThreadTaskRunnerHandle::Get().get())->AsWeakPtr(); |
| 183 utility_process_host_->SetName(l10n_util::GetStringUTF16( | 184 utility_process_host_->SetName(l10n_util::GetStringUTF16( |
| 184 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); | 185 IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); |
| 185 if (!utility_process_host_->Start()) { | 186 if (!utility_process_host_->Start()) { |
| 186 delete utility_process_host_.get(); | 187 delete utility_process_host_.get(); |
| 187 return; | 188 return; |
| 188 } | 189 } |
| 189 content::ServiceRegistry* service_registry = | 190 utility_process_host_->GetRemoteInterfaces()->GetInterface(&decoder_); |
| 190 utility_process_host_->GetServiceRegistry(); | |
| 191 service_registry->ConnectToRemoteService(mojo::GetProxy(&decoder_)); | |
| 192 } | 191 } |
| 193 | 192 |
| 194 void ImageDecoder::StopBatchMode() { | 193 void ImageDecoder::StopBatchMode() { |
| 195 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 194 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 196 { | 195 { |
| 197 // Check for outstanding requests and wait for them to finish. | 196 // Check for outstanding requests and wait for them to finish. |
| 198 base::AutoLock lock(map_lock_); | 197 base::AutoLock lock(map_lock_); |
| 199 if (!image_request_id_map_.empty()) { | 198 if (!image_request_id_map_.empty()) { |
| 200 batch_mode_timer_->Reset(); | 199 batch_mode_timer_->Reset(); |
| 201 return; | 200 return; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 auto it = image_request_id_map_.find(request_id); | 295 auto it = image_request_id_map_.find(request_id); |
| 297 if (it == image_request_id_map_.end()) | 296 if (it == image_request_id_map_.end()) |
| 298 return; | 297 return; |
| 299 image_request = it->second; | 298 image_request = it->second; |
| 300 image_request_id_map_.erase(it); | 299 image_request_id_map_.erase(it); |
| 301 } | 300 } |
| 302 | 301 |
| 303 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); | 302 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); |
| 304 image_request->OnDecodeImageFailed(); | 303 image_request->OnDecodeImageFailed(); |
| 305 } | 304 } |
| OLD | NEW |