Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Side by Side Diff: remoting/host/daemon_process.cc

Issue 10855249: [Chromoting] The daemon process now starts the networking process and passes the host configuration… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback and rebased on top of https://chromiumcodereview.appspot.com/10829467/ Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "remoting/host/daemon_process.h" 5 #include "remoting/host/daemon_process.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/file_path.h"
11 #include "base/file_util.h"
9 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread.h" 13 #include "remoting/host/branding.h"
11 14 #include "remoting/host/chromoting_messages.h"
12 namespace {
13
14 const char kIpcThreadName[] = "Daemon process IPC";
15
16 } // namespace
17 15
18 namespace remoting { 16 namespace remoting {
19 17
20 DaemonProcess::~DaemonProcess() { 18 DaemonProcess::~DaemonProcess() {
19 CHECK(!config_watcher_.get());
20 }
21
22 void DaemonProcess::OnConfigUpdated(const std::string& config) {
23 if (config_ != config) {
24 config_ = config;
25 Send(new ChromotingDaemonNetworkMsg_Configuration(config_));
26 }
27 }
28
29 void DaemonProcess::OnConfigWatcherError() {
30 Stop();
31 }
32
33 void DaemonProcess::OnChannelConnected() {
34 DCHECK(main_task_runner()->BelongsToCurrentThread());
35
36 // Send the configuration to the network process.
37 Send(new ChromotingDaemonNetworkMsg_Configuration(config_));
21 } 38 }
22 39
23 bool DaemonProcess::OnMessageReceived(const IPC::Message& message) { 40 bool DaemonProcess::OnMessageReceived(const IPC::Message& message) {
24 return true; 41 DCHECK(main_task_runner()->BelongsToCurrentThread());
42
43 return false;
25 } 44 }
26 45
27 DaemonProcess::DaemonProcess( 46 DaemonProcess::DaemonProcess(
28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 47 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
29 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 48 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
30 const base::Closure& stopped_callback) 49 const base::Closure& stopped_callback)
31 : Stoppable(main_task_runner, stopped_callback), 50 : Stoppable(main_task_runner, stopped_callback),
32 main_task_runner_(main_task_runner), 51 main_task_runner_(main_task_runner),
33 io_task_runner_(io_task_runner) { 52 io_task_runner_(io_task_runner),
53 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
34 // Initialize on the same thread that will be used for shutting down. 54 // Initialize on the same thread that will be used for shutting down.
35 main_task_runner_->PostTask( 55 main_task_runner_->PostTask(
36 FROM_HERE, 56 FROM_HERE,
37 base::Bind(&DaemonProcess::Init, base::Unretained(this))); 57 base::Bind(&DaemonProcess::Initialize, base::Unretained(this)));
38 } 58 }
39 59
40 void DaemonProcess::Init() { 60 void DaemonProcess::Initialize() {
41 DCHECK(main_task_runner_->BelongsToCurrentThread()); 61 DCHECK(main_task_runner()->BelongsToCurrentThread());
42 62
43 if (!LaunchNetworkProcess()) { 63 // Get the name of the host configuration file.
44 LOG(ERROR) << "Failed to launch the networking process."; 64 FilePath default_config_dir = remoting::GetConfigDir();
45 Stop(); 65 FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile);
46 return; 66 const CommandLine* command_line = CommandLine::ForCurrentProcess();
67 if (command_line->HasSwitch(kHostConfigSwitchName)) {
68 config_path = command_line->GetSwitchValuePath(kHostConfigSwitchName);
47 } 69 }
70
71 // Start watching the host configuration file.
72 config_watcher_.reset(new DaemonConfigWatcher(main_task_runner(),
73 io_task_runner(),
74 weak_factory_.GetWeakPtr()));
75 config_watcher_->Watch(config_path);
76
77 // Launch the process.
78 LaunchNetworkProcess();
48 } 79 }
49 80
50 void DaemonProcess::DoStop() { 81 void DaemonProcess::DoStop() {
51 DCHECK(main_task_runner_->BelongsToCurrentThread()); 82 DCHECK(main_task_runner()->BelongsToCurrentThread());
83
84 weak_factory_.InvalidateWeakPtrs();
85 if (config_watcher_.get()) {
86 DaemonConfigWatcher* config_watcher = config_watcher_.get();
Wez 2012/08/24 22:20:38 Why do you need this?
alexeypa (please no reviews) 2012/08/27 23:16:41 I wasn't sure that -> will be evaluated before con
87 config_watcher->Stop(config_watcher_.Pass());
88 }
52 89
53 CompleteStopping(); 90 CompleteStopping();
54 } 91 }
55 92
93 void DaemonProcess::SendConfig(const std::string& config) {
94 DCHECK(main_task_runner()->BelongsToCurrentThread());
95
96 if (config_ != config) {
97 config_ = config;
98 Send(new ChromotingDaemonNetworkMsg_Configuration(config_));
99 }
100 }
101
56 } // namespace remoting 102 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698