OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // Keeps track of devices that have responded to discovery requests and notifies |
| 20 // the observer with the set of active devices has changed. The registry's |
| 21 // observer (i.e., the Dial API) owns the registry instance. |
| 22 class DialRegistry { |
| 23 public: |
| 24 typedef std::vector<DialDeviceData> DeviceList; |
| 25 |
| 26 class Observer { |
| 27 public: |
| 28 // Invoked on the IO thread by the DialRegistry during a device event (new |
| 29 // device discovered or an update triggered by dial.discoverNow). |
| 30 virtual void OnDialDeviceEvent(const DeviceList& devices) = 0; |
| 31 |
| 32 protected: |
| 33 virtual ~Observer() {} |
| 34 }; |
| 35 |
| 36 // Create the DIAL registry and pass a reference to allow it to notify on |
| 37 // DIAL device events. |
| 38 explicit DialRegistry(Observer *dial_api); |
| 39 virtual ~DialRegistry(); |
| 40 |
| 41 // Called by the DIAL API when event listeners are added or removed. The dial |
| 42 // service is started after the first listener is added and stopped after the |
| 43 // last listener is removed. |
| 44 void OnListenerAdded(); |
| 45 void OnListenerRemoved(); |
| 46 |
| 47 // Called by the DIAL API to try to kickoff a discovery if there is not one |
| 48 // already active. |
| 49 bool DiscoverNow(); |
| 50 |
| 51 private: |
| 52 // The current number of event listeners attached to this registry. |
| 53 int num_listeners_; |
| 54 |
| 55 // Whether discovering is currently active. |
| 56 bool discovering_; |
| 57 |
| 58 // Interface from which the DIAL API is notified of DIAL device events. the |
| 59 // DIAL API owns this DIAL registry. |
| 60 Observer* dial_api_; |
| 61 |
| 62 // Thread checker. |
| 63 base::ThreadChecker thread_checker_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(DialRegistry); |
| 66 }; |
| 67 |
| 68 } // namespace extensions |
| 69 |
| 70 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
OLD | NEW |