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 "remoting/host/setup/native_messaging_host.h" | 5 #include "remoting/host/setup/native_messaging_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const base::DictionaryValue& message, | 143 const base::DictionaryValue& message, |
144 scoped_ptr<base::DictionaryValue> response) { | 144 scoped_ptr<base::DictionaryValue> response) { |
145 response->SetString("version", STRINGIZE(VERSION)); | 145 response->SetString("version", STRINGIZE(VERSION)); |
146 SendResponse(response.Pass()); | 146 SendResponse(response.Pass()); |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 bool NativeMessagingHost::ProcessClearPairedClients( | 150 bool NativeMessagingHost::ProcessClearPairedClients( |
151 const base::DictionaryValue& message, | 151 const base::DictionaryValue& message, |
152 scoped_ptr<base::DictionaryValue> response) { | 152 scoped_ptr<base::DictionaryValue> response) { |
153 pairing_registry_->ClearAllPairings( | 153 if (pairing_registry_) { |
154 base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_, | 154 pairing_registry_->ClearAllPairings( |
155 base::Passed(&response))); | 155 base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_, |
| 156 base::Passed(&response))); |
| 157 } else { |
| 158 SendBooleanResult(response.Pass(), false); |
| 159 } |
156 return true; | 160 return true; |
157 } | 161 } |
158 | 162 |
159 bool NativeMessagingHost::ProcessDeletePairedClient( | 163 bool NativeMessagingHost::ProcessDeletePairedClient( |
160 const base::DictionaryValue& message, | 164 const base::DictionaryValue& message, |
161 scoped_ptr<base::DictionaryValue> response) { | 165 scoped_ptr<base::DictionaryValue> response) { |
162 std::string client_id; | 166 std::string client_id; |
163 if (!message.GetString(protocol::PairingRegistry::kClientIdKey, &client_id)) { | 167 if (!message.GetString(protocol::PairingRegistry::kClientIdKey, &client_id)) { |
164 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey | 168 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey |
165 << "' string not found."; | 169 << "' string not found."; |
166 return false; | 170 return false; |
167 } | 171 } |
168 | 172 |
169 pairing_registry_->DeletePairing( | 173 if (pairing_registry_) { |
170 client_id, base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_, | 174 pairing_registry_->DeletePairing( |
171 base::Passed(&response))); | 175 client_id, base::Bind(&NativeMessagingHost::SendBooleanResult, |
| 176 weak_ptr_, base::Passed(&response))); |
| 177 } else { |
| 178 SendBooleanResult(response.Pass(), false); |
| 179 } |
172 return true; | 180 return true; |
173 } | 181 } |
174 | 182 |
175 bool NativeMessagingHost::ProcessGetHostName( | 183 bool NativeMessagingHost::ProcessGetHostName( |
176 const base::DictionaryValue& message, | 184 const base::DictionaryValue& message, |
177 scoped_ptr<base::DictionaryValue> response) { | 185 scoped_ptr<base::DictionaryValue> response) { |
178 response->SetString("hostname", net::GetHostName()); | 186 response->SetString("hostname", net::GetHostName()); |
179 SendResponse(response.Pass()); | 187 SendResponse(response.Pass()); |
180 return true; | 188 return true; |
181 } | 189 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 scoped_ptr<base::DictionaryValue> response) { | 238 scoped_ptr<base::DictionaryValue> response) { |
231 daemon_controller_->GetConfig( | 239 daemon_controller_->GetConfig( |
232 base::Bind(&NativeMessagingHost::SendConfigResponse, | 240 base::Bind(&NativeMessagingHost::SendConfigResponse, |
233 base::Unretained(this), base::Passed(&response))); | 241 base::Unretained(this), base::Passed(&response))); |
234 return true; | 242 return true; |
235 } | 243 } |
236 | 244 |
237 bool NativeMessagingHost::ProcessGetPairedClients( | 245 bool NativeMessagingHost::ProcessGetPairedClients( |
238 const base::DictionaryValue& message, | 246 const base::DictionaryValue& message, |
239 scoped_ptr<base::DictionaryValue> response) { | 247 scoped_ptr<base::DictionaryValue> response) { |
240 pairing_registry_->GetAllPairings( | 248 if (pairing_registry_) { |
241 base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_, | 249 pairing_registry_->GetAllPairings( |
242 base::Passed(&response))); | 250 base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_, |
| 251 base::Passed(&response))); |
| 252 } else { |
| 253 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); |
| 254 SendPairedClientsResponse(response.Pass(), no_paired_clients.Pass()); |
| 255 } |
243 return true; | 256 return true; |
244 } | 257 } |
245 | 258 |
246 bool NativeMessagingHost::ProcessGetUsageStatsConsent( | 259 bool NativeMessagingHost::ProcessGetUsageStatsConsent( |
247 const base::DictionaryValue& message, | 260 const base::DictionaryValue& message, |
248 scoped_ptr<base::DictionaryValue> response) { | 261 scoped_ptr<base::DictionaryValue> response) { |
249 daemon_controller_->GetUsageStatsConsent( | 262 daemon_controller_->GetUsageStatsConsent( |
250 base::Bind(&NativeMessagingHost::SendUsageStatsConsentResponse, | 263 base::Bind(&NativeMessagingHost::SendUsageStatsConsentResponse, |
251 base::Unretained(this), base::Passed(&response))); | 264 base::Unretained(this), base::Passed(&response))); |
252 return true; | 265 return true; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 SendResponse(response.Pass()); | 391 SendResponse(response.Pass()); |
379 } | 392 } |
380 | 393 |
381 void NativeMessagingHost::SendBooleanResult( | 394 void NativeMessagingHost::SendBooleanResult( |
382 scoped_ptr<base::DictionaryValue> response, bool result) { | 395 scoped_ptr<base::DictionaryValue> response, bool result) { |
383 response->SetBoolean("result", result); | 396 response->SetBoolean("result", result); |
384 SendResponse(response.Pass()); | 397 SendResponse(response.Pass()); |
385 } | 398 } |
386 | 399 |
387 } // namespace remoting | 400 } // namespace remoting |
OLD | NEW |