Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/cast_devices_private/cast_devices_privat e_api.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/common/extensions/api/cast_devices_private.h" | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 ash::CastConfigDelegate::Receiver ConvertReceiverType( | |
| 16 const api::cast_devices_private::Receiver& receiver) { | |
| 17 ash::CastConfigDelegate::Receiver result; | |
| 18 result.id = receiver.id; | |
| 19 result.name = base::UTF8ToUTF16(receiver.name); | |
| 20 return result; | |
| 21 } | |
| 22 | |
| 23 ash::CastConfigDelegate::Activity ConvertActivityType( | |
| 24 const api::cast_devices_private::Activity& activity) { | |
| 25 ash::CastConfigDelegate::Activity result; | |
| 26 result.id = activity.id; | |
| 27 result.title = base::UTF8ToUTF16(activity.title); | |
| 28 result.tab_id = activity.tab_id; | |
| 29 return result; | |
| 30 } | |
| 31 | |
| 32 ash::CastConfigDelegate::ReceiverAndActivity ConvertReceiverAndActivityType( | |
| 33 const api::cast_devices_private::Receiver& receiver, | |
| 34 const api::cast_devices_private::Activity* activity) { | |
| 35 ash::CastConfigDelegate::ReceiverAndActivity result; | |
| 36 result.receiver = ConvertReceiverType(receiver); | |
| 37 if (activity) | |
| 38 result.activity = ConvertActivityType(*activity); | |
| 39 return result; | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 static base::LazyInstance< | |
| 45 BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>> g_factory = | |
| 46 LAZY_INSTANCE_INITIALIZER; | |
| 47 | |
| 48 // static | |
| 49 BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* | |
| 50 CastDeviceUpdateListeners::GetFactoryInstance() { | |
| 51 return g_factory.Pointer(); | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 CastDeviceUpdateListeners* CastDeviceUpdateListeners::Get( | |
| 56 content::BrowserContext* context) { | |
| 57 return BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>::Get(context); | |
| 58 } | |
| 59 | |
| 60 CastDeviceUpdateListeners::CastDeviceUpdateListeners( | |
| 61 content::BrowserContext* context) {} | |
| 62 | |
| 63 CastDeviceUpdateListeners::~CastDeviceUpdateListeners() {} | |
| 64 | |
| 65 ash::CastConfigDelegate::DeviceUpdateSubscription | |
| 66 CastDeviceUpdateListeners::RegisterCallback( | |
| 67 const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback) { | |
| 68 return callback_list_.Add(callback); | |
| 69 } | |
| 70 | |
| 71 void CastDeviceUpdateListeners::NotifyCallbacks( | |
| 72 const CastDeviceUpdateListeners::ReceiverAndActivityList& devices) { | |
|
achuithb
2015/08/18 22:30:14
Do you actually need CastDeviceUpdateListeners:: i
jdufault
2015/08/18 23:31:52
Done.
| |
| 73 callback_list_.Notify(devices); | |
| 74 } | |
| 75 | |
| 76 CastDevicesPrivateUpdateDevicesFunction:: | |
| 77 CastDevicesPrivateUpdateDevicesFunction() {} | |
| 78 | |
| 79 CastDevicesPrivateUpdateDevicesFunction:: | |
| 80 ~CastDevicesPrivateUpdateDevicesFunction() {} | |
| 81 | |
| 82 ExtensionFunction::ResponseAction | |
| 83 CastDevicesPrivateUpdateDevicesFunction::Run() { | |
| 84 auto params = | |
| 85 api::cast_devices_private::UpdateDevices::Params::Create(*args_); | |
| 86 | |
| 87 CastDeviceUpdateListeners::ReceiverAndActivityList devices; | |
| 88 for (linked_ptr<api::cast_devices_private::ReceiverActivity> device : | |
| 89 params->devices) { | |
| 90 devices.push_back(ConvertReceiverAndActivityType(device->receiver, | |
| 91 device->activity.get())); | |
| 92 } | |
| 93 | |
| 94 auto storage = CastDeviceUpdateListeners::Get(browser_context()); | |
|
achuithb
2015/08/18 22:30:14
why storage instead of say listeners?
jdufault
2015/08/18 23:31:51
Done.
| |
| 95 storage->NotifyCallbacks(devices); | |
| 96 | |
| 97 return RespondNow(NoArguments()); | |
| 98 } | |
| 99 | |
| 100 } // namespace extensions | |
| OLD | NEW |