Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / local_discovery / service_discovery_shared_client.cc
blobe7f851e50c0b38f229991c7904e752b64c3a9e1d
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"
9 #if defined(OS_WIN)
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/installer/util/browser_distribution.h"
15 #include "chrome/installer/util/firewall_manager_win.h"
16 #endif // OS_WIN
18 #if defined(OS_MACOSX)
19 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
20 #endif
22 #if defined(ENABLE_MDNS)
23 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
24 #include "chrome/browser/local_discovery/service_discovery_client_utility.h"
25 #endif // ENABLE_MDNS
27 namespace {
29 #if defined(OS_WIN)
31 bool g_is_firewall_ready = false;
33 void ReportFirewallStats() {
34 base::FilePath exe_path;
35 if (!PathService::Get(base::FILE_EXE, &exe_path))
36 return;
37 base::ElapsedTimer timer;
38 scoped_ptr<installer::FirewallManager> manager =
39 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(),
40 exe_path);
41 if (!manager)
42 return;
43 g_is_firewall_ready = manager->CanUseLocalPorts();
44 UMA_HISTOGRAM_TIMES("LocalDiscovery.FirewallAccessTime", timer.Elapsed());
45 UMA_HISTOGRAM_BOOLEAN("LocalDiscovery.IsFirewallReady", g_is_firewall_ready);
47 #endif // OS_WIN
49 } // namespace
52 namespace local_discovery {
54 using content::BrowserThread;
56 namespace {
57 ServiceDiscoverySharedClient* g_service_discovery_client = NULL;
58 } // namespace
60 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
61 DCHECK(!g_service_discovery_client);
62 g_service_discovery_client = this;
65 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
66 DCHECK_EQ(g_service_discovery_client, this);
67 g_service_discovery_client = NULL;
70 #if defined(ENABLE_MDNS) || defined(OS_MACOSX)
72 scoped_refptr<ServiceDiscoverySharedClient>
73 ServiceDiscoverySharedClient::GetInstance() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 if (g_service_discovery_client)
77 return g_service_discovery_client;
79 #if defined(OS_MACOSX)
80 return ServiceDiscoveryClientMacFactory::CreateInstance();
81 #else // OS_MACOSX
83 #if defined(OS_WIN)
84 static bool reported =
85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
86 base::Bind(&ReportFirewallStats));
87 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what
88 // to do with firewall for user-level installs. crbug.com/366408
89 if (!g_is_firewall_ready)
90 return new ServiceDiscoveryClientUtility();
91 #endif // OS_WIN
93 return new ServiceDiscoveryClientMdns();
94 #endif // OS_MACOSX
97 #else
99 scoped_refptr<ServiceDiscoverySharedClient>
100 ServiceDiscoverySharedClient::GetInstance() {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
102 NOTIMPLEMENTED();
103 return NULL;
106 #endif // ENABLE_MDNS
108 } // namespace local_discovery