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 ConvertType( | |
|
achuithb
2015/08/18 06:19:30
Rename to ConvertReceiverType?
I don't think ther
jdufault
2015/08/18 19:53:00
Done.
| |
| 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 ConvertType( | |
|
achuithb
2015/08/18 06:19:30
Rename to ConvertActivityType?
jdufault
2015/08/18 19:53:01
Done.
| |
| 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 ConvertType( | |
|
achuithb
2015/08/18 06:19:30
Rename to ConvertReceiverAndActivityType?
jdufault
2015/08/18 19:53:00
Done.
| |
| 33 const api::cast_devices_private::Receiver& receiver, | |
| 34 const api::cast_devices_private::Activity* activity) { | |
| 35 ash::CastConfigDelegate::ReceiverAndActivity result; | |
| 36 result.receiver = ConvertType(receiver); | |
| 37 if (activity) | |
| 38 result.activity = ConvertType(*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 CastDeviceUpdateListeners::~CastDeviceUpdateListeners() {} | |
|
achuithb
2015/08/18 06:19:31
newline before this line?
jdufault
2015/08/18 19:53:00
Done.
| |
| 63 | |
| 64 ash::CastConfigDelegate::DeviceUpdateSubscription | |
| 65 CastDeviceUpdateListeners::RegisterCallback( | |
| 66 const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback) { | |
| 67 return callback_list_.Add(callback); | |
| 68 } | |
| 69 | |
| 70 void CastDeviceUpdateListeners::NotifyCallbacks( | |
| 71 const std::vector<ash::CastConfigDelegate::ReceiverAndActivity>& devices) { | |
| 72 callback_list_.Notify(devices); | |
| 73 } | |
| 74 | |
| 75 CastDevicesPrivateUpdateDevicesFunction:: | |
| 76 CastDevicesPrivateUpdateDevicesFunction() {} | |
| 77 | |
| 78 CastDevicesPrivateUpdateDevicesFunction:: | |
| 79 ~CastDevicesPrivateUpdateDevicesFunction() {} | |
| 80 | |
| 81 ExtensionFunction::ResponseAction | |
| 82 CastDevicesPrivateUpdateDevicesFunction::Run() { | |
|
Ken Rockot(use gerrit already)
2015/08/15 00:07:45
nit: in this case (return type on its own line) pr
jdufault
2015/08/18 19:53:00
Done.
| |
| 83 auto params = | |
| 84 api::cast_devices_private::UpdateDevices::Params::Create(*args_); | |
| 85 | |
| 86 std::vector<ash::CastConfigDelegate::ReceiverAndActivity> devices; | |
| 87 for (linked_ptr<api::cast_devices_private::ReceiverActivity> device : | |
| 88 params->devices) { | |
| 89 devices.push_back(ConvertType(device->receiver, device->activity.get())); | |
| 90 } | |
| 91 | |
| 92 CastDeviceUpdateListeners* storage = | |
|
achuithb
2015/08/18 06:19:30
auto is fine here?
jdufault
2015/08/18 19:53:00
Done.
| |
| 93 CastDeviceUpdateListeners::Get(browser_context()); | |
| 94 storage->NotifyCallbacks(devices); | |
| 95 | |
| 96 return RespondNow(NoArguments()); | |
| 97 } | |
| 98 | |
| 99 } // namespace extensions | |
| OLD | NEW |