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 "base/files/file_path.h"
11 #include "base/metrics/histogram.h"
12 #include "base/path_service.h"
13 #include "base/timer/elapsed_timer.h"
14 #include "chrome/browser/local_discovery/service_discovery_client_utility.h"
15 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/firewall_manager_win.h"
19 #if defined(OS_MACOSX)
20 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
23 #if defined(ENABLE_MDNS)
24 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
30 void ReportFirewallStats() {
31 base::FilePath exe_path
;
32 if (!PathService::Get(base::FILE_EXE
, &exe_path
))
34 base::ElapsedTimer timer
;
35 scoped_ptr
<installer::FirewallManager
> manager
=
36 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(),
40 bool is_ready
= manager
->CanUseLocalPorts();
41 UMA_HISTOGRAM_TIMES("LocalDiscovery.FirewallAccessTime", timer
.Elapsed());
42 UMA_HISTOGRAM_BOOLEAN("LocalDiscovery.IsFirewallReady", is_ready
);
49 namespace local_discovery
{
51 using content::BrowserThread
;
54 ServiceDiscoverySharedClient
* g_service_discovery_client
= NULL
;
57 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
58 DCHECK(!g_service_discovery_client
);
59 g_service_discovery_client
= this;
62 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
63 DCHECK_EQ(g_service_discovery_client
, this);
64 g_service_discovery_client
= NULL
;
67 #if defined(ENABLE_MDNS) || defined(OS_MACOSX)
69 scoped_refptr
<ServiceDiscoverySharedClient
>
70 ServiceDiscoverySharedClient::GetInstance() {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
73 if (g_service_discovery_client
)
74 return g_service_discovery_client
;
76 #if defined(OS_MACOSX)
77 return ServiceDiscoveryClientMacFactory::CreateInstance();
81 static bool reported
=
82 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
83 base::Bind(&ReportFirewallStats
));
84 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what
85 // to do with firewall for user-level installs. crbug.com/366408
86 return new ServiceDiscoveryClientUtility();
88 return new ServiceDiscoveryClientMdns();
94 scoped_refptr
<ServiceDiscoverySharedClient
>
95 ServiceDiscoverySharedClient::GetInstance() {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
101 #endif // ENABLE_MDNS
103 } // namespace local_discovery