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/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
bluetooth_util.h" | 11 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
bluetooth_util.h" |
12 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" | 12 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/signin/easy_unlock_service.h" |
13 #include "chrome/common/extensions/api/easy_unlock_private.h" | 15 #include "chrome/common/extensions/api/easy_unlock_private.h" |
14 #include "extensions/browser/browser_context_keyed_api_factory.h" | 16 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 17 #include "extensions/browser/event_router.h" |
15 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
17 | 20 |
18 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
19 #include "chrome/browser/chromeos/chromeos_utils.h" | 22 #include "chrome/browser/chromeos/chromeos_utils.h" |
20 #endif | 23 #endif |
21 | 24 |
22 namespace extensions { | 25 namespace extensions { |
23 namespace api { | 26 namespace api { |
24 | 27 |
(...skipping 11 matching lines...) Expand all Loading... |
36 | 39 |
37 } // namespace | 40 } // namespace |
38 | 41 |
39 // static | 42 // static |
40 BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* | 43 BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* |
41 EasyUnlockPrivateAPI::GetFactoryInstance() { | 44 EasyUnlockPrivateAPI::GetFactoryInstance() { |
42 return g_factory.Pointer(); | 45 return g_factory.Pointer(); |
43 } | 46 } |
44 | 47 |
45 EasyUnlockPrivateAPI::EasyUnlockPrivateAPI(content::BrowserContext* context) | 48 EasyUnlockPrivateAPI::EasyUnlockPrivateAPI(content::BrowserContext* context) |
46 : crypto_delegate_(EasyUnlockPrivateCryptoDelegate::Create()) { | 49 : browser_context_(context), |
| 50 crypto_delegate_(EasyUnlockPrivateCryptoDelegate::Create()) { |
47 } | 51 } |
48 | 52 |
49 EasyUnlockPrivateAPI::~EasyUnlockPrivateAPI() {} | 53 EasyUnlockPrivateAPI::~EasyUnlockPrivateAPI() {} |
50 | 54 |
| 55 void EasyUnlockPrivateAPI::SendTurnOffFlowFinished() { |
| 56 using easy_unlock_private::OnTurnOffFlowFinished::kEventName; |
| 57 EventRouter* router = EventRouter::Get(browser_context_); |
| 58 if (!router || !router->HasEventListener(kEventName)) |
| 59 return; |
| 60 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 61 scoped_ptr<Event> event(new Event(kEventName, args.Pass())); |
| 62 router->BroadcastEvent(event.Pass()); |
| 63 } |
| 64 |
51 EasyUnlockPrivateGetStringsFunction::EasyUnlockPrivateGetStringsFunction() { | 65 EasyUnlockPrivateGetStringsFunction::EasyUnlockPrivateGetStringsFunction() { |
52 } | 66 } |
53 EasyUnlockPrivateGetStringsFunction::~EasyUnlockPrivateGetStringsFunction() { | 67 EasyUnlockPrivateGetStringsFunction::~EasyUnlockPrivateGetStringsFunction() { |
54 } | 68 } |
55 | 69 |
56 bool EasyUnlockPrivateGetStringsFunction::RunSync() { | 70 bool EasyUnlockPrivateGetStringsFunction::RunSync() { |
57 scoped_ptr<base::DictionaryValue> strings(new base::DictionaryValue); | 71 scoped_ptr<base::DictionaryValue> strings(new base::DictionaryValue); |
58 | 72 |
59 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
60 const base::string16 device_type = chromeos::GetChromeDeviceType(); | 74 const base::string16 device_type = chromeos::GetChromeDeviceType(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( | 375 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( |
362 const easy_unlock::SeekDeviceResult& seek_result) { | 376 const easy_unlock::SeekDeviceResult& seek_result) { |
363 if (seek_result.success) { | 377 if (seek_result.success) { |
364 SendResponse(true); | 378 SendResponse(true); |
365 } else { | 379 } else { |
366 SetError(seek_result.error_message); | 380 SetError(seek_result.error_message); |
367 SendResponse(false); | 381 SendResponse(false); |
368 } | 382 } |
369 } | 383 } |
370 | 384 |
| 385 EasyUnlockPrivateSetPermitAccessFunction:: |
| 386 EasyUnlockPrivateSetPermitAccessFunction() { |
| 387 } |
| 388 |
| 389 EasyUnlockPrivateSetPermitAccessFunction:: |
| 390 ~EasyUnlockPrivateSetPermitAccessFunction() { |
| 391 } |
| 392 |
| 393 bool EasyUnlockPrivateSetPermitAccessFunction::RunSync() { |
| 394 scoped_ptr<easy_unlock_private::SetPermitAccess::Params> params( |
| 395 easy_unlock_private::SetPermitAccess::Params::Create(*args_)); |
| 396 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 397 |
| 398 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 399 EasyUnlockService::Get(profile) |
| 400 ->SetPermitAccess(*params->permit_access.ToValue()); |
| 401 |
| 402 return true; |
| 403 } |
| 404 |
| 405 EasyUnlockPrivateGetPermitAccessFunction:: |
| 406 EasyUnlockPrivateGetPermitAccessFunction() { |
| 407 } |
| 408 |
| 409 EasyUnlockPrivateGetPermitAccessFunction:: |
| 410 ~EasyUnlockPrivateGetPermitAccessFunction() { |
| 411 } |
| 412 |
| 413 bool EasyUnlockPrivateGetPermitAccessFunction::RunSync() { |
| 414 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 415 const base::DictionaryValue* permit_value = |
| 416 EasyUnlockService::Get(profile)->GetPermitAccess(); |
| 417 if (permit_value) { |
| 418 scoped_ptr<easy_unlock_private::PermitRecord> permit = |
| 419 easy_unlock_private::PermitRecord::FromValue(*permit_value); |
| 420 results_ = easy_unlock_private::GetPermitAccess::Results::Create(*permit); |
| 421 } |
| 422 |
| 423 return true; |
| 424 } |
| 425 |
| 426 EasyUnlockPrivateClearPermitAccessFunction:: |
| 427 EasyUnlockPrivateClearPermitAccessFunction() { |
| 428 } |
| 429 |
| 430 EasyUnlockPrivateClearPermitAccessFunction:: |
| 431 ~EasyUnlockPrivateClearPermitAccessFunction() { |
| 432 } |
| 433 |
| 434 bool EasyUnlockPrivateClearPermitAccessFunction::RunSync() { |
| 435 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 436 EasyUnlockService::Get(profile)->ClearPermitAccess(); |
| 437 return true; |
| 438 } |
| 439 |
| 440 EasyUnlockPrivateSetRemoteDevicesFunction:: |
| 441 EasyUnlockPrivateSetRemoteDevicesFunction() { |
| 442 } |
| 443 |
| 444 EasyUnlockPrivateSetRemoteDevicesFunction:: |
| 445 ~EasyUnlockPrivateSetRemoteDevicesFunction() { |
| 446 } |
| 447 |
| 448 bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() { |
| 449 scoped_ptr<easy_unlock_private::SetRemoteDevices::Params> params( |
| 450 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); |
| 451 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 452 |
| 453 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 454 if (params->devices.empty()) { |
| 455 EasyUnlockService::Get(profile)->ClearRemoteDevices(); |
| 456 } else { |
| 457 base::ListValue devices; |
| 458 for (size_t i = 0; i < params->devices.size(); ++i) { |
| 459 devices.Append(params->devices[i]->ToValue().release()); |
| 460 } |
| 461 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); |
| 462 } |
| 463 |
| 464 return true; |
| 465 } |
| 466 |
| 467 EasyUnlockPrivateGetRemoteDevicesFunction:: |
| 468 EasyUnlockPrivateGetRemoteDevicesFunction() { |
| 469 } |
| 470 |
| 471 EasyUnlockPrivateGetRemoteDevicesFunction:: |
| 472 ~EasyUnlockPrivateGetRemoteDevicesFunction() { |
| 473 } |
| 474 |
| 475 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { |
| 476 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 477 const base::ListValue* devices = |
| 478 EasyUnlockService::Get(profile)->GetRemoteDevices(); |
| 479 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); |
| 480 return true; |
| 481 } |
| 482 |
371 } // namespace api | 483 } // namespace api |
372 } // namespace extensions | 484 } // namespace extensions |
OLD | NEW |