| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" | 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const SessionCallback& callback); | 66 const SessionCallback& callback); |
| 67 | 67 |
| 68 void SendMessage(int session_id, | 68 void SendMessage(int session_id, |
| 69 const std::string& api, | 69 const std::string& api, |
| 70 const base::DictionaryValue& input, | 70 const base::DictionaryValue& input, |
| 71 const MessageResponseCallback& callback); | 71 const MessageResponseCallback& callback); |
| 72 | 72 |
| 73 void RemoveSession(int session_id); | 73 void RemoveSession(int session_id); |
| 74 void RemoveSessionDelayed(int session_id); | 74 void RemoveSessionDelayed(int session_id); |
| 75 | 75 |
| 76 scoped_ptr<base::ListValue> GetPrefetchedSSIDList(); | 76 std::unique_ptr<base::ListValue> GetPrefetchedSSIDList(); |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 typedef std::map<std::string /* ssid */, std::string /* password */> | 79 typedef std::map<std::string /* ssid */, std::string /* password */> |
| 80 PasswordMap; | 80 PasswordMap; |
| 81 | 81 |
| 82 void SendMessageInternal(int session_id, | 82 void SendMessageInternal(int session_id, |
| 83 const std::string& api, | 83 const std::string& api, |
| 84 const base::DictionaryValue& input, | 84 const base::DictionaryValue& input, |
| 85 const MessageResponseCallback& callback); | 85 const MessageResponseCallback& callback); |
| 86 | 86 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR); | 172 return callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR); |
| 173 | 173 |
| 174 found->second.session->ConfirmCode(code, callback); | 174 found->second.session->ConfirmCode(code, callback); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GcdPrivateAPIImpl::SendMessage(int session_id, | 177 void GcdPrivateAPIImpl::SendMessage(int session_id, |
| 178 const std::string& api, | 178 const std::string& api, |
| 179 const base::DictionaryValue& input, | 179 const base::DictionaryValue& input, |
| 180 const MessageResponseCallback& callback) { | 180 const MessageResponseCallback& callback) { |
| 181 const base::DictionaryValue* input_actual = &input; | 181 const base::DictionaryValue* input_actual = &input; |
| 182 scoped_ptr<base::DictionaryValue> input_cloned; | 182 std::unique_ptr<base::DictionaryValue> input_cloned; |
| 183 | 183 |
| 184 if (api == kPrivatAPISetup) { | 184 if (api == kPrivatAPISetup) { |
| 185 const base::DictionaryValue* wifi = NULL; | 185 const base::DictionaryValue* wifi = NULL; |
| 186 | 186 |
| 187 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) { | 187 if (input.GetDictionary(kPrivetKeyWifi, &wifi)) { |
| 188 std::string ssid; | 188 std::string ssid; |
| 189 | 189 |
| 190 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { | 190 if (!wifi->GetString(kPrivetKeySSID, &ssid)) { |
| 191 LOG(ERROR) << "Missing " << kPrivetKeySSID; | 191 LOG(ERROR) << "Missing " << kPrivetKeySSID; |
| 192 return callback.Run(gcd_private::STATUS_SETUPPARSEERROR, | 192 return callback.Run(gcd_private::STATUS_SETUPPARSEERROR, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 214 void GcdPrivateAPIImpl::RemoveSession(int session_id) { | 214 void GcdPrivateAPIImpl::RemoveSession(int session_id) { |
| 215 sessions_.erase(session_id); | 215 sessions_.erase(session_id); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void GcdPrivateAPIImpl::RemoveSessionDelayed(int session_id) { | 218 void GcdPrivateAPIImpl::RemoveSessionDelayed(int session_id) { |
| 219 base::ThreadTaskRunnerHandle::Get()->PostTask( | 219 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 220 FROM_HERE, base::Bind(&GcdPrivateAPIImpl::RemoveSession, | 220 FROM_HERE, base::Bind(&GcdPrivateAPIImpl::RemoveSession, |
| 221 weak_ptr_factory_.GetWeakPtr(), session_id)); | 221 weak_ptr_factory_.GetWeakPtr(), session_id)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 scoped_ptr<base::ListValue> GcdPrivateAPIImpl::GetPrefetchedSSIDList() { | 224 std::unique_ptr<base::ListValue> GcdPrivateAPIImpl::GetPrefetchedSSIDList() { |
| 225 scoped_ptr<base::ListValue> retval(new base::ListValue); | 225 std::unique_ptr<base::ListValue> retval(new base::ListValue); |
| 226 | 226 |
| 227 return retval; | 227 return retval; |
| 228 } | 228 } |
| 229 | 229 |
| 230 | 230 |
| 231 | 231 |
| 232 GcdPrivateAPI::GcdPrivateAPI(content::BrowserContext* context) | 232 GcdPrivateAPI::GcdPrivateAPI(content::BrowserContext* context) |
| 233 : impl_(new GcdPrivateAPIImpl(context)) { | 233 : impl_(new GcdPrivateAPIImpl(context)) { |
| 234 } | 234 } |
| 235 | 235 |
| 236 GcdPrivateAPI::~GcdPrivateAPI() { | 236 GcdPrivateAPI::~GcdPrivateAPI() { |
| 237 } | 237 } |
| 238 | 238 |
| 239 // static | 239 // static |
| 240 BrowserContextKeyedAPIFactory<GcdPrivateAPI>* | 240 BrowserContextKeyedAPIFactory<GcdPrivateAPI>* |
| 241 GcdPrivateAPI::GetFactoryInstance() { | 241 GcdPrivateAPI::GetFactoryInstance() { |
| 242 return g_factory.Pointer(); | 242 return g_factory.Pointer(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 GcdPrivateGetDeviceInfoFunction::GcdPrivateGetDeviceInfoFunction() { | 245 GcdPrivateGetDeviceInfoFunction::GcdPrivateGetDeviceInfoFunction() { |
| 246 } | 246 } |
| 247 | 247 |
| 248 GcdPrivateGetDeviceInfoFunction::~GcdPrivateGetDeviceInfoFunction() { | 248 GcdPrivateGetDeviceInfoFunction::~GcdPrivateGetDeviceInfoFunction() { |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool GcdPrivateGetDeviceInfoFunction::RunAsync() { | 251 bool GcdPrivateGetDeviceInfoFunction::RunAsync() { |
| 252 scoped_ptr<gcd_private::CreateSession::Params> params = | 252 std::unique_ptr<gcd_private::CreateSession::Params> params = |
| 253 gcd_private::CreateSession::Params::Create(*args_); | 253 gcd_private::CreateSession::Params::Create(*args_); |
| 254 | 254 |
| 255 if (!params) | 255 if (!params) |
| 256 return false; | 256 return false; |
| 257 | 257 |
| 258 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 258 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 259 | 259 |
| 260 GcdPrivateAPIImpl::CreateSessionCallback callback = | 260 GcdPrivateAPIImpl::CreateSessionCallback callback = |
| 261 base::Bind(&GcdPrivateGetDeviceInfoFunction::OnSessionInitialized, this); | 261 base::Bind(&GcdPrivateGetDeviceInfoFunction::OnSessionInitialized, this); |
| 262 gcd_api->CreateSession(params->service_name, callback); | 262 gcd_api->CreateSession(params->service_name, callback); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 278 gcd_api->RemoveSessionDelayed(session_id); | 278 gcd_api->RemoveSessionDelayed(session_id); |
| 279 } | 279 } |
| 280 | 280 |
| 281 GcdPrivateCreateSessionFunction::GcdPrivateCreateSessionFunction() { | 281 GcdPrivateCreateSessionFunction::GcdPrivateCreateSessionFunction() { |
| 282 } | 282 } |
| 283 | 283 |
| 284 GcdPrivateCreateSessionFunction::~GcdPrivateCreateSessionFunction() { | 284 GcdPrivateCreateSessionFunction::~GcdPrivateCreateSessionFunction() { |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool GcdPrivateCreateSessionFunction::RunAsync() { | 287 bool GcdPrivateCreateSessionFunction::RunAsync() { |
| 288 scoped_ptr<gcd_private::CreateSession::Params> params = | 288 std::unique_ptr<gcd_private::CreateSession::Params> params = |
| 289 gcd_private::CreateSession::Params::Create(*args_); | 289 gcd_private::CreateSession::Params::Create(*args_); |
| 290 | 290 |
| 291 if (!params) | 291 if (!params) |
| 292 return false; | 292 return false; |
| 293 | 293 |
| 294 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 294 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 295 | 295 |
| 296 GcdPrivateAPIImpl::CreateSessionCallback callback = | 296 GcdPrivateAPIImpl::CreateSessionCallback callback = |
| 297 base::Bind(&GcdPrivateCreateSessionFunction::OnSessionInitialized, this); | 297 base::Bind(&GcdPrivateCreateSessionFunction::OnSessionInitialized, this); |
| 298 gcd_api->CreateSession(params->service_name, callback); | 298 gcd_api->CreateSession(params->service_name, callback); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 329 SendResponse(true); | 329 SendResponse(true); |
| 330 } | 330 } |
| 331 | 331 |
| 332 GcdPrivateStartPairingFunction::GcdPrivateStartPairingFunction() { | 332 GcdPrivateStartPairingFunction::GcdPrivateStartPairingFunction() { |
| 333 } | 333 } |
| 334 | 334 |
| 335 GcdPrivateStartPairingFunction::~GcdPrivateStartPairingFunction() { | 335 GcdPrivateStartPairingFunction::~GcdPrivateStartPairingFunction() { |
| 336 } | 336 } |
| 337 | 337 |
| 338 bool GcdPrivateStartPairingFunction::RunAsync() { | 338 bool GcdPrivateStartPairingFunction::RunAsync() { |
| 339 scoped_ptr<gcd_private::StartPairing::Params> params = | 339 std::unique_ptr<gcd_private::StartPairing::Params> params = |
| 340 gcd_private::StartPairing::Params::Create(*args_); | 340 gcd_private::StartPairing::Params::Create(*args_); |
| 341 | 341 |
| 342 if (!params) | 342 if (!params) |
| 343 return false; | 343 return false; |
| 344 | 344 |
| 345 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 345 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 346 | 346 |
| 347 gcd_api->StartPairing( | 347 gcd_api->StartPairing( |
| 348 params->session_id, params->pairing_type, | 348 params->session_id, params->pairing_type, |
| 349 base::Bind(&GcdPrivateStartPairingFunction::OnPairingStarted, this)); | 349 base::Bind(&GcdPrivateStartPairingFunction::OnPairingStarted, this)); |
| 350 | 350 |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 | 353 |
| 354 void GcdPrivateStartPairingFunction::OnPairingStarted( | 354 void GcdPrivateStartPairingFunction::OnPairingStarted( |
| 355 api::gcd_private::Status status) { | 355 api::gcd_private::Status status) { |
| 356 results_ = gcd_private::StartPairing::Results::Create(status); | 356 results_ = gcd_private::StartPairing::Results::Create(status); |
| 357 SendResponse(true); | 357 SendResponse(true); |
| 358 } | 358 } |
| 359 | 359 |
| 360 GcdPrivateConfirmCodeFunction::GcdPrivateConfirmCodeFunction() { | 360 GcdPrivateConfirmCodeFunction::GcdPrivateConfirmCodeFunction() { |
| 361 } | 361 } |
| 362 | 362 |
| 363 GcdPrivateConfirmCodeFunction::~GcdPrivateConfirmCodeFunction() { | 363 GcdPrivateConfirmCodeFunction::~GcdPrivateConfirmCodeFunction() { |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool GcdPrivateConfirmCodeFunction::RunAsync() { | 366 bool GcdPrivateConfirmCodeFunction::RunAsync() { |
| 367 scoped_ptr<gcd_private::ConfirmCode::Params> params = | 367 std::unique_ptr<gcd_private::ConfirmCode::Params> params = |
| 368 gcd_private::ConfirmCode::Params::Create(*args_); | 368 gcd_private::ConfirmCode::Params::Create(*args_); |
| 369 | 369 |
| 370 if (!params) | 370 if (!params) |
| 371 return false; | 371 return false; |
| 372 | 372 |
| 373 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 373 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 374 | 374 |
| 375 gcd_api->ConfirmCode( | 375 gcd_api->ConfirmCode( |
| 376 params->session_id, params->code, | 376 params->session_id, params->code, |
| 377 base::Bind(&GcdPrivateConfirmCodeFunction::OnCodeConfirmed, this)); | 377 base::Bind(&GcdPrivateConfirmCodeFunction::OnCodeConfirmed, this)); |
| 378 | 378 |
| 379 return true; | 379 return true; |
| 380 } | 380 } |
| 381 | 381 |
| 382 void GcdPrivateConfirmCodeFunction::OnCodeConfirmed( | 382 void GcdPrivateConfirmCodeFunction::OnCodeConfirmed( |
| 383 api::gcd_private::Status status) { | 383 api::gcd_private::Status status) { |
| 384 results_ = gcd_private::ConfirmCode::Results::Create(status); | 384 results_ = gcd_private::ConfirmCode::Results::Create(status); |
| 385 SendResponse(true); | 385 SendResponse(true); |
| 386 } | 386 } |
| 387 | 387 |
| 388 GcdPrivateSendMessageFunction::GcdPrivateSendMessageFunction() { | 388 GcdPrivateSendMessageFunction::GcdPrivateSendMessageFunction() { |
| 389 } | 389 } |
| 390 | 390 |
| 391 GcdPrivateSendMessageFunction::~GcdPrivateSendMessageFunction() { | 391 GcdPrivateSendMessageFunction::~GcdPrivateSendMessageFunction() { |
| 392 } | 392 } |
| 393 | 393 |
| 394 bool GcdPrivateSendMessageFunction::RunAsync() { | 394 bool GcdPrivateSendMessageFunction::RunAsync() { |
| 395 scoped_ptr<gcd_private::PassMessage::Params> params = | 395 std::unique_ptr<gcd_private::PassMessage::Params> params = |
| 396 gcd_private::PassMessage::Params::Create(*args_); | 396 gcd_private::PassMessage::Params::Create(*args_); |
| 397 | 397 |
| 398 if (!params) | 398 if (!params) |
| 399 return false; | 399 return false; |
| 400 | 400 |
| 401 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 401 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 402 | 402 |
| 403 | 403 |
| 404 gcd_api->SendMessage( | 404 gcd_api->SendMessage( |
| 405 params->session_id, | 405 params->session_id, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 420 SendResponse(true); | 420 SendResponse(true); |
| 421 } | 421 } |
| 422 | 422 |
| 423 GcdPrivateTerminateSessionFunction::GcdPrivateTerminateSessionFunction() { | 423 GcdPrivateTerminateSessionFunction::GcdPrivateTerminateSessionFunction() { |
| 424 } | 424 } |
| 425 | 425 |
| 426 GcdPrivateTerminateSessionFunction::~GcdPrivateTerminateSessionFunction() { | 426 GcdPrivateTerminateSessionFunction::~GcdPrivateTerminateSessionFunction() { |
| 427 } | 427 } |
| 428 | 428 |
| 429 bool GcdPrivateTerminateSessionFunction::RunAsync() { | 429 bool GcdPrivateTerminateSessionFunction::RunAsync() { |
| 430 scoped_ptr<gcd_private::TerminateSession::Params> params = | 430 std::unique_ptr<gcd_private::TerminateSession::Params> params = |
| 431 gcd_private::TerminateSession::Params::Create(*args_); | 431 gcd_private::TerminateSession::Params::Create(*args_); |
| 432 | 432 |
| 433 if (!params) | 433 if (!params) |
| 434 return false; | 434 return false; |
| 435 | 435 |
| 436 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 436 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 437 | 437 |
| 438 gcd_api->RemoveSession(params->session_id); | 438 gcd_api->RemoveSession(params->session_id); |
| 439 | 439 |
| 440 SendResponse(true); | 440 SendResponse(true); |
| 441 return true; | 441 return true; |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace extensions | 444 } // namespace extensions |
| OLD | NEW |