OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 5 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 | 8 |
| 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 "chrome/browser/local_discovery/service_discovery_client_utility.h" |
| 14 #include "chrome/installer/util/browser_distribution.h" |
| 15 #include "chrome/installer/util/firewall_manager_win.h" |
| 16 #endif // OS_WIN |
| 17 |
9 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
10 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h" | 19 #include "chrome/browser/local_discovery/service_discovery_client_mac_factory.h" |
11 #endif | 20 #endif |
12 | 21 |
13 #if defined(ENABLE_MDNS) | 22 #if defined(ENABLE_MDNS) |
14 #include "chrome/browser/local_discovery/service_discovery_client_utility.h" | 23 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h" |
15 #endif // ENABLE_MDNS | 24 #endif // ENABLE_MDNS |
16 | 25 |
| 26 namespace { |
| 27 |
| 28 #if defined(OS_WIN) |
| 29 bool IsFirewallReady() { |
| 30 base::FilePath exe_path; |
| 31 if (PathService::Get(base::FILE_EXE, &exe_path)) |
| 32 return false; |
| 33 scoped_ptr<installer::FirewallManager> manager = |
| 34 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(), |
| 35 exe_path); |
| 36 if (!manager) |
| 37 return false; |
| 38 bool is_ready = manager->CanUseLocalPorts(); |
| 39 UMA_HISTOGRAM_BOOLEAN("LocalDiscovery.IsFirewallReady", is_ready); |
| 40 return is_ready; |
| 41 } |
| 42 #endif // OS_WIN |
| 43 |
| 44 } // namespace |
| 45 |
| 46 |
17 namespace local_discovery { | 47 namespace local_discovery { |
18 | 48 |
19 using content::BrowserThread; | 49 using content::BrowserThread; |
20 | 50 |
21 namespace { | 51 namespace { |
22 ServiceDiscoverySharedClient* g_service_discovery_client = NULL; | 52 ServiceDiscoverySharedClient* g_service_discovery_client = NULL; |
23 } // namespace | 53 } // namespace |
24 | 54 |
25 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() { | 55 ServiceDiscoverySharedClient::ServiceDiscoverySharedClient() { |
26 DCHECK(!g_service_discovery_client); | 56 DCHECK(!g_service_discovery_client); |
(...skipping 10 matching lines...) Expand all Loading... |
37 scoped_refptr<ServiceDiscoverySharedClient> | 67 scoped_refptr<ServiceDiscoverySharedClient> |
38 ServiceDiscoverySharedClient::GetInstance() { | 68 ServiceDiscoverySharedClient::GetInstance() { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
40 | 70 |
41 if (g_service_discovery_client) | 71 if (g_service_discovery_client) |
42 return g_service_discovery_client; | 72 return g_service_discovery_client; |
43 | 73 |
44 #if defined(OS_MACOSX) | 74 #if defined(OS_MACOSX) |
45 return ServiceDiscoveryClientMacFactory::CreateInstance(); | 75 return ServiceDiscoveryClientMacFactory::CreateInstance(); |
46 #else | 76 #else |
47 return new ServiceDiscoveryClientUtility(); | 77 |
| 78 #if defined(OS_WIN) |
| 79 static bool is_firewall_ready = IsFirewallReady(); |
| 80 if (!is_firewall_ready) { |
| 81 // TODO(vitalybuka): Remove after we find what to do with firewall for |
| 82 // user-level installs. crbug.com/366408 |
| 83 return new ServiceDiscoveryClientUtility(); |
| 84 } |
| 85 #endif // OS_WIN |
| 86 return new ServiceDiscoveryClientMdns(); |
48 #endif | 87 #endif |
49 } | 88 } |
50 | 89 |
51 #else | 90 #else |
52 | 91 |
53 scoped_refptr<ServiceDiscoverySharedClient> | 92 scoped_refptr<ServiceDiscoverySharedClient> |
54 ServiceDiscoverySharedClient::GetInstance() { | 93 ServiceDiscoverySharedClient::GetInstance() { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
56 NOTIMPLEMENTED(); | 95 NOTIMPLEMENTED(); |
57 return NULL; | 96 return NULL; |
58 } | 97 } |
59 | 98 |
60 #endif // ENABLE_MDNS | 99 #endif // ENABLE_MDNS |
61 | 100 |
62 } // namespace local_discovery | 101 } // namespace local_discovery |
OLD | NEW |