| Index: remoting/host/remoting_me2me_host.cc
|
| diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
|
| index 6aa6b1e27eefdfead7a33b6ab89920cf4f6ba5cc..b00ae92de089e639e343f83b5604c2bc58c62a07 100644
|
| --- a/remoting/host/remoting_me2me_host.cc
|
| +++ b/remoting/host/remoting_me2me_host.cc
|
| @@ -19,7 +19,6 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "base/synchronization/waitable_event.h"
|
| #include "base/threading/thread.h"
|
| #include "build/build_config.h"
|
| #include "crypto/nss_util.h"
|
| @@ -148,7 +147,7 @@ class HostProcess
|
| public IPC::Listener,
|
| public base::RefCountedThreadSafe<HostProcess> {
|
| public:
|
| - HostProcess(scoped_ptr<ChromotingHostContext> context,
|
| + HostProcess(scoped_refptr<ChromotingHostContext> context,
|
| int* exit_code_out);
|
|
|
| // ConfigWatcher::Delegate interface.
|
| @@ -260,6 +259,8 @@ class HostProcess
|
|
|
| void ShutdownOnNetworkThread();
|
|
|
| + void PostPolicyWatcherShutdown();
|
| +
|
| // Crashes the process in response to a daemon's request. The daemon passes
|
| // the location of the code that detected the fatal error resulted in this
|
| // request.
|
| @@ -267,7 +268,7 @@ class HostProcess
|
| const std::string& file_name,
|
| const int& line_number);
|
|
|
| - scoped_ptr<ChromotingHostContext> context_;
|
| + scoped_refptr<ChromotingHostContext> context_;
|
|
|
| // Created on the UI thread but used from the network thread.
|
| scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
|
| @@ -345,9 +346,9 @@ class HostProcess
|
| scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_;
|
| };
|
|
|
| -HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
|
| +HostProcess::HostProcess(scoped_refptr<ChromotingHostContext> context,
|
| int* exit_code_out)
|
| - : context_(context.Pass()),
|
| + : context_(context),
|
| state_(HOST_INITIALIZING),
|
| use_service_account_(false),
|
| enable_vp9_(false),
|
| @@ -376,15 +377,6 @@ HostProcess::~HostProcess() {
|
| DCHECK(!config_watcher_);
|
| DCHECK(!daemon_channel_);
|
| DCHECK(!desktop_environment_factory_);
|
| -
|
| - // We might be getting deleted on one of the threads the |host_context| owns,
|
| - // so we need to post it back to the caller thread to safely join & delete the
|
| - // threads it contains. This will go away when we move to AutoThread.
|
| - // |context_release()| will null |context_| before the method is invoked, so
|
| - // we need to pull out the task-runner on which to call DeleteSoon first.
|
| - scoped_refptr<base::SingleThreadTaskRunner> task_runner =
|
| - context_->ui_task_runner();
|
| - task_runner->DeleteSoon(FROM_HERE, context_.release());
|
| }
|
|
|
| bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) {
|
| @@ -1411,24 +1403,25 @@ void HostProcess::ShutdownOnNetworkThread() {
|
| state_ = HOST_STOPPED;
|
|
|
| if (policy_watcher_.get()) {
|
| - base::WaitableEvent done_event(true, false);
|
| - policy_watcher_->StopWatching(&done_event);
|
| - done_event.Wait();
|
| - policy_watcher_.reset();
|
| + policy_watcher_->StopWatching(
|
| + base::Bind(&HostProcess::PostPolicyWatcherShutdown, this));
|
| + } else {
|
| + PostPolicyWatcherShutdown();
|
| }
|
| -
|
| - config_watcher_.reset();
|
| -
|
| - // Complete the rest of shutdown on the main thread.
|
| - context_->ui_task_runner()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&HostProcess::ShutdownOnUiThread, this));
|
| } else {
|
| // This method is only called in STOPPING_TO_RESTART and STOPPING states.
|
| NOTREACHED();
|
| }
|
| }
|
|
|
| +void HostProcess::PostPolicyWatcherShutdown() {
|
| + policy_watcher_.reset();
|
| +
|
| + // Complete the rest of shutdown on the main thread.
|
| + context_->ui_task_runner()->PostTask(
|
| + FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this));
|
| +}
|
| +
|
| void HostProcess::OnCrash(const std::string& function_name,
|
| const std::string& file_name,
|
| const int& line_number) {
|
| @@ -1462,17 +1455,17 @@ int HostProcessMain() {
|
|
|
| // Create the main message loop and start helper threads.
|
| base::MessageLoopForUI message_loop;
|
| - scoped_ptr<ChromotingHostContext> context =
|
| + scoped_refptr<ChromotingHostContext> context =
|
| ChromotingHostContext::Create(new AutoThreadTaskRunner(
|
| message_loop.message_loop_proxy(), base::MessageLoop::QuitClosure()));
|
| - if (!context)
|
| + if (!context.get())
|
| return kInitializationFailed;
|
|
|
| // Create & start the HostProcess using these threads.
|
| // TODO(wez): The HostProcess holds a reference to itself until Shutdown().
|
| // Remove this hack as part of the multi-process refactoring.
|
| int exit_code = kSuccessExitCode;
|
| - new HostProcess(context.Pass(), &exit_code);
|
| + new HostProcess(context, &exit_code);
|
|
|
| // Run the main (also UI) message loop until the host no longer needs it.
|
| message_loop.Run();
|
|
|