blob: d5fc9e0a33d6fa2a91d2f9bea440a2c02f01ec90 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/local_discovery/service_discovery_shared_client.h"
#include "content/public/browser/browser_thread.h"
#if defined(OS_MACOSX)
#include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
#endif
#if defined(ENABLE_MDNS)
#include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
#endif // ENABLE_MDNS
namespace local_discovery {
using content::BrowserThread;
namespace {
ServiceDiscoverySharedClient* g_service_discovery_client = NULL;
} // namespace
ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
DCHECK(!g_service_discovery_client);
g_service_discovery_client = this;
}
ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
DCHECK_EQ(g_service_discovery_client, this);
g_service_discovery_client = NULL;
}
#if defined(ENABLE_MDNS) || defined(OS_MACOSX)
scoped_refptr<ServiceDiscoverySharedClient>
ServiceDiscoverySharedClient::GetInstance() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (g_service_discovery_client)
return g_service_discovery_client;
#if defined(OS_MACOSX)
return ServiceDiscoveryClientMacFactory::CreateInstance();
#else
return new ServiceDiscoveryClientMdns();
#endif
}
#else
scoped_refptr<ServiceDiscoverySharedClient>
ServiceDiscoverySharedClient::GetInstance() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
NOTIMPLEMENTED();
return NULL;
}
#endif // ENABLE_MDNS
} // namespace local_discovery