OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <CoreFoundation/CoreFoundation.h> | |
6 | |
7 #include "remoting/host/setup/daemon_controller_delegate_mac.h" | 5 #include "remoting/host/setup/daemon_controller_delegate_mac.h" |
8 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> |
9 #include <launch.h> | 8 #include <launch.h> |
10 #include <stdio.h> | 9 #include <stdio.h> |
11 #include <sys/types.h> | 10 #include <sys/types.h> |
12 | 11 |
13 #include "base/bind.h" | 12 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
15 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
20 #include "base/mac/launchd.h" | 19 #include "base/mac/launchd.h" |
21 #include "base/mac/mac_logging.h" | 20 #include "base/mac/mac_logging.h" |
22 #include "base/mac/mac_util.h" | 21 #include "base/mac/mac_util.h" |
23 #include "base/mac/scoped_launch_data.h" | 22 #include "base/mac/scoped_launch_data.h" |
| 23 #include "base/memory/ptr_util.h" |
24 #include "base/time/time.h" | 24 #include "base/time/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/host_config.h" | 27 #include "remoting/host/host_config.h" |
28 #include "remoting/host/usage_stats_consent.h" | 28 #include "remoting/host/usage_stats_consent.h" |
29 | 29 |
30 namespace remoting { | 30 namespace remoting { |
31 | 31 |
32 DaemonControllerDelegateMac::DaemonControllerDelegateMac() { | 32 DaemonControllerDelegateMac::DaemonControllerDelegateMac() { |
33 } | 33 } |
34 | 34 |
35 DaemonControllerDelegateMac::~DaemonControllerDelegateMac() { | 35 DaemonControllerDelegateMac::~DaemonControllerDelegateMac() { |
36 DeregisterForPreferencePaneNotifications(); | 36 DeregisterForPreferencePaneNotifications(); |
37 } | 37 } |
38 | 38 |
39 DaemonController::State DaemonControllerDelegateMac::GetState() { | 39 DaemonController::State DaemonControllerDelegateMac::GetState() { |
40 pid_t job_pid = base::mac::PIDForJob(kServiceName); | 40 pid_t job_pid = base::mac::PIDForJob(kServiceName); |
41 if (job_pid < 0) { | 41 if (job_pid < 0) { |
42 return DaemonController::STATE_UNKNOWN; | 42 return DaemonController::STATE_UNKNOWN; |
43 } else if (job_pid == 0) { | 43 } else if (job_pid == 0) { |
44 // Service is stopped, or a start attempt failed. | 44 // Service is stopped, or a start attempt failed. |
45 return DaemonController::STATE_STOPPED; | 45 return DaemonController::STATE_STOPPED; |
46 } else { | 46 } else { |
47 return DaemonController::STATE_STARTED; | 47 return DaemonController::STATE_STARTED; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 scoped_ptr<base::DictionaryValue> DaemonControllerDelegateMac::GetConfig() { | 51 std::unique_ptr<base::DictionaryValue> |
| 52 DaemonControllerDelegateMac::GetConfig() { |
52 base::FilePath config_path(kHostConfigFilePath); | 53 base::FilePath config_path(kHostConfigFilePath); |
53 scoped_ptr<base::DictionaryValue> host_config( | 54 std::unique_ptr<base::DictionaryValue> host_config( |
54 HostConfigFromJsonFile(config_path)); | 55 HostConfigFromJsonFile(config_path)); |
55 if (!host_config) | 56 if (!host_config) |
56 return nullptr; | 57 return nullptr; |
57 | 58 |
58 scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue); | 59 std::unique_ptr<base::DictionaryValue> config(new base::DictionaryValue); |
59 std::string value; | 60 std::string value; |
60 if (host_config->GetString(kHostIdConfigPath, &value)) | 61 if (host_config->GetString(kHostIdConfigPath, &value)) |
61 config->SetString(kHostIdConfigPath, value); | 62 config->SetString(kHostIdConfigPath, value); |
62 if (host_config->GetString(kXmppLoginConfigPath, &value)) | 63 if (host_config->GetString(kXmppLoginConfigPath, &value)) |
63 config->SetString(kXmppLoginConfigPath, value); | 64 config->SetString(kXmppLoginConfigPath, value); |
64 return config; | 65 return config; |
65 } | 66 } |
66 | 67 |
67 void DaemonControllerDelegateMac::SetConfigAndStart( | 68 void DaemonControllerDelegateMac::SetConfigAndStart( |
68 scoped_ptr<base::DictionaryValue> config, | 69 std::unique_ptr<base::DictionaryValue> config, |
69 bool consent, | 70 bool consent, |
70 const DaemonController::CompletionCallback& done) { | 71 const DaemonController::CompletionCallback& done) { |
71 config->SetBoolean(kUsageStatsConsentConfigPath, consent); | 72 config->SetBoolean(kUsageStatsConsentConfigPath, consent); |
72 ShowPreferencePane(HostConfigToJson(*config), done); | 73 ShowPreferencePane(HostConfigToJson(*config), done); |
73 } | 74 } |
74 | 75 |
75 void DaemonControllerDelegateMac::UpdateConfig( | 76 void DaemonControllerDelegateMac::UpdateConfig( |
76 scoped_ptr<base::DictionaryValue> config, | 77 std::unique_ptr<base::DictionaryValue> config, |
77 const DaemonController::CompletionCallback& done) { | 78 const DaemonController::CompletionCallback& done) { |
78 base::FilePath config_file_path(kHostConfigFilePath); | 79 base::FilePath config_file_path(kHostConfigFilePath); |
79 scoped_ptr<base::DictionaryValue> host_config( | 80 std::unique_ptr<base::DictionaryValue> host_config( |
80 HostConfigFromJsonFile(config_file_path)); | 81 HostConfigFromJsonFile(config_file_path)); |
81 if (!host_config) { | 82 if (!host_config) { |
82 done.Run(DaemonController::RESULT_FAILED); | 83 done.Run(DaemonController::RESULT_FAILED); |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
86 host_config->MergeDictionary(config.get()); | 87 host_config->MergeDictionary(config.get()); |
87 ShowPreferencePane(HostConfigToJson(*host_config), done); | 88 ShowPreferencePane(HostConfigToJson(*host_config), done); |
88 } | 89 } |
89 | 90 |
90 void DaemonControllerDelegateMac::Stop( | 91 void DaemonControllerDelegateMac::Stop( |
91 const DaemonController::CompletionCallback& done) { | 92 const DaemonController::CompletionCallback& done) { |
92 ShowPreferencePane("", done); | 93 ShowPreferencePane("", done); |
93 } | 94 } |
94 | 95 |
95 DaemonController::UsageStatsConsent | 96 DaemonController::UsageStatsConsent |
96 DaemonControllerDelegateMac::GetUsageStatsConsent() { | 97 DaemonControllerDelegateMac::GetUsageStatsConsent() { |
97 DaemonController::UsageStatsConsent consent; | 98 DaemonController::UsageStatsConsent consent; |
98 consent.supported = true; | 99 consent.supported = true; |
99 consent.allowed = false; | 100 consent.allowed = false; |
100 // set_by_policy is not yet supported. | 101 // set_by_policy is not yet supported. |
101 consent.set_by_policy = false; | 102 consent.set_by_policy = false; |
102 | 103 |
103 base::FilePath config_file_path(kHostConfigFilePath); | 104 base::FilePath config_file_path(kHostConfigFilePath); |
104 scoped_ptr<base::DictionaryValue> host_config( | 105 std::unique_ptr<base::DictionaryValue> host_config( |
105 HostConfigFromJsonFile(config_file_path)); | 106 HostConfigFromJsonFile(config_file_path)); |
106 if (host_config) { | 107 if (host_config) { |
107 host_config->GetBoolean(kUsageStatsConsentConfigPath, &consent.allowed); | 108 host_config->GetBoolean(kUsageStatsConsentConfigPath, &consent.allowed); |
108 } | 109 } |
109 | 110 |
110 return consent; | 111 return consent; |
111 } | 112 } |
112 | 113 |
113 void DaemonControllerDelegateMac::ShowPreferencePane( | 114 void DaemonControllerDelegateMac::ShowPreferencePane( |
114 const std::string& config_data, | 115 const std::string& config_data, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (!self) { | 244 if (!self) { |
244 LOG(WARNING) << "Ignoring notification with nullptr observer: " << name; | 245 LOG(WARNING) << "Ignoring notification with nullptr observer: " << name; |
245 return; | 246 return; |
246 } | 247 } |
247 | 248 |
248 self->PreferencePaneCallbackDelegate(name); | 249 self->PreferencePaneCallbackDelegate(name); |
249 } | 250 } |
250 | 251 |
251 scoped_refptr<DaemonController> DaemonController::Create() { | 252 scoped_refptr<DaemonController> DaemonController::Create() { |
252 return new DaemonController( | 253 return new DaemonController( |
253 make_scoped_ptr(new DaemonControllerDelegateMac())); | 254 base::WrapUnique(new DaemonControllerDelegateMac())); |
254 } | 255 } |
255 | 256 |
256 } // namespace remoting | 257 } // namespace remoting |
OLD | NEW |