| 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/api_function.h" | 10 #include "chrome/browser/extensions/api/api_function.h" |
| 11 #include "chrome/browser/extensions/api/dial/dial_device_data.h" | 11 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
| 12 #include "chrome/browser/extensions/api/dial/dial_registry.h" | 12 #include "chrome/browser/extensions/api/dial/dial_registry.h" |
| 13 #include "chrome/browser/extensions/api/dial/mdns_service.h" |
| 13 #include "chrome/browser/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" | 15 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 18 class DialRegistry; | 19 class DialRegistry; |
| 19 | 20 |
| 20 // Dial API which is a ref-counted BrowserContextKeyedService that manages | 21 // Dial API which is a ref-counted BrowserContextKeyedService that manages |
| 21 // the DIAL registry. It takes care of creating the registry on the IO thread | 22 // the DIAL registry. It takes care of creating the registry on the IO thread |
| 22 // and is an observer of the registry. It makes sure devices events are sent out | 23 // and is an observer of the registry. It makes sure devices events are sent out |
| 23 // to extension listeners on the right thread. | 24 // to extension listeners on the right thread. |
| 24 class DialAPI : public RefcountedBrowserContextKeyedService, | 25 class DialAPI : public RefcountedBrowserContextKeyedService, |
| 25 public EventRouter::Observer, | 26 public EventRouter::Observer, |
| 26 public DialRegistry::Observer { | 27 public DialRegistry::Observer { |
| 27 public: | 28 public: |
| 28 explicit DialAPI(Profile* profile); | 29 explicit DialAPI(Profile* profile); |
| 29 | 30 |
| 30 // The DialRegistry for the API. This must always be used only from the IO | 31 // The DialRegistry for the API. This must always be used only from the IO |
| 31 // thread. | 32 // thread. |
| 32 DialRegistry* dial_registry(); | 33 DialRegistry* dial_registry(); |
| 34 MDNSService* mdns_service(); |
| 33 | 35 |
| 34 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches | 36 // Called by the DialRegistry on the IO thread so that the DialAPI dispatches |
| 35 // the event to listeners on the UI thread. | 37 // the event to listeners on the UI thread. |
| 36 void SendEventOnUIThread(const DialRegistry::DeviceList& devices); | 38 void SendEventOnUIThread(const DialRegistry::DeviceList& devices); |
| 37 void SendErrorOnUIThread(const DialRegistry::DialErrorCode type); | 39 void SendErrorOnUIThread(const DialRegistry::DialErrorCode type); |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 virtual ~DialAPI(); | 42 virtual ~DialAPI(); |
| 41 | 43 |
| 42 // RefcountedBrowserContextKeyedService: | 44 // RefcountedBrowserContextKeyedService: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 | 55 |
| 54 // Methods to notify the DialRegistry on the correct thread of new/removed | 56 // Methods to notify the DialRegistry on the correct thread of new/removed |
| 55 // listeners. | 57 // listeners. |
| 56 void NotifyListenerAddedOnIOThread(); | 58 void NotifyListenerAddedOnIOThread(); |
| 57 void NotifyListenerRemovedOnIOThread(); | 59 void NotifyListenerRemovedOnIOThread(); |
| 58 | 60 |
| 59 Profile* profile_; | 61 Profile* profile_; |
| 60 | 62 |
| 61 // Created lazily on first access on the IO thread. | 63 // Created lazily on first access on the IO thread. |
| 62 scoped_ptr<DialRegistry> dial_registry_; | 64 scoped_ptr<DialRegistry> dial_registry_; |
| 65 scoped_ptr<MDNSService> mdns_service_; |
| 63 | 66 |
| 64 DISALLOW_COPY_AND_ASSIGN(DialAPI); | 67 DISALLOW_COPY_AND_ASSIGN(DialAPI); |
| 65 }; | 68 }; |
| 66 | 69 |
| 67 namespace api { | 70 namespace api { |
| 68 | 71 |
| 69 // DiscoverNow function. This function needs a round-trip from the IO thread | 72 // 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 | 73 // 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 | 74 // reference to the DialRegistry while on the IO thread. Then, the result |
| 72 // must be returned on the UI thread. | 75 // must be returned on the UI thread. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 DialAPI* dial_; | 92 DialAPI* dial_; |
| 90 | 93 |
| 91 // Result of the discoverNow call to the DIAL registry. This result is | 94 // 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 | 95 // retrieved on the IO thread but the function result is returned on the UI |
| 93 // thread. | 96 // thread. |
| 94 bool result_; | 97 bool result_; |
| 95 | 98 |
| 96 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); | 99 DISALLOW_COPY_AND_ASSIGN(DialDiscoverNowFunction); |
| 97 }; | 100 }; |
| 98 | 101 |
| 102 // DiscoverNow function. This function needs a round-trip from the IO thread |
| 103 // because it needs to grab a pointer to the DIAL API in order to get a |
| 104 // reference to the DialRegistry while on the IO thread. Then, the result |
| 105 // must be returned on the UI thread. |
| 106 class DialGetNetworkServicesFunction : public AsyncApiFunction { |
| 107 public: |
| 108 DialGetNetworkServicesFunction(); |
| 109 |
| 110 protected: |
| 111 virtual ~DialGetNetworkServicesFunction() {} |
| 112 |
| 113 // AsyncApiFunction: |
| 114 virtual bool Prepare() OVERRIDE; |
| 115 virtual void Work() OVERRIDE; |
| 116 virtual bool Respond() OVERRIDE; |
| 117 |
| 118 private: |
| 119 DECLARE_EXTENSION_FUNCTION("dial.getNetworkServices", DIAL_GETNETWORKSERVICES) |
| 120 |
| 121 // Pointer to the DIAL API for this profile. We get this on the UI thread. |
| 122 DialAPI* dial_; |
| 123 |
| 124 // Result of the discoverNow call to the DIAL registry. This result is |
| 125 // retrieved on the IO thread but the function result is returned on the UI |
| 126 // thread. |
| 127 bool result_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(DialGetNetworkServicesFunction); |
| 130 }; |
| 131 |
| 99 } // namespace api | 132 } // namespace api |
| 100 | 133 |
| 101 } // namespace extensions | 134 } // namespace extensions |
| 102 | 135 |
| 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ | 136 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_API_H_ |
| OLD | NEW |