Chromium Code Reviews| 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/nacl_host/nacl_broker_service_win.h" | 5 #include "components/nacl/browser/nacl_broker_service_win.h" |
| 6 | 6 |
| 7 #include "chrome/browser/nacl_host/nacl_process_host.h" | 7 #include "components/nacl/browser/nacl_process_host.h" |
| 8 #include "components/nacl/common/nacl_process_type.h" | 8 #include "components/nacl/common/nacl_process_type.h" |
| 9 #include "content/public/browser/browser_child_process_host_iterator.h" | 9 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 10 | 10 |
| 11 using content::BrowserChildProcessHostIterator; | 11 using content::BrowserChildProcessHostIterator; |
| 12 | 12 |
| 13 namespace nacl { | |
| 14 | |
| 13 NaClBrokerService* NaClBrokerService::GetInstance() { | 15 NaClBrokerService* NaClBrokerService::GetInstance() { |
| 14 return Singleton<NaClBrokerService>::get(); | 16 return Singleton<NaClBrokerService>::get(); |
| 15 } | 17 } |
| 16 | 18 |
| 17 NaClBrokerService::NaClBrokerService() | 19 NaClBrokerService::NaClBrokerService() |
| 18 : loaders_running_(0) { | 20 : loaders_running_(0) { |
| 19 } | 21 } |
| 20 | 22 |
| 21 bool NaClBrokerService::StartBroker() { | 23 bool NaClBrokerService::StartBroker() { |
| 22 NaClBrokerHost* broker_host = new NaClBrokerHost; | 24 nacl::NaClBrokerHost* broker_host = new nacl::NaClBrokerHost; |
|
Mark Seaborn
2013/11/21 23:47:34
"nacl::" prefix shouldn't be necessary. Same belo
| |
| 23 if (!broker_host->Init()) { | 25 if (!broker_host->Init()) { |
| 24 delete broker_host; | 26 delete broker_host; |
| 25 return false; | 27 return false; |
| 26 } | 28 } |
| 27 return true; | 29 return true; |
| 28 } | 30 } |
| 29 | 31 |
| 30 bool NaClBrokerService::LaunchLoader( | 32 bool NaClBrokerService::LaunchLoader( |
| 31 base::WeakPtr<NaClProcessHost> nacl_process_host, | 33 base::WeakPtr<nacl::NaClProcessHost> nacl_process_host, |
| 32 const std::string& loader_channel_id) { | 34 const std::string& loader_channel_id) { |
| 33 // Add task to the list | 35 // Add task to the list |
| 34 pending_launches_[loader_channel_id] = nacl_process_host; | 36 pending_launches_[loader_channel_id] = nacl_process_host; |
| 35 NaClBrokerHost* broker_host = GetBrokerHost(); | 37 nacl::NaClBrokerHost* broker_host = GetBrokerHost(); |
| 36 | 38 |
| 37 if (!broker_host) { | 39 if (!broker_host) { |
| 38 if (!StartBroker()) | 40 if (!StartBroker()) |
| 39 return false; | 41 return false; |
| 40 broker_host = GetBrokerHost(); | 42 broker_host = GetBrokerHost(); |
| 41 } | 43 } |
| 42 broker_host->LaunchLoader(loader_channel_id); | 44 broker_host->LaunchLoader(loader_channel_id); |
| 43 | 45 |
| 44 return true; | 46 return true; |
| 45 } | 47 } |
| 46 | 48 |
| 47 void NaClBrokerService::OnLoaderLaunched(const std::string& channel_id, | 49 void NaClBrokerService::OnLoaderLaunched(const std::string& channel_id, |
| 48 base::ProcessHandle handle) { | 50 base::ProcessHandle handle) { |
| 49 PendingLaunchesMap::iterator it = pending_launches_.find(channel_id); | 51 PendingLaunchesMap::iterator it = pending_launches_.find(channel_id); |
| 50 if (pending_launches_.end() == it) | 52 if (pending_launches_.end() == it) |
| 51 NOTREACHED(); | 53 NOTREACHED(); |
| 52 | 54 |
| 53 NaClProcessHost* client = it->second.get(); | 55 nacl::NaClProcessHost* client = it->second.get(); |
| 54 if (client) | 56 if (client) |
| 55 client->OnProcessLaunchedByBroker(handle); | 57 client->OnProcessLaunchedByBroker(handle); |
| 56 pending_launches_.erase(it); | 58 pending_launches_.erase(it); |
| 57 ++loaders_running_; | 59 ++loaders_running_; |
| 58 } | 60 } |
| 59 | 61 |
| 60 void NaClBrokerService::OnLoaderDied() { | 62 void NaClBrokerService::OnLoaderDied() { |
| 61 DCHECK(loaders_running_ > 0); | 63 DCHECK(loaders_running_ > 0); |
| 62 --loaders_running_; | 64 --loaders_running_; |
| 63 // Stop the broker only if there are no loaders running or being launched. | 65 // Stop the broker only if there are no loaders running or being launched. |
| 64 NaClBrokerHost* broker_host = GetBrokerHost(); | 66 nacl::NaClBrokerHost* broker_host = GetBrokerHost(); |
| 65 if (loaders_running_ + pending_launches_.size() == 0 && broker_host != NULL) { | 67 if (loaders_running_ + pending_launches_.size() == 0 && broker_host != NULL) { |
| 66 broker_host->StopBroker(); | 68 broker_host->StopBroker(); |
| 67 } | 69 } |
| 68 } | 70 } |
| 69 | 71 |
| 70 bool NaClBrokerService::LaunchDebugExceptionHandler( | 72 bool NaClBrokerService::LaunchDebugExceptionHandler( |
| 71 base::WeakPtr<NaClProcessHost> nacl_process_host, int32 pid, | 73 base::WeakPtr<nacl::NaClProcessHost> nacl_process_host, int32 pid, |
| 72 base::ProcessHandle process_handle, const std::string& startup_info) { | 74 base::ProcessHandle process_handle, const std::string& startup_info) { |
| 73 pending_debuggers_[pid] = nacl_process_host; | 75 pending_debuggers_[pid] = nacl_process_host; |
| 74 NaClBrokerHost* broker_host = GetBrokerHost(); | 76 nacl::NaClBrokerHost* broker_host = GetBrokerHost(); |
| 75 if (!broker_host) | 77 if (!broker_host) |
| 76 return false; | 78 return false; |
| 77 return broker_host->LaunchDebugExceptionHandler(pid, process_handle, | 79 return broker_host->LaunchDebugExceptionHandler(pid, process_handle, |
| 78 startup_info); | 80 startup_info); |
| 79 } | 81 } |
| 80 | 82 |
| 81 void NaClBrokerService::OnDebugExceptionHandlerLaunched(int32 pid, | 83 void NaClBrokerService::OnDebugExceptionHandlerLaunched(int32 pid, |
| 82 bool success) { | 84 bool success) { |
| 83 PendingDebugExceptionHandlersMap::iterator it = pending_debuggers_.find(pid); | 85 PendingDebugExceptionHandlersMap::iterator it = pending_debuggers_.find(pid); |
| 84 if (pending_debuggers_.end() == it) | 86 if (pending_debuggers_.end() == it) |
| 85 NOTREACHED(); | 87 NOTREACHED(); |
| 86 | 88 |
| 87 NaClProcessHost* client = it->second.get(); | 89 nacl::NaClProcessHost* client = it->second.get(); |
| 88 if (client) | 90 if (client) |
| 89 client->OnDebugExceptionHandlerLaunchedByBroker(success); | 91 client->OnDebugExceptionHandlerLaunchedByBroker(success); |
| 90 pending_debuggers_.erase(it); | 92 pending_debuggers_.erase(it); |
| 91 } | 93 } |
| 92 | 94 |
| 93 NaClBrokerHost* NaClBrokerService::GetBrokerHost() { | 95 nacl::NaClBrokerHost* NaClBrokerService::GetBrokerHost() { |
| 94 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_BROKER); | 96 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_BROKER); |
| 95 while (!iter.Done()) { | 97 while (!iter.Done()) { |
| 96 NaClBrokerHost* host = static_cast<NaClBrokerHost*>(iter.GetDelegate()); | 98 nacl::NaClBrokerHost* host = static_cast<nacl::NaClBrokerHost*>( |
| 99 iter.GetDelegate()); | |
| 97 if (!host->IsTerminating()) | 100 if (!host->IsTerminating()) |
| 98 return host; | 101 return host; |
| 99 ++iter; | 102 ++iter; |
| 100 } | 103 } |
| 101 return NULL; | 104 return NULL; |
| 102 } | 105 } |
| 106 | |
| 107 } // namespace nacl | |
| OLD | NEW |