| 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 ASH_CAST_CONFIG_DELEGATE_H_ | 5 #ifndef ASH_CAST_CONFIG_DELEGATE_H_ |
| 6 #define ASH_CAST_CONFIG_DELEGATE_H_ | 6 #define ASH_CAST_CONFIG_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/callback_list.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 | 20 |
| 20 // This delegate allows the UI code in ash, e.g. |TrayCastDetailedView|, | 21 // This delegate allows the UI code in ash, e.g. |TrayCastDetailedView|, |
| 21 // to access the cast extension. | 22 // to access the cast extension. |
| 22 class CastConfigDelegate { | 23 class CastConfigDelegate { |
| 23 public: | 24 public: |
| 24 struct ASH_EXPORT Receiver { | 25 struct ASH_EXPORT Receiver { |
| 25 Receiver(); | 26 Receiver(); |
| 26 ~Receiver(); | 27 ~Receiver(); |
| 27 | 28 |
| 28 std::string id; | 29 std::string id; |
| 29 base::string16 name; | 30 base::string16 name; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 struct ASH_EXPORT Activity { | 33 struct ASH_EXPORT Activity { |
| 33 // The tab identifier that we are casting. These are the special tab values | 34 // The tab identifier that we are casting. These are the special tab values |
| 34 // taken from the chromecast extension itself. If an actual tab is being | 35 // taken from the chromecast extension itself. If an actual tab is being |
| 35 // casted, then the TabId will be >= 0. | 36 // casted, then the TabId will be >= 0. |
| 36 enum TabId { | 37 enum TabId { |
| 37 EXTENSION = -1, | 38 EXTENSION = -1, |
| 38 DESKTOP = -2, | 39 DESKTOP = -2, |
| 39 DISCOVERED_ACTIVITY = -3, | 40 DISCOVERED_ACTIVITY = -3, |
| 40 EXTERNAL_EXTENSION_CLIENT = -4 | 41 EXTERNAL_EXTENSION_CLIENT = -4, |
| 42 |
| 43 // Not in the extension. Used when the extension does not give us a tabId |
| 44 // (ie, the cast is running from another device). |
| 45 UNKNOWN = -5 |
| 41 }; | 46 }; |
| 42 | 47 |
| 43 Activity(); | 48 Activity(); |
| 44 ~Activity(); | 49 ~Activity(); |
| 45 | 50 |
| 46 std::string id; | 51 std::string id; |
| 47 base::string16 title; | 52 base::string16 title; |
| 48 std::string activity_type; | |
| 49 bool allow_stop = false; | |
| 50 | 53 |
| 51 // The id for the tab we are casting. Could be one of the TabId values, | 54 // The id for the tab we are casting. Could be one of the TabId values, |
| 52 // or a value >= 0 that represents that tab index of the tab we are | 55 // or a value >= 0 that represents that tab index of the tab we are |
| 53 // casting. We default to casting the desktop, as a tab may not | 56 // casting. We default to casting the desktop, as a tab may not |
| 54 // necessarily exist. | 57 // necessarily exist. |
| 55 int tab_id = TabId::DESKTOP; | 58 int tab_id = TabId::DESKTOP; |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 struct ASH_EXPORT ReceiverAndActivity { | 61 struct ASH_EXPORT ReceiverAndActivity { |
| 59 ReceiverAndActivity(); | 62 ReceiverAndActivity(); |
| 60 ~ReceiverAndActivity(); | 63 ~ReceiverAndActivity(); |
| 61 | 64 |
| 62 Receiver receiver; | 65 Receiver receiver; |
| 63 Activity activity; | 66 Activity activity; |
| 64 }; | 67 }; |
| 65 | 68 |
| 66 // The key is the receiver id. | 69 // The key is the receiver id. |
| 67 using ReceiversAndActivites = std::map<std::string, ReceiverAndActivity>; | 70 using ReceiversAndActivites = std::vector<ReceiverAndActivity>; |
| 68 using ReceiversAndActivitesCallback = | 71 using ReceiversAndActivitesCallback = |
| 69 base::Callback<void(const ReceiversAndActivites&)>; | 72 base::Callback<void(const ReceiversAndActivites&)>; |
| 73 using DeviceUpdateSubscription = scoped_ptr< |
| 74 base::CallbackList<void(const ReceiversAndActivites&)>::Subscription>; |
| 70 | 75 |
| 71 virtual ~CastConfigDelegate() {} | 76 virtual ~CastConfigDelegate() {} |
| 72 | 77 |
| 73 // Returns true if cast extension is installed. | 78 // Returns true if cast extension is installed. |
| 74 virtual bool HasCastExtension() const = 0; | 79 virtual bool HasCastExtension() const = 0; |
| 75 | 80 |
| 76 // Fetches the current set of receivers and their possible activities. This | 81 // Adds a listener that will get invoked whenever the receivers or their |
| 77 // method will lookup the current chromecast extension and query its current | 82 // associated activites have changed. |
| 78 // state. The |callback| will be invoked when the receiver/activity data is | 83 virtual DeviceUpdateSubscription RegisterDeviceUpdateObserver( |
| 79 // available. | |
| 80 virtual void GetReceiversAndActivities( | |
| 81 const ReceiversAndActivitesCallback& callback) = 0; | 84 const ReceiversAndActivitesCallback& callback) = 0; |
| 82 | 85 |
| 86 // Request fresh data from the backend. When the data is available, all |
| 87 // registered observers will get called. |
| 88 virtual void RequestDeviceRefresh() = 0; |
| 89 |
| 83 // Cast to a receiver specified by |receiver_id|. | 90 // Cast to a receiver specified by |receiver_id|. |
| 84 virtual void CastToReceiver(const std::string& receiver_id) = 0; | 91 virtual void CastToReceiver(const std::string& receiver_id) = 0; |
| 85 | 92 |
| 86 // Stop an ongoing cast. | 93 // Stop an ongoing cast (this should be a user initiated stop). |
| 87 virtual void StopCasting() = 0; | 94 virtual void StopCasting() = 0; |
| 88 | 95 |
| 89 // Opens Options page for cast. | 96 // Opens Options page for cast. |
| 90 virtual void LaunchCastOptions() = 0; | 97 virtual void LaunchCastOptions() = 0; |
| 91 | 98 |
| 92 private: | 99 private: |
| 93 DISALLOW_ASSIGN(CastConfigDelegate); | 100 DISALLOW_ASSIGN(CastConfigDelegate); |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 } // namespace ash | 103 } // namespace ash |
| 97 | 104 |
| 98 #endif // ASH_CAST_CONFIG_DELEGATE_H_ | 105 #endif // ASH_CAST_CONFIG_DELEGATE_H_ |
| OLD | NEW |