Index: chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc |
diff --git a/chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc b/chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..017e333ac7e8c94cae2d0e529beb97d36c602b09 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc |
@@ -0,0 +1,100 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.h" |
+ |
+#include "base/lazy_instance.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/common/extensions/api/cast_devices_private.h" |
+ |
+namespace extensions { |
+ |
+namespace { |
+ |
+ash::CastConfigDelegate::Receiver ConvertReceiverType( |
+ const api::cast_devices_private::Receiver& receiver) { |
+ ash::CastConfigDelegate::Receiver result; |
+ result.id = receiver.id; |
+ result.name = base::UTF8ToUTF16(receiver.name); |
+ return result; |
+} |
+ |
+ash::CastConfigDelegate::Activity ConvertActivityType( |
+ const api::cast_devices_private::Activity& activity) { |
+ ash::CastConfigDelegate::Activity result; |
+ result.id = activity.id; |
+ result.title = base::UTF8ToUTF16(activity.title); |
+ result.tab_id = activity.tab_id; |
+ return result; |
+} |
+ |
+ash::CastConfigDelegate::ReceiverAndActivity ConvertReceiverAndActivityType( |
+ const api::cast_devices_private::Receiver& receiver, |
+ const api::cast_devices_private::Activity* activity) { |
+ ash::CastConfigDelegate::ReceiverAndActivity result; |
+ result.receiver = ConvertReceiverType(receiver); |
+ if (activity) |
+ result.activity = ConvertActivityType(*activity); |
+ return result; |
+} |
+ |
+} // namespace |
+ |
+static base::LazyInstance< |
+ BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>> g_factory = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+// static |
+BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* |
+CastDeviceUpdateListeners::GetFactoryInstance() { |
+ return g_factory.Pointer(); |
+} |
+ |
+// static |
+CastDeviceUpdateListeners* CastDeviceUpdateListeners::Get( |
+ content::BrowserContext* context) { |
+ return BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>::Get(context); |
+} |
+ |
+CastDeviceUpdateListeners::CastDeviceUpdateListeners( |
+ content::BrowserContext* context) {} |
+ |
+CastDeviceUpdateListeners::~CastDeviceUpdateListeners() {} |
+ |
+ash::CastConfigDelegate::DeviceUpdateSubscription |
+CastDeviceUpdateListeners::RegisterCallback( |
+ const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback) { |
+ return callback_list_.Add(callback); |
+} |
+ |
+void CastDeviceUpdateListeners::NotifyCallbacks( |
+ 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.
|
+ callback_list_.Notify(devices); |
+} |
+ |
+CastDevicesPrivateUpdateDevicesFunction:: |
+ CastDevicesPrivateUpdateDevicesFunction() {} |
+ |
+CastDevicesPrivateUpdateDevicesFunction:: |
+ ~CastDevicesPrivateUpdateDevicesFunction() {} |
+ |
+ExtensionFunction::ResponseAction |
+CastDevicesPrivateUpdateDevicesFunction::Run() { |
+ auto params = |
+ api::cast_devices_private::UpdateDevices::Params::Create(*args_); |
+ |
+ CastDeviceUpdateListeners::ReceiverAndActivityList devices; |
+ for (linked_ptr<api::cast_devices_private::ReceiverActivity> device : |
+ params->devices) { |
+ devices.push_back(ConvertReceiverAndActivityType(device->receiver, |
+ device->activity.get())); |
+ } |
+ |
+ 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.
|
+ storage->NotifyCallbacks(devices); |
+ |
+ return RespondNow(NoArguments()); |
+} |
+ |
+} // namespace extensions |