| 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 "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" | 
|  | 9 #include "chrome/grit/generated_resources.h" | 
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" | 
| 10 #include "content/public/browser/utility_process_host.h" | 11 #include "content/public/browser/utility_process_host.h" | 
| 11 #include "content/public/browser/utility_process_host_client.h" | 12 #include "content/public/browser/utility_process_host_client.h" | 
| 12 #include "content/public/common/service_registry.h" | 13 #include "content/public/common/service_registry.h" | 
| 13 #include "net/proxy/mojo_proxy_resolver_factory.h" | 14 #include "net/proxy/mojo_proxy_resolver_factory.h" | 
|  | 15 #include "ui/base/l10n/l10n_util.h" | 
| 14 | 16 | 
| 15 // static | 17 // static | 
| 16 UtilityProcessMojoProxyResolverFactory* | 18 UtilityProcessMojoProxyResolverFactory* | 
| 17 UtilityProcessMojoProxyResolverFactory::GetInstance() { | 19 UtilityProcessMojoProxyResolverFactory::GetInstance() { | 
| 18   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 20   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 
| 19   return Singleton< | 21   return Singleton< | 
| 20       UtilityProcessMojoProxyResolverFactory, | 22       UtilityProcessMojoProxyResolverFactory, | 
| 21       LeakySingletonTraits<UtilityProcessMojoProxyResolverFactory>>::get(); | 23       LeakySingletonTraits<UtilityProcessMojoProxyResolverFactory>>::get(); | 
| 22 } | 24 } | 
| 23 | 25 | 
| 24 UtilityProcessMojoProxyResolverFactory:: | 26 UtilityProcessMojoProxyResolverFactory:: | 
| 25     UtilityProcessMojoProxyResolverFactory() { | 27     UtilityProcessMojoProxyResolverFactory() { | 
| 26   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 28   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 
| 27 } | 29 } | 
| 28 | 30 | 
| 29 UtilityProcessMojoProxyResolverFactory:: | 31 UtilityProcessMojoProxyResolverFactory:: | 
| 30     ~UtilityProcessMojoProxyResolverFactory() { | 32     ~UtilityProcessMojoProxyResolverFactory() { | 
| 31   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 33   DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 
| 32 } | 34 } | 
| 33 | 35 | 
| 34 void UtilityProcessMojoProxyResolverFactory::CreateProcessAndConnect() { | 36 void UtilityProcessMojoProxyResolverFactory::CreateProcessAndConnect() { | 
| 35   DVLOG(1) << "Attempting to create utility process for proxy resolver"; | 37   DVLOG(1) << "Attempting to create utility process for proxy resolver"; | 
| 36   content::UtilityProcessHost* utility_process_host = | 38   content::UtilityProcessHost* utility_process_host = | 
| 37       content::UtilityProcessHost::Create( | 39       content::UtilityProcessHost::Create( | 
| 38           scoped_refptr<content::UtilityProcessHostClient>(), | 40           scoped_refptr<content::UtilityProcessHostClient>(), | 
| 39           base::MessageLoopProxy::current().get()); | 41           base::MessageLoopProxy::current().get()); | 
|  | 42   utility_process_host->SetName(l10n_util::GetStringUTF8( | 
|  | 43       IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME)); | 
| 40   bool process_started = utility_process_host->StartMojoMode(); | 44   bool process_started = utility_process_host->StartMojoMode(); | 
| 41   if (process_started) { | 45   if (process_started) { | 
| 42     content::ServiceRegistry* service_registry = | 46     content::ServiceRegistry* service_registry = | 
| 43         utility_process_host->GetServiceRegistry(); | 47         utility_process_host->GetServiceRegistry(); | 
| 44     service_registry->ConnectToRemoteService(&resolver_factory_); | 48     service_registry->ConnectToRemoteService(&resolver_factory_); | 
| 45     resolver_factory_.set_error_handler(this); | 49     resolver_factory_.set_error_handler(this); | 
| 46   } else { | 50   } else { | 
| 47     LOG(ERROR) << "Unable to connect to utility process"; | 51     LOG(ERROR) << "Unable to connect to utility process"; | 
| 48   } | 52   } | 
| 49 } | 53 } | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 61     req = nullptr; | 65     req = nullptr; | 
| 62     return; | 66     return; | 
| 63   } | 67   } | 
| 64   resolver_factory_->CreateResolver(req.Pass(), host_resolver.Pass()); | 68   resolver_factory_->CreateResolver(req.Pass(), host_resolver.Pass()); | 
| 65 } | 69 } | 
| 66 | 70 | 
| 67 void UtilityProcessMojoProxyResolverFactory::OnConnectionError() { | 71 void UtilityProcessMojoProxyResolverFactory::OnConnectionError() { | 
| 68   DVLOG(1) << "Disconnection from utility process detected"; | 72   DVLOG(1) << "Disconnection from utility process detected"; | 
| 69   resolver_factory_.reset(); | 73   resolver_factory_.reset(); | 
| 70 } | 74 } | 
| OLD | NEW | 
|---|