Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Unified Diff: chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc

Issue 1291113002: Cast extension private API for ChromeOS system tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Address comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2d8db395c4e2e4fd349413121cd42ec7d004682a
--- /dev/null
+++ b/chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc
@@ -0,0 +1,99 @@
+// 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 ConvertType(
achuithb 2015/08/18 06:19:30 Rename to ConvertReceiverType? I don't think ther
jdufault 2015/08/18 19:53:00 Done.
+ 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 ConvertType(
achuithb 2015/08/18 06:19:30 Rename to ConvertActivityType?
jdufault 2015/08/18 19:53:01 Done.
+ 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 ConvertType(
achuithb 2015/08/18 06:19:30 Rename to ConvertReceiverAndActivityType?
jdufault 2015/08/18 19:53:00 Done.
+ const api::cast_devices_private::Receiver& receiver,
+ const api::cast_devices_private::Activity* activity) {
+ ash::CastConfigDelegate::ReceiverAndActivity result;
+ result.receiver = ConvertType(receiver);
+ if (activity)
+ result.activity = ConvertType(*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() {}
achuithb 2015/08/18 06:19:31 newline before this line?
jdufault 2015/08/18 19:53:00 Done.
+
+ash::CastConfigDelegate::DeviceUpdateSubscription
+CastDeviceUpdateListeners::RegisterCallback(
+ const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback) {
+ return callback_list_.Add(callback);
+}
+
+void CastDeviceUpdateListeners::NotifyCallbacks(
+ const std::vector<ash::CastConfigDelegate::ReceiverAndActivity>& devices) {
+ callback_list_.Notify(devices);
+}
+
+CastDevicesPrivateUpdateDevicesFunction::
+ CastDevicesPrivateUpdateDevicesFunction() {}
+
+CastDevicesPrivateUpdateDevicesFunction::
+ ~CastDevicesPrivateUpdateDevicesFunction() {}
+
+ExtensionFunction::ResponseAction
+ 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.
+ auto params =
+ api::cast_devices_private::UpdateDevices::Params::Create(*args_);
+
+ std::vector<ash::CastConfigDelegate::ReceiverAndActivity> devices;
+ for (linked_ptr<api::cast_devices_private::ReceiverActivity> device :
+ params->devices) {
+ devices.push_back(ConvertType(device->receiver, device->activity.get()));
+ }
+
+ CastDeviceUpdateListeners* storage =
achuithb 2015/08/18 06:19:30 auto is fine here?
jdufault 2015/08/18 19:53:00 Done.
+ CastDeviceUpdateListeners::Get(browser_context());
+ storage->NotifyCallbacks(devices);
+
+ return RespondNow(NoArguments());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698