[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / local_discovery / service_discovery_shared_client.cc
blobdcfb64b93e8322c5737498862f83e6aeaa9fcd0a
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/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"
17 #endif // OS_WIN
19 #if defined(OS_MACOSX)
20 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h"
21 #endif
23 #if defined(ENABLE_MDNS)
24 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
25 #endif // ENABLE_MDNS
27 namespace {
29 #if defined(OS_WIN)
30 bool IsFirewallReady() {
31 base::FilePath exe_path;
32 if (!PathService::Get(base::FILE_EXE, &exe_path))
33 return false;
34 base::ElapsedTimer timer;
35 scoped_ptr<installer::FirewallManager> manager =
36 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(),
37 exe_path);
38 if (!manager)
39 return false;
40 bool is_ready = manager->CanUseLocalPorts();
41 UMA_HISTOGRAM_TIMES("LocalDiscovery.FirewallAccessTime", timer.Elapsed());
42 UMA_HISTOGRAM_BOOLEAN("LocalDiscovery.IsFirewallReady", is_ready);
43 return is_ready;
45 #endif // OS_WIN
47 } // namespace
50 namespace local_discovery {
52 using content::BrowserThread;
54 namespace {
55 ServiceDiscoverySharedClient* g_service_discovery_client = NULL;
56 } // namespace
58 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() {
59 DCHECK(!g_service_discovery_client);
60 g_service_discovery_client = this;
63 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() {
64 DCHECK_EQ(g_service_discovery_client, this);
65 g_service_discovery_client = NULL;
68 #if defined(ENABLE_MDNS) || defined(OS_MACOSX)
70 scoped_refptr<ServiceDiscoverySharedClient>
71 ServiceDiscoverySharedClient::GetInstance() {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74 if (g_service_discovery_client)
75 return g_service_discovery_client;
77 #if defined(OS_MACOSX)
78 return ServiceDiscoveryClientMacFactory::CreateInstance();
79 #else
81 #if defined(OS_WIN)
82 static bool is_firewall_ready = IsFirewallReady();
83 if (!is_firewall_ready) {
84 // TODO(vitalybuka): Remove after we find what to do with firewall for
85 // user-level installs. crbug.com/366408
86 return new ServiceDiscoveryClientUtility();
88 #endif // OS_WIN
89 return new ServiceDiscoveryClientMdns();
90 #endif
93 #else
95 scoped_refptr<ServiceDiscoverySharedClient>
96 ServiceDiscoverySharedClient::GetInstance() {
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
98 NOTIMPLEMENTED();
99 return NULL;
102 #endif // ENABLE_MDNS
104 } // namespace local_discovery