| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 14 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 class Thread; | 18 class Thread; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace local_discovery { | 21 namespace local_discovery { |
| 20 | 22 |
| 21 template <class T> | 23 template <class T> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMac); | 55 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryClientMac); |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 class ServiceWatcherImplMac : public ServiceWatcher { | 58 class ServiceWatcherImplMac : public ServiceWatcher { |
| 57 public: | 59 public: |
| 58 class NetServiceBrowserContainer { | 60 class NetServiceBrowserContainer { |
| 59 public: | 61 public: |
| 60 NetServiceBrowserContainer( | 62 NetServiceBrowserContainer( |
| 61 const std::string& service_type, | 63 const std::string& service_type, |
| 62 const ServiceWatcher::UpdatedCallback& callback, | 64 const ServiceWatcher::UpdatedCallback& callback, |
| 63 scoped_refptr<base::MessageLoopProxy> service_discovery_runner); | 65 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner); |
| 64 ~NetServiceBrowserContainer(); | 66 ~NetServiceBrowserContainer(); |
| 65 | 67 |
| 66 void Start(); | 68 void Start(); |
| 67 void DiscoverNewServices(); | 69 void DiscoverNewServices(); |
| 68 | 70 |
| 69 void OnServicesUpdate(ServiceWatcher::UpdateType update, | 71 void OnServicesUpdate(ServiceWatcher::UpdateType update, |
| 70 const std::string& service); | 72 const std::string& service); |
| 71 | 73 |
| 72 void DeleteSoon(); | 74 void DeleteSoon(); |
| 73 | 75 |
| 74 private: | 76 private: |
| 75 void StartOnDiscoveryThread(); | 77 void StartOnDiscoveryThread(); |
| 76 void DiscoverOnDiscoveryThread(); | 78 void DiscoverOnDiscoveryThread(); |
| 77 | 79 |
| 78 bool IsOnServiceDiscoveryThread() { | 80 bool IsOnServiceDiscoveryThread() { |
| 79 return base::MessageLoopProxy::current() == | 81 return base::ThreadTaskRunnerHandle::Get() == |
| 80 service_discovery_runner_.get(); | 82 service_discovery_runner_.get(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 std::string service_type_; | 85 std::string service_type_; |
| 84 ServiceWatcher::UpdatedCallback callback_; | 86 ServiceWatcher::UpdatedCallback callback_; |
| 85 | 87 |
| 86 scoped_refptr<base::MessageLoopProxy> callback_runner_; | 88 scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; |
| 87 scoped_refptr<base::MessageLoopProxy> service_discovery_runner_; | 89 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner_; |
| 88 | 90 |
| 89 base::scoped_nsobject<id> delegate_; | 91 base::scoped_nsobject<id> delegate_; |
| 90 base::scoped_nsobject<NSNetServiceBrowser> browser_; | 92 base::scoped_nsobject<NSNetServiceBrowser> browser_; |
| 91 base::WeakPtrFactory<NetServiceBrowserContainer> weak_factory_; | 93 base::WeakPtrFactory<NetServiceBrowserContainer> weak_factory_; |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 ServiceWatcherImplMac( | 96 ServiceWatcherImplMac( |
| 95 const std::string& service_type, | 97 const std::string& service_type, |
| 96 const ServiceWatcher::UpdatedCallback& callback, | 98 const ServiceWatcher::UpdatedCallback& callback, |
| 97 scoped_refptr<base::MessageLoopProxy> service_discovery_runner); | 99 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner); |
| 98 | 100 |
| 99 void OnServicesUpdate(ServiceWatcher::UpdateType update, | 101 void OnServicesUpdate(ServiceWatcher::UpdateType update, |
| 100 const std::string& service); | 102 const std::string& service); |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 ~ServiceWatcherImplMac() override; | 105 ~ServiceWatcherImplMac() override; |
| 104 | 106 |
| 105 void Start() override; | 107 void Start() override; |
| 106 void DiscoverNewServices(bool force_update) override; | 108 void DiscoverNewServices(bool force_update) override; |
| 107 void SetActivelyRefreshServices(bool actively_refresh_services) override; | 109 void SetActivelyRefreshServices(bool actively_refresh_services) override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 DISALLOW_COPY_AND_ASSIGN(ServiceWatcherImplMac); | 121 DISALLOW_COPY_AND_ASSIGN(ServiceWatcherImplMac); |
| 120 }; | 122 }; |
| 121 | 123 |
| 122 class ServiceResolverImplMac : public ServiceResolver { | 124 class ServiceResolverImplMac : public ServiceResolver { |
| 123 public: | 125 public: |
| 124 class NetServiceContainer { | 126 class NetServiceContainer { |
| 125 public: | 127 public: |
| 126 NetServiceContainer( | 128 NetServiceContainer( |
| 127 const std::string& service_name, | 129 const std::string& service_name, |
| 128 const ServiceResolver::ResolveCompleteCallback& callback, | 130 const ServiceResolver::ResolveCompleteCallback& callback, |
| 129 scoped_refptr<base::MessageLoopProxy> service_discovery_runner); | 131 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner); |
| 130 | 132 |
| 131 virtual ~NetServiceContainer(); | 133 virtual ~NetServiceContainer(); |
| 132 | 134 |
| 133 void StartResolving(); | 135 void StartResolving(); |
| 134 | 136 |
| 135 void OnResolveUpdate(RequestStatus); | 137 void OnResolveUpdate(RequestStatus); |
| 136 | 138 |
| 137 void SetServiceForTesting(base::scoped_nsobject<NSNetService> service); | 139 void SetServiceForTesting(base::scoped_nsobject<NSNetService> service); |
| 138 | 140 |
| 139 void DeleteSoon(); | 141 void DeleteSoon(); |
| 140 | 142 |
| 141 private: | 143 private: |
| 142 void StartResolvingOnDiscoveryThread(); | 144 void StartResolvingOnDiscoveryThread(); |
| 143 | 145 |
| 144 bool IsOnServiceDiscoveryThread() { | 146 bool IsOnServiceDiscoveryThread() { |
| 145 return base::MessageLoopProxy::current() == | 147 return base::ThreadTaskRunnerHandle::Get() == |
| 146 service_discovery_runner_.get(); | 148 service_discovery_runner_.get(); |
| 147 } | 149 } |
| 148 | 150 |
| 149 const std::string service_name_; | 151 const std::string service_name_; |
| 150 ServiceResolver::ResolveCompleteCallback callback_; | 152 ServiceResolver::ResolveCompleteCallback callback_; |
| 151 | 153 |
| 152 scoped_refptr<base::MessageLoopProxy> callback_runner_; | 154 scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; |
| 153 scoped_refptr<base::MessageLoopProxy> service_discovery_runner_; | 155 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner_; |
| 154 | 156 |
| 155 base::scoped_nsobject<id> delegate_; | 157 base::scoped_nsobject<id> delegate_; |
| 156 base::scoped_nsobject<NSNetService> service_; | 158 base::scoped_nsobject<NSNetService> service_; |
| 157 ServiceDescription service_description_; | 159 ServiceDescription service_description_; |
| 158 base::WeakPtrFactory<NetServiceContainer> weak_factory_; | 160 base::WeakPtrFactory<NetServiceContainer> weak_factory_; |
| 159 }; | 161 }; |
| 160 | 162 |
| 161 ServiceResolverImplMac( | 163 ServiceResolverImplMac( |
| 162 const std::string& service_name, | 164 const std::string& service_name, |
| 163 const ServiceResolver::ResolveCompleteCallback& callback, | 165 const ServiceResolver::ResolveCompleteCallback& callback, |
| 164 scoped_refptr<base::MessageLoopProxy> service_discovery_runner); | 166 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner); |
| 165 | 167 |
| 166 // Testing methods. | 168 // Testing methods. |
| 167 NetServiceContainer* GetContainerForTesting(); | 169 NetServiceContainer* GetContainerForTesting(); |
| 168 | 170 |
| 169 private: | 171 private: |
| 170 ~ServiceResolverImplMac() override; | 172 ~ServiceResolverImplMac() override; |
| 171 | 173 |
| 172 void StartResolving() override; | 174 void StartResolving() override; |
| 173 std::string GetName() const override; | 175 std::string GetName() const override; |
| 174 | 176 |
| 175 void OnResolveComplete(RequestStatus status, | 177 void OnResolveComplete(RequestStatus status, |
| 176 const ServiceDescription& description); | 178 const ServiceDescription& description); |
| 177 | 179 |
| 178 const std::string service_name_; | 180 const std::string service_name_; |
| 179 ServiceResolver::ResolveCompleteCallback callback_; | 181 ServiceResolver::ResolveCompleteCallback callback_; |
| 180 bool has_resolved_; | 182 bool has_resolved_; |
| 181 | 183 |
| 182 scoped_ptr<NetServiceContainer, | 184 scoped_ptr<NetServiceContainer, |
| 183 ServiceDiscoveryThreadDeleter<NetServiceContainer> > container_; | 185 ServiceDiscoveryThreadDeleter<NetServiceContainer> > container_; |
| 184 base::WeakPtrFactory<ServiceResolverImplMac> weak_factory_; | 186 base::WeakPtrFactory<ServiceResolverImplMac> weak_factory_; |
| 185 | 187 |
| 186 DISALLOW_COPY_AND_ASSIGN(ServiceResolverImplMac); | 188 DISALLOW_COPY_AND_ASSIGN(ServiceResolverImplMac); |
| 187 }; | 189 }; |
| 188 | 190 |
| 189 } // namespace local_discovery | 191 } // namespace local_discovery |
| 190 | 192 |
| 191 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ | 193 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_MAC_H_ |
| OLD | NEW |