OLD | NEW |
---|---|
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 // Fetch an instance for the given context. |
stevenjb
2016/01/12 23:31:49
s/Fetch/Fetches/ (while you're in here)
jdufault
2016/01/12 23:59:22
Done.
| |
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 // Set the function that will be invoked only when a new device update is |
stevenjb
2016/01/12 23:31:50
s/Set/Sets/
jdufault
2016/01/12 23:59:22
Done.
| |
27 // available. | 28 // available. |
28 ash::CastConfigDelegate::DeviceUpdateSubscription RegisterCallback( | 29 void AddObserver(ash::CastConfigDelegate::Observer* observer); |
29 const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback); | 30 void RemoveObserver(ash::CastConfigDelegate::Observer* observer); |
30 | 31 |
31 // BrowserContextKeyedAPI implementation: | 32 // BrowserContextKeyedAPI implementation: |
32 static BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* | 33 static BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>* |
33 GetFactoryInstance(); | 34 GetFactoryInstance(); |
34 static const bool kServiceIsCreatedWithBrowserContext = false; | 35 static const bool kServiceIsCreatedWithBrowserContext = false; |
35 | 36 |
36 private: | 37 private: |
37 using ReceiverAndActivityList = | 38 using ReceiverAndActivityList = |
38 std::vector<ash::CastConfigDelegate::ReceiverAndActivity>; | 39 std::vector<ash::CastConfigDelegate::ReceiverAndActivity>; |
39 | 40 |
40 friend class CastDevicesPrivateUpdateDevicesFunction; // For NotifyCallbacks. | 41 friend class CastDevicesPrivateUpdateDevicesFunction; // For NotifyCallbacks. |
41 void NotifyCallbacks(const ReceiverAndActivityList& devices); | 42 void NotifyCallbacks(const ReceiverAndActivityList& devices); |
42 | 43 |
43 base::CallbackList<void(const ReceiverAndActivityList&)> callback_list_; | 44 base::ObserverList<ash::CastConfigDelegate::Observer> observer_list_; |
44 | 45 |
45 friend class BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>; | 46 friend class BrowserContextKeyedAPIFactory<CastDeviceUpdateListeners>; |
46 | 47 |
47 // BrowserContextKeyedAPI implementation: | 48 // BrowserContextKeyedAPI implementation: |
48 static const char* service_name() { return "CastDeviceUpdateListeners"; } | 49 static const char* service_name() { return "CastDeviceUpdateListeners"; } |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(CastDeviceUpdateListeners); | 51 DISALLOW_COPY_AND_ASSIGN(CastDeviceUpdateListeners); |
51 }; | 52 }; |
52 | 53 |
53 // static void updateDeviceState(ReceiverActivity[] devices); | 54 // static void updateDeviceState(ReceiverActivity[] devices); |
54 class CastDevicesPrivateUpdateDevicesFunction : | 55 class CastDevicesPrivateUpdateDevicesFunction : |
55 public UIThreadExtensionFunction { | 56 public UIThreadExtensionFunction { |
56 public: | 57 public: |
57 CastDevicesPrivateUpdateDevicesFunction(); | 58 CastDevicesPrivateUpdateDevicesFunction(); |
58 | 59 |
59 private: | 60 private: |
60 ~CastDevicesPrivateUpdateDevicesFunction() override; | 61 ~CastDevicesPrivateUpdateDevicesFunction() override; |
61 | 62 |
62 // ExtensionFunction: | 63 // ExtensionFunction: |
63 ResponseAction Run() override; | 64 ResponseAction Run() override; |
64 | 65 |
65 DECLARE_EXTENSION_FUNCTION("cast.devicesPrivate.updateDevices", | 66 DECLARE_EXTENSION_FUNCTION("cast.devicesPrivate.updateDevices", |
66 CASTDEVICESPRIVATE_UPDATEDEVICES); | 67 CASTDEVICESPRIVATE_UPDATEDEVICES); |
67 DISALLOW_COPY_AND_ASSIGN(CastDevicesPrivateUpdateDevicesFunction); | 68 DISALLOW_COPY_AND_ASSIGN(CastDevicesPrivateUpdateDevicesFunction); |
68 }; | 69 }; |
69 | 70 |
70 } // namespace extensions | 71 } // namespace extensions |
71 | 72 |
72 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVA TE_API_H_ | 73 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_DEVICES_PRIVATE_CAST_DEVICES_PRIVA TE_API_H_ |
OLD | NEW |