OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_DIAL_DIAL_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/extensions/api/dial/dial_device_data.h" | 10 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // The DialRegistry for the API. This must always be used only from the IO | 30 // The DialRegistry for the API. This must always be used only from the IO |
31 // thread. | 31 // thread. |
32 DialRegistry* dial_registry(); | 32 DialRegistry* dial_registry(); |
33 | 33 |
34 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches | 34 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches |
35 // the event to listeners on the UI thread. | 35 // the event to listeners on the UI thread. |
36 void SendEventOnUIThread(const DialRegistry::DeviceList& devices); | 36 void SendEventOnUIThread(const DialRegistry::DeviceList& devices); |
37 void SendErrorOnUIThread(const DialRegistry::DialErrorCode type); | 37 void SendErrorOnUIThread(const DialRegistry::DialErrorCode type); |
38 | 38 |
39 private: | 39 private: |
40 virtual ~DialAPI(); | 40 ~DialAPI() override; |
41 | 41 |
42 // RefcountedKeyedService: | 42 // RefcountedKeyedService: |
43 virtual void ShutdownOnUIThread() override; | 43 void ShutdownOnUIThread() override; |
44 | 44 |
45 // EventRouter::Observer: | 45 // EventRouter::Observer: |
46 virtual void OnListenerAdded(const EventListenerInfo& details) override; | 46 void OnListenerAdded(const EventListenerInfo& details) override; |
47 virtual void OnListenerRemoved(const EventListenerInfo& details) override; | 47 void OnListenerRemoved(const EventListenerInfo& details) override; |
48 | 48 |
49 // DialRegistry::Observer: | 49 // DialRegistry::Observer: |
50 virtual void OnDialDeviceEvent( | 50 void OnDialDeviceEvent(const DialRegistry::DeviceList& devices) override; |
51 const DialRegistry::DeviceList& devices) override; | 51 void OnDialError(DialRegistry::DialErrorCode type) override; |
52 virtual void OnDialError(DialRegistry::DialErrorCode type) override; | |
53 | 52 |
54 // Methods to notify the DialRegistry on the correct thread of new/removed | 53 // Methods to notify the DialRegistry on the correct thread of new/removed |
55 // listeners. | 54 // listeners. |
56 void NotifyListenerAddedOnIOThread(); | 55 void NotifyListenerAddedOnIOThread(); |
57 void NotifyListenerRemovedOnIOThread(); | 56 void NotifyListenerRemovedOnIOThread(); |
58 | 57 |
59 Profile* profile_; | 58 Profile* profile_; |
60 | 59 |
61 // Created lazily on first access on the IO thread. | 60 // Created lazily on first access on the IO thread. |
62 scoped_ptr<DialRegistry> dial_registry_; | 61 scoped_ptr<DialRegistry> dial_registry_; |
63 | 62 |
64 DISALLOW_COPY_AND_ASSIGN(DialAPI); | 63 DISALLOW_COPY_AND_ASSIGN(DialAPI); |
65 }; | 64 }; |
66 | 65 |
67 namespace api { | 66 namespace api { |
68 | 67 |
69 // DiscoverNow function. This function needs a round-trip from the IO thread | 68 // DiscoverNow function. This function needs a round-trip from the IO thread |
70 // because it needs to grab a pointer to the DIAL API in order to get a | 69 // because it needs to grab a pointer to the DIAL API in order to get a |
71 // reference to the DialRegistry while on the IO thread. Then, the result | 70 // reference to the DialRegistry while on the IO thread. Then, the result |
72 // must be returned on the UI thread. | 71 // must be returned on the UI thread. |
73 class DialDiscoverNowFunction : public AsyncApiFunction { | 72 class DialDiscoverNowFunction : public AsyncApiFunction { |
74 public: | 73 public: |
75 DialDiscoverNowFunction(); | 74 DialDiscoverNowFunction(); |
76 | 75 |
77 protected: | 76 protected: |
78 virtual ~DialDiscoverNowFunction() {} | 77 ~DialDiscoverNowFunction() override {} |
79 | 78 |
80 // AsyncApiFunction: | 79 // AsyncApiFunction: |
81 virtual bool Prepare() override; | 80 bool Prepare() override; |
82 virtual void Work() override; | 81 void Work() override; |
83 virtual bool Respond() override; | 82 bool Respond() override; |
84 | 83 |
85 private: | 84 private: |
86 DECLARE_EXTENSION_FUNCTION("dial.discoverNow", DIAL_DISCOVERNOW) | 85 DECLARE_EXTENSION_FUNCTION("dial.discoverNow", DIAL_DISCOVERNOW) |
87 | 86 |
88 // Pointer to the DIAL API for this profile. We get this on the UI thread. | 87 // Pointer to the DIAL API for this profile. We get this on the UI thread. |
89 DialAPI* dial_; | 88 DialAPI* dial_; |
90 | 89 |
91 // Result of the discoverNow call to the DIAL registry. This result is | 90 // Result of the discoverNow call to the DIAL registry. This result is |
92 // retrieved on the IO thread but the function result is returned on the UI | 91 // retrieved on the IO thread but the function result is returned on the UI |
93 // thread. | 92 // thread. |
94 bool result_; | 93 bool result_; |
95 | 94 |
96 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); | 95 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); |
97 }; | 96 }; |
98 | 97 |
99 } // namespace api | 98 } // namespace api |
100 | 99 |
101 } // namespace extensions | 100 } // namespace extensions |
102 | 101 |
103 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ | 102 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ |
OLD | NEW |