- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / local_discovery / service_discovery_shared_client.cc
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.
4
5 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
6
7 #include "content/public/browser/browser_thread.h"
8
9 #if defined(OS_MACOSX)
10 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
11 #endif
12
13 #if defined(ENABLE_MDNS)
14 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
15 #endif  // ENABLE_MDNS
16
17 namespace local_discovery {
18
19 using content::BrowserThread;
20
21 namespace {
22 ServiceDiscoverySharedClient* g_service_discovery_client = NULL;
23 }  // namespace
24
25 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
26   DCHECK(!g_service_discovery_client);
27   g_service_discovery_client = this;
28 }
29
30 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
31   DCHECK_EQ(g_service_discovery_client, this);
32   g_service_discovery_client = NULL;
33 }
34
35 #if defined(ENABLE_MDNS) || defined(OS_MACOSX)
36
37 scoped_refptr<ServiceDiscoverySharedClient>
38     ServiceDiscoverySharedClient::GetInstance() {
39   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40
41   if (g_service_discovery_client)
42     return g_service_discovery_client;
43
44 #if defined(OS_MACOSX)
45   return ServiceDiscoveryClientMacFactory::CreateInstance();
46 #else
47   return new ServiceDiscoveryClientMdns();
48 #endif
49 }
50
51 #else
52
53 scoped_refptr<ServiceDiscoverySharedClient>
54     ServiceDiscoverySharedClient::GetInstance() {
55   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56   NOTIMPLEMENTED();
57   return NULL;
58 }
59
60 #endif  // ENABLE_MDNS
61
62 }  // namespace local_discovery