| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/net/utility_process_mojo_proxy_resolver_factory.h" | 5 #include "chrome/browser/net/utility_process_mojo_proxy_resolver_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/utility_process_host.h" | 16 #include "content/public/browser/utility_process_host.h" |
| 17 #include "content/public/browser/utility_process_host_client.h" | 17 #include "content/public/browser/utility_process_host_client.h" |
| 18 #include "content/public/common/service_registry.h" | 18 #include "services/shell/public/cpp/interface_provider.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 const int kUtilityProcessIdleTimeoutSeconds = 5; | 22 const int kUtilityProcessIdleTimeoutSeconds = 5; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 UtilityProcessMojoProxyResolverFactory* | 26 UtilityProcessMojoProxyResolverFactory* |
| 27 UtilityProcessMojoProxyResolverFactory::GetInstance() { | 27 UtilityProcessMojoProxyResolverFactory::GetInstance() { |
| 28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 DCHECK(!weak_utility_process_host_); | 47 DCHECK(!weak_utility_process_host_); |
| 48 DVLOG(1) << "Attempting to create utility process for proxy resolver"; | 48 DVLOG(1) << "Attempting to create utility process for proxy resolver"; |
| 49 content::UtilityProcessHost* utility_process_host = | 49 content::UtilityProcessHost* utility_process_host = |
| 50 content::UtilityProcessHost::Create( | 50 content::UtilityProcessHost::Create( |
| 51 scoped_refptr<content::UtilityProcessHostClient>(), | 51 scoped_refptr<content::UtilityProcessHostClient>(), |
| 52 base::ThreadTaskRunnerHandle::Get()); | 52 base::ThreadTaskRunnerHandle::Get()); |
| 53 utility_process_host->SetName(l10n_util::GetStringUTF16( | 53 utility_process_host->SetName(l10n_util::GetStringUTF16( |
| 54 IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME)); | 54 IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME)); |
| 55 bool process_started = utility_process_host->Start(); | 55 bool process_started = utility_process_host->Start(); |
| 56 if (process_started) { | 56 if (process_started) { |
| 57 content::ServiceRegistry* service_registry = | 57 utility_process_host->GetRemoteInterfaces()->GetInterface( |
| 58 utility_process_host->GetServiceRegistry(); | 58 &resolver_factory_); |
| 59 service_registry->ConnectToRemoteService( | |
| 60 mojo::GetProxy(&resolver_factory_)); | |
| 61 resolver_factory_.set_connection_error_handler( | 59 resolver_factory_.set_connection_error_handler( |
| 62 base::Bind(&UtilityProcessMojoProxyResolverFactory::OnConnectionError, | 60 base::Bind(&UtilityProcessMojoProxyResolverFactory::OnConnectionError, |
| 63 base::Unretained(this))); | 61 base::Unretained(this))); |
| 64 weak_utility_process_host_ = utility_process_host->AsWeakPtr(); | 62 weak_utility_process_host_ = utility_process_host->AsWeakPtr(); |
| 65 } else { | 63 } else { |
| 66 LOG(ERROR) << "Unable to connect to utility process"; | 64 LOG(ERROR) << "Unable to connect to utility process"; |
| 67 } | 65 } |
| 68 } | 66 } |
| 69 | 67 |
| 70 std::unique_ptr<base::ScopedClosureRunner> | 68 std::unique_ptr<base::ScopedClosureRunner> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 113 } |
| 116 } | 114 } |
| 117 | 115 |
| 118 void UtilityProcessMojoProxyResolverFactory::OnIdleTimeout() { | 116 void UtilityProcessMojoProxyResolverFactory::OnIdleTimeout() { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 DCHECK_EQ(num_proxy_resolvers_, 0u); | 118 DCHECK_EQ(num_proxy_resolvers_, 0u); |
| 121 delete weak_utility_process_host_.get(); | 119 delete weak_utility_process_host_.get(); |
| 122 weak_utility_process_host_.reset(); | 120 weak_utility_process_host_.reset(); |
| 123 resolver_factory_.reset(); | 121 resolver_factory_.reset(); |
| 124 } | 122 } |
| OLD | NEW |