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