| 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 "remoting/host/plugin/daemon_controller.h" | 5 #include "remoting/host/plugin/daemon_controller.h" |
| 6 | 6 |
| 7 #include <launch.h> | 7 #include <launch.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
| 19 #include "base/mac/launchd.h" | 19 #include "base/mac/launchd.h" |
| 20 #include "base/mac/mac_logging.h" | 20 #include "base/mac/mac_logging.h" |
| 21 #include "base/mac/mac_util.h" | 21 #include "base/mac/mac_util.h" |
| 22 #include "base/mac/scoped_launch_data.h" | 22 #include "base/mac/scoped_launch_data.h" |
| 23 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| 24 #include "base/time.h" | 24 #include "base/time.h" |
| 25 #include "base/values.h" | 25 #include "base/values.h" |
| 26 #include "remoting/host/constants_mac.h" | 26 #include "remoting/host/constants_mac.h" |
| 27 #include "remoting/host/json_host_config.h" | 27 #include "remoting/host/json_host_config.h" |
| 28 #include "remoting/host/usage_stats_consent.h" |
| 28 | 29 |
| 29 namespace remoting { | 30 namespace remoting { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // The NSSystemDirectories.h header has a conflicting definition of | 34 // The NSSystemDirectories.h header has a conflicting definition of |
| 34 // NSSearchPathDirectory with the one in base/mac/foundation_util.h. | 35 // NSSearchPathDirectory with the one in base/mac/foundation_util.h. |
| 35 // Foundation.h would work, but it can only be included from Objective-C files. | 36 // Foundation.h would work, but it can only be included from Objective-C files. |
| 36 // Therefore, we define the needed constants here. | 37 // Therefore, we define the needed constants here. |
| 37 const int NSLibraryDirectory = 5; | 38 const int NSLibraryDirectory = 5; |
| 38 | 39 |
| 39 // Use a single configuration file, instead of separate "auth" and "host" files. | 40 // Use a single configuration file, instead of separate "auth" and "host" files. |
| 40 // This is because the SetConfigAndStart() API only provides a single | 41 // This is because the SetConfigAndStart() API only provides a single |
| 41 // dictionary, and splitting this into two dictionaries would require | 42 // dictionary, and splitting this into two dictionaries would require |
| 42 // knowledge of which keys belong in which files. | 43 // knowledge of which keys belong in which files. |
| 43 const char kHostConfigFile[] = kHostConfigDir kServiceName ".json"; | 44 const char kHostConfigFile[] = kHostConfigDir kServiceName ".json"; |
| 44 | 45 |
| 45 class DaemonControllerMac : public remoting::DaemonController { | 46 class DaemonControllerMac : public remoting::DaemonController { |
| 46 public: | 47 public: |
| 47 DaemonControllerMac(); | 48 DaemonControllerMac(); |
| 48 virtual ~DaemonControllerMac(); | 49 virtual ~DaemonControllerMac(); |
| 49 | 50 |
| 50 virtual State GetState() OVERRIDE; | 51 virtual State GetState() OVERRIDE; |
| 51 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE; | 52 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE; |
| 52 virtual void SetConfigAndStart( | 53 virtual void SetConfigAndStart( |
| 53 scoped_ptr<base::DictionaryValue> config, | 54 scoped_ptr<base::DictionaryValue> config, |
| 54 const CompletionCallback& done_callback) OVERRIDE; | 55 bool consent, |
| 56 const CompletionCallback& done) OVERRIDE; |
| 55 virtual void UpdateConfig(scoped_ptr<base::DictionaryValue> config, | 57 virtual void UpdateConfig(scoped_ptr<base::DictionaryValue> config, |
| 56 const CompletionCallback& done_callback) OVERRIDE; | 58 const CompletionCallback& done_callback) OVERRIDE; |
| 57 virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; | 59 virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; |
| 58 virtual void SetWindow(void* window_handle) OVERRIDE; | 60 virtual void SetWindow(void* window_handle) OVERRIDE; |
| 59 virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; | 61 virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; |
| 62 virtual void GetUsageStatsConsent( |
| 63 const GetUsageStatsConsentCallback& callback) OVERRIDE; |
| 60 | 64 |
| 61 private: | 65 private: |
| 62 void DoGetConfig(const GetConfigCallback& callback); | 66 void DoGetConfig(const GetConfigCallback& callback); |
| 63 void DoGetVersion(const GetVersionCallback& callback); | 67 void DoGetVersion(const GetVersionCallback& callback); |
| 64 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 68 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, |
| 65 const CompletionCallback& done_callback); | 69 const CompletionCallback& done); |
| 66 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, | 70 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, |
| 67 const CompletionCallback& done_callback); | 71 const CompletionCallback& done_callback); |
| 68 void DoStop(const CompletionCallback& done_callback); | 72 void DoStop(const CompletionCallback& done_callback); |
| 69 | 73 |
| 70 void ShowPreferencePane(const std::string& config_data, | 74 void ShowPreferencePane(const std::string& config_data, |
| 71 const CompletionCallback& done_callback); | 75 const CompletionCallback& done_callback); |
| 72 void RegisterForPreferencePaneNotifications( | 76 void RegisterForPreferencePaneNotifications( |
| 73 const CompletionCallback &done_callback); | 77 const CompletionCallback &done_callback); |
| 74 void DeregisterForPreferencePaneNotifications(); | 78 void DeregisterForPreferencePaneNotifications(); |
| 75 void PreferencePaneCallbackDelegate(CFStringRef name); | 79 void PreferencePaneCallbackDelegate(CFStringRef name); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // base::Unretained() is safe, since this object owns the thread and therefore | 132 // base::Unretained() is safe, since this object owns the thread and therefore |
| 129 // outlives it. | 133 // outlives it. |
| 130 auth_thread_.message_loop_proxy()->PostTask( | 134 auth_thread_.message_loop_proxy()->PostTask( |
| 131 FROM_HERE, | 135 FROM_HERE, |
| 132 base::Bind(&DaemonControllerMac::DoGetConfig, base::Unretained(this), | 136 base::Bind(&DaemonControllerMac::DoGetConfig, base::Unretained(this), |
| 133 callback)); | 137 callback)); |
| 134 } | 138 } |
| 135 | 139 |
| 136 void DaemonControllerMac::SetConfigAndStart( | 140 void DaemonControllerMac::SetConfigAndStart( |
| 137 scoped_ptr<base::DictionaryValue> config, | 141 scoped_ptr<base::DictionaryValue> config, |
| 138 const CompletionCallback& done_callback) { | 142 bool /* consent */, |
| 143 const CompletionCallback& done) { |
| 139 auth_thread_.message_loop_proxy()->PostTask( | 144 auth_thread_.message_loop_proxy()->PostTask( |
| 140 FROM_HERE, base::Bind( | 145 FROM_HERE, base::Bind( |
| 141 &DaemonControllerMac::DoSetConfigAndStart, base::Unretained(this), | 146 &DaemonControllerMac::DoSetConfigAndStart, base::Unretained(this), |
| 142 base::Passed(&config), done_callback)); | 147 base::Passed(&config), done)); |
| 143 } | 148 } |
| 144 | 149 |
| 145 void DaemonControllerMac::UpdateConfig( | 150 void DaemonControllerMac::UpdateConfig( |
| 146 scoped_ptr<base::DictionaryValue> config, | 151 scoped_ptr<base::DictionaryValue> config, |
| 147 const CompletionCallback& done_callback) { | 152 const CompletionCallback& done_callback) { |
| 148 auth_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 153 auth_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 149 &DaemonControllerMac::DoUpdateConfig, base::Unretained(this), | 154 &DaemonControllerMac::DoUpdateConfig, base::Unretained(this), |
| 150 base::Passed(&config), done_callback)); | 155 base::Passed(&config), done_callback)); |
| 151 } | 156 } |
| 152 | 157 |
| 153 void DaemonControllerMac::Stop(const CompletionCallback& done_callback) { | 158 void DaemonControllerMac::Stop(const CompletionCallback& done_callback) { |
| 154 auth_thread_.message_loop_proxy()->PostTask( | 159 auth_thread_.message_loop_proxy()->PostTask( |
| 155 FROM_HERE, base::Bind( | 160 FROM_HERE, base::Bind( |
| 156 &DaemonControllerMac::DoStop, base::Unretained(this), done_callback)); | 161 &DaemonControllerMac::DoStop, base::Unretained(this), done_callback)); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void DaemonControllerMac::SetWindow(void* window_handle) { | 164 void DaemonControllerMac::SetWindow(void* window_handle) { |
| 160 // noop | 165 // noop |
| 161 } | 166 } |
| 162 | 167 |
| 163 void DaemonControllerMac::GetVersion(const GetVersionCallback& callback) { | 168 void DaemonControllerMac::GetVersion(const GetVersionCallback& callback) { |
| 164 auth_thread_.message_loop_proxy()->PostTask( | 169 auth_thread_.message_loop_proxy()->PostTask( |
| 165 FROM_HERE, | 170 FROM_HERE, |
| 166 base::Bind(&DaemonControllerMac::DoGetVersion, base::Unretained(this), | 171 base::Bind(&DaemonControllerMac::DoGetVersion, base::Unretained(this), |
| 167 callback)); | 172 callback)); |
| 168 } | 173 } |
| 169 | 174 |
| 175 void DaemonControllerMac::GetUsageStatsConsent( |
| 176 const GetUsageStatsConsentCallback& callback) { |
| 177 // Crash dump collection is not implemented on Mac yet. |
| 178 // http://crbug.com/130678. |
| 179 callback.Run(false, false, false); |
| 180 } |
| 181 |
| 170 void DaemonControllerMac::DoGetConfig(const GetConfigCallback& callback) { | 182 void DaemonControllerMac::DoGetConfig(const GetConfigCallback& callback) { |
| 171 FilePath config_path(kHostConfigFile); | 183 FilePath config_path(kHostConfigFile); |
| 172 JsonHostConfig host_config(config_path); | 184 JsonHostConfig host_config(config_path); |
| 173 scoped_ptr<base::DictionaryValue> config; | 185 scoped_ptr<base::DictionaryValue> config; |
| 174 | 186 |
| 175 if (host_config.Read()) { | 187 if (host_config.Read()) { |
| 176 config.reset(new base::DictionaryValue()); | 188 config.reset(new base::DictionaryValue()); |
| 177 std::string value; | 189 std::string value; |
| 178 if (host_config.GetString(kHostIdConfigPath, &value)) | 190 if (host_config.GetString(kHostIdConfigPath, &value)) |
| 179 config.get()->SetString(kHostIdConfigPath, value); | 191 config.get()->SetString(kHostIdConfigPath, value); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 203 } | 215 } |
| 204 } | 216 } |
| 205 version = result; | 217 version = result; |
| 206 } | 218 } |
| 207 } | 219 } |
| 208 callback.Run(version); | 220 callback.Run(version); |
| 209 } | 221 } |
| 210 | 222 |
| 211 void DaemonControllerMac::DoSetConfigAndStart( | 223 void DaemonControllerMac::DoSetConfigAndStart( |
| 212 scoped_ptr<base::DictionaryValue> config, | 224 scoped_ptr<base::DictionaryValue> config, |
| 213 const CompletionCallback& done_callback) { | 225 const CompletionCallback& done) { |
| 214 std::string config_data; | 226 std::string config_data; |
| 215 base::JSONWriter::Write(config.get(), &config_data); | 227 base::JSONWriter::Write(config.get(), &config_data); |
| 216 ShowPreferencePane(config_data, done_callback); | 228 ShowPreferencePane(config_data, done); |
| 217 } | 229 } |
| 218 | 230 |
| 219 void DaemonControllerMac::DoUpdateConfig( | 231 void DaemonControllerMac::DoUpdateConfig( |
| 220 scoped_ptr<base::DictionaryValue> config, | 232 scoped_ptr<base::DictionaryValue> config, |
| 221 const CompletionCallback& done_callback) { | 233 const CompletionCallback& done_callback) { |
| 222 FilePath config_file_path(kHostConfigFile); | 234 FilePath config_file_path(kHostConfigFile); |
| 223 JsonHostConfig config_file(config_file_path); | 235 JsonHostConfig config_file(config_file_path); |
| 224 if (!config_file.Read()) { | 236 if (!config_file.Read()) { |
| 225 done_callback.Run(RESULT_FAILED); | 237 done_callback.Run(RESULT_FAILED); |
| 226 return; | 238 return; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 371 } |
| 360 } | 372 } |
| 361 | 373 |
| 362 } // namespace | 374 } // namespace |
| 363 | 375 |
| 364 scoped_ptr<DaemonController> remoting::DaemonController::Create() { | 376 scoped_ptr<DaemonController> remoting::DaemonController::Create() { |
| 365 return scoped_ptr<DaemonController>(new DaemonControllerMac()); | 377 return scoped_ptr<DaemonController>(new DaemonControllerMac()); |
| 366 } | 378 } |
| 367 | 379 |
| 368 } // namespace remoting | 380 } // namespace remoting |
| OLD | NEW |