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 static base::LazyInstance< | |
| 14 BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>> g_factory = | |
| 15 LAZY_INSTANCE_INITIALIZER; | |
| 16 | |
| 17 // static | |
| 18 BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* | |
| 19 CastDeviceUpdateListeners::GetFactoryInstance() { | |
| 20 return g_factory.Pointer(); | |
| 21 } | |
| 22 | |
| 23 // static | |
| 24 CastDeviceUpdateListeners* CastDeviceUpdateListeners::Get( | |
| 25 content::BrowserContext* context) { | |
| 26 return BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>::Get(context); | |
| 27 } | |
| 28 | |
| 29 CastDeviceUpdateListeners::CastDeviceUpdateListeners( | |
| 30 content::BrowserContext* context) {} | |
| 31 CastDeviceUpdateListeners::~CastDeviceUpdateListeners() {} | |
| 32 | |
| 33 ash::CastConfigDelegate::DeviceUpdateSubscription | |
| 34 CastDeviceUpdateListeners::RegisterCallback( | |
| 35 const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback) { | |
| 36 return callback_list_.Add(callback); | |
| 37 } | |
| 38 | |
| 39 void CastDeviceUpdateListeners::NotifyCallbacks( | |
| 40 const std::vector<ash::CastConfigDelegate::ReceiverAndActivity>& devices) { | |
| 41 callback_list_.Notify(devices); | |
| 42 } | |
| 43 | |
| 44 static ash::CastConfigDelegate::Receiver ConvertType( | |
|
Ken Rockot(use gerrit already)
2015/08/14 23:20:09
instead of using static for these internal functio
jdufault
2015/08/15 00:04:52
Done.
| |
| 45 const api::cast_devices_private::Receiver& receiver) { | |
| 46 ash::CastConfigDelegate::Receiver result; | |
| 47 result.id = receiver.id; | |
| 48 result.name = base::UTF8ToUTF16(receiver.name); | |
| 49 return result; | |
| 50 } | |
| 51 | |
| 52 static ash::CastConfigDelegate::Activity ConvertType( | |
| 53 const api::cast_devices_private::Activity& activity) { | |
| 54 ash::CastConfigDelegate::Activity result; | |
| 55 result.id = activity.id; | |
| 56 result.title = base::UTF8ToUTF16(activity.title); | |
| 57 result.tab_id = activity.tab_id; | |
| 58 return result; | |
| 59 } | |
| 60 | |
| 61 static ash::CastConfigDelegate::ReceiverAndActivity ConvertType( | |
| 62 const api::cast_devices_private::Receiver& receiver, | |
| 63 const api::cast_devices_private::Activity* activity) { | |
| 64 ash::CastConfigDelegate::ReceiverAndActivity result; | |
| 65 result.receiver = ConvertType(receiver); | |
| 66 if (activity) | |
| 67 result.activity = ConvertType(*activity); | |
| 68 return result; | |
| 69 } | |
| 70 | |
| 71 CastDevicesPrivateUpdateDevicesFunction:: | |
| 72 CastDevicesPrivateUpdateDevicesFunction() {} | |
| 73 | |
| 74 CastDevicesPrivateUpdateDevicesFunction:: | |
| 75 ~CastDevicesPrivateUpdateDevicesFunction() {} | |
| 76 | |
| 77 bool CastDevicesPrivateUpdateDevicesFunction::RunAsync() { | |
| 78 auto params = | |
| 79 api::cast_devices_private::UpdateDevices::Params::Create(*args_); | |
| 80 | |
| 81 std::vector<ash::CastConfigDelegate::ReceiverAndActivity> devices; | |
| 82 for (linked_ptr<api::cast_devices_private::ReceiverActivity> device : | |
| 83 params->devices) { | |
| 84 devices.push_back(ConvertType(device->receiver, device->activity.get())); | |
| 85 } | |
| 86 | |
| 87 CastDeviceUpdateListeners* storage = | |
| 88 CastDeviceUpdateListeners::Get(browser_context()); | |
| 89 storage->NotifyCallbacks(devices); | |
| 90 | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 } // namespace extensions | |
| OLD | NEW |