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

Side by Side Diff: chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.h

Issue 1567103005: Replace base::CallbackList with base::ObserverList in CastConfigDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add TODO for proper fix Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVATE_ API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVATE_ API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVATE_ API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVATE_ API_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/cast_config_delegate.h" 10 #include "ash/cast_config_delegate.h"
11 #include "base/callback_list.h" 11 #include "base/callback_list.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/observer_list.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h" 14 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h" 15 #include "extensions/browser/extension_function.h"
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 class CastDeviceUpdateListeners : public BrowserContextKeyedAPI { 19 class CastDeviceUpdateListeners : public BrowserContextKeyedAPI {
19 public: 20 public:
20 explicit CastDeviceUpdateListeners(content::BrowserContext* context); 21 explicit CastDeviceUpdateListeners(content::BrowserContext* context);
21 ~CastDeviceUpdateListeners() override; 22 ~CastDeviceUpdateListeners() override;
22 23
23 // Fetch an instance for the given context. 24 // Fetches an instance for the given context.
24 static CastDeviceUpdateListeners* Get(content::BrowserContext* context); 25 static CastDeviceUpdateListeners* Get(content::BrowserContext* context);
25 26
26 // Register a function that will be invoked only when a new device update is 27 // Adds an observer that will be invoked when new device data is available.
27 // available. 28 void AddObserver(ash::CastConfigDelegate::Observer* observer);
28 ash::CastConfigDelegate::DeviceUpdateSubscription RegisterCallback( 29 void RemoveObserver(ash::CastConfigDelegate::Observer* observer);
29 const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback);
30 30
31 // BrowserContextKeyedAPI implementation: 31 // BrowserContextKeyedAPI implementation:
32 static BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* 32 static BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>*
33 GetFactoryInstance(); 33 GetFactoryInstance();
34 static const bool kServiceIsCreatedWithBrowserContext = false; 34 static const bool kServiceIsCreatedWithBrowserContext = false;
35 35
36 private: 36 private:
37 using ReceiverAndActivityList = 37 using ReceiverAndActivityList =
38 std::vector<ash::CastConfigDelegate::ReceiverAndActivity>; 38 std::vector<ash::CastConfigDelegate::ReceiverAndActivity>;
39 39
40 friend class CastDevicesPrivateUpdateDevicesFunction; // For NotifyCallbacks. 40 friend class CastDevicesPrivateUpdateDevicesFunction; // For NotifyCallbacks.
41 void NotifyCallbacks(const ReceiverAndActivityList& devices); 41 void NotifyCallbacks(const ReceiverAndActivityList& devices);
42 42
43 base::CallbackList<void(const ReceiverAndActivityList&)> callback_list_; 43 base::ObserverList<ash::CastConfigDelegate::Observer> observer_list_;
44 44
45 friend class BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>; 45 friend class BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>;
46 46
47 // BrowserContextKeyedAPI implementation: 47 // BrowserContextKeyedAPI implementation:
48 static const char* service_name() { return "CastDeviceUpdateListeners"; } 48 static const char* service_name() { return "CastDeviceUpdateListeners"; }
49 49
50 DISALLOW_COPY_AND_ASSIGN(CastDeviceUpdateListeners); 50 DISALLOW_COPY_AND_ASSIGN(CastDeviceUpdateListeners);
51 }; 51 };
52 52
53 // static void updateDeviceState(ReceiverActivity[] devices); 53 // static void updateDeviceState(ReceiverActivity[] devices);
54 class CastDevicesPrivateUpdateDevicesFunction : 54 class CastDevicesPrivateUpdateDevicesFunction :
55 public UIThreadExtensionFunction { 55 public UIThreadExtensionFunction {
56 public: 56 public:
57 CastDevicesPrivateUpdateDevicesFunction(); 57 CastDevicesPrivateUpdateDevicesFunction();
58 58
59 private: 59 private:
60 ~CastDevicesPrivateUpdateDevicesFunction() override; 60 ~CastDevicesPrivateUpdateDevicesFunction() override;
61 61
62 // ExtensionFunction: 62 // ExtensionFunction:
63 ResponseAction Run() override; 63 ResponseAction Run() override;
64 64
65 DECLARE_EXTENSION_FUNCTION("cast.devicesPrivate.updateDevices", 65 DECLARE_EXTENSION_FUNCTION("cast.devicesPrivate.updateDevices",
66 CASTDEVICESPRIVATE_UPDATEDEVICES); 66 CASTDEVICESPRIVATE_UPDATEDEVICES);
67 DISALLOW_COPY_AND_ASSIGN(CastDevicesPrivateUpdateDevicesFunction); 67 DISALLOW_COPY_AND_ASSIGN(CastDevicesPrivateUpdateDevicesFunction);
68 }; 68 };
69 69
70 } // namespace extensions 70 } // namespace extensions
71 71
72 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVA TE_API_H_ 72 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVA TE_API_H_
OLDNEW
« no previous file with comments | « ash/test/tray_cast_test_api.cc ('k') | chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698