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
3 // found in the LICENSE file.
5 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
7 #include "content/public/browser/browser_thread.h"
10 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
13 #if defined(ENABLE_MDNS)
14 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
17 namespace local_discovery
{
19 using content::BrowserThread
;
22 ServiceDiscoverySharedClient
* g_service_discovery_client
= NULL
;
25 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
26 DCHECK(!g_service_discovery_client
);
27 g_service_discovery_client
= this;
30 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
31 DCHECK_EQ(g_service_discovery_client
, this);
32 g_service_discovery_client
= NULL
;
35 #if defined(ENABLE_MDNS) || defined(OS_MACOSX)
37 scoped_refptr
<ServiceDiscoverySharedClient
>
38 ServiceDiscoverySharedClient::GetInstance() {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
41 if (g_service_discovery_client
)
42 return g_service_discovery_client
;
44 #if defined(OS_MACOSX)
45 return ServiceDiscoveryClientMacFactory::CreateInstance();
47 return new ServiceDiscoveryClientMdns();
53 scoped_refptr
<ServiceDiscoverySharedClient
>
54 ServiceDiscoverySharedClient::GetInstance() {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
62 } // namespace local_discovery