| 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 22 matching lines...) Expand all Loading... |
| 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 virtual ~DialAPI(); |
| 41 | 41 |
| 42 // RefcountedBrowserContextKeyedService: | 42 // RefcountedBrowserContextKeyedService: |
| 43 virtual void ShutdownOnUIThread() OVERRIDE; | 43 virtual void ShutdownOnUIThread() override; |
| 44 | 44 |
| 45 // EventRouter::Observer: | 45 // EventRouter::Observer: |
| 46 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 46 virtual void OnListenerAdded(const EventListenerInfo& details) override; |
| 47 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; | 47 virtual void OnListenerRemoved(const EventListenerInfo& details) override; |
| 48 | 48 |
| 49 // DialRegistry::Observer: | 49 // DialRegistry::Observer: |
| 50 virtual void OnDialDeviceEvent( | 50 virtual void OnDialDeviceEvent( |
| 51 const DialRegistry::DeviceList& devices) OVERRIDE; | 51 const DialRegistry::DeviceList& devices) override; |
| 52 virtual void OnDialError(DialRegistry::DialErrorCode type) OVERRIDE; | 52 virtual void OnDialError(DialRegistry::DialErrorCode type) override; |
| 53 | 53 |
| 54 // Methods to notify the DialRegistry on the correct thread of new/removed | 54 // Methods to notify the DialRegistry on the correct thread of new/removed |
| 55 // listeners. | 55 // listeners. |
| 56 void NotifyListenerAddedOnIOThread(); | 56 void NotifyListenerAddedOnIOThread(); |
| 57 void NotifyListenerRemovedOnIOThread(); | 57 void NotifyListenerRemovedOnIOThread(); |
| 58 | 58 |
| 59 Profile* profile_; | 59 Profile* profile_; |
| 60 | 60 |
| 61 // Created lazily on first access on the IO thread. | 61 // Created lazily on first access on the IO thread. |
| 62 scoped_ptr<DialRegistry> dial_registry_; | 62 scoped_ptr<DialRegistry> dial_registry_; |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(DialAPI); | 64 DISALLOW_COPY_AND_ASSIGN(DialAPI); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 namespace api { | 67 namespace api { |
| 68 | 68 |
| 69 // DiscoverNow function. This function needs a round-trip from the IO thread | 69 // 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 | 70 // 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 | 71 // reference to the DialRegistry while on the IO thread. Then, the result |
| 72 // must be returned on the UI thread. | 72 // must be returned on the UI thread. |
| 73 class DialDiscoverNowFunction : public AsyncApiFunction { | 73 class DialDiscoverNowFunction : public AsyncApiFunction { |
| 74 public: | 74 public: |
| 75 DialDiscoverNowFunction(); | 75 DialDiscoverNowFunction(); |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 virtual ~DialDiscoverNowFunction() {} | 78 virtual ~DialDiscoverNowFunction() {} |
| 79 | 79 |
| 80 // AsyncApiFunction: | 80 // AsyncApiFunction: |
| 81 virtual bool Prepare() OVERRIDE; | 81 virtual bool Prepare() override; |
| 82 virtual void Work() OVERRIDE; | 82 virtual void Work() override; |
| 83 virtual bool Respond() OVERRIDE; | 83 virtual bool Respond() override; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 DECLARE_EXTENSION_FUNCTION("dial.discoverNow", DIAL_DISCOVERNOW) | 86 DECLARE_EXTENSION_FUNCTION("dial.discoverNow", DIAL_DISCOVERNOW) |
| 87 | 87 |
| 88 // Pointer to the DIAL API for this profile. We get this on the UI thread. | 88 // Pointer to the DIAL API for this profile. We get this on the UI thread. |
| 89 DialAPI* dial_; | 89 DialAPI* dial_; |
| 90 | 90 |
| 91 // Result of the discoverNow call to the DIAL registry. This result is | 91 // 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 | 92 // retrieved on the IO thread but the function result is returned on the UI |
| 93 // thread. | 93 // thread. |
| 94 bool result_; | 94 bool result_; |
| 95 | 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); | 96 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 } // namespace api | 99 } // namespace api |
| 100 | 100 |
| 101 } // namespace extensions | 101 } // namespace extensions |
| 102 | 102 |
| 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ |
| OLD | NEW |