| 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) | 9 #if defined(OS_WIN) |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() { | 69 ServiceDiscoverySharedClient::~ServiceDiscoverySharedClient() { |
| 70 DCHECK_EQ(g_service_discovery_client, this); | 70 DCHECK_EQ(g_service_discovery_client, this); |
| 71 g_service_discovery_client = NULL; | 71 g_service_discovery_client = NULL; |
| 72 } | 72 } |
| 73 | 73 |
| 74 #if defined(ENABLE_MDNS) || defined(OS_MACOSX) | 74 #if defined(ENABLE_MDNS) || defined(OS_MACOSX) |
| 75 | 75 |
| 76 scoped_refptr<ServiceDiscoverySharedClient> | 76 scoped_refptr<ServiceDiscoverySharedClient> |
| 77 ServiceDiscoverySharedClient::GetInstance() { | 77 ServiceDiscoverySharedClient::GetInstance() { |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 | 79 |
| 80 if (g_service_discovery_client) | 80 if (g_service_discovery_client) |
| 81 return g_service_discovery_client; | 81 return g_service_discovery_client; |
| 82 | 82 |
| 83 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
| 84 if (!g_is_firewall_state_reported) { | 84 if (!g_is_firewall_state_reported) { |
| 85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 86 base::Bind(&ReportFirewallStats)); | 86 base::Bind(&ReportFirewallStats)); |
| 87 } | 87 } |
| 88 #endif // OS_WIN | 88 #endif // OS_WIN |
| 89 | 89 |
| 90 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
| 91 return ServiceDiscoveryClientMacFactory::CreateInstance(); | 91 return ServiceDiscoveryClientMacFactory::CreateInstance(); |
| 92 #else // OS_MACOSX | 92 #else // OS_MACOSX |
| 93 | 93 |
| 94 return new ServiceDiscoveryClientMdns(); | 94 return new ServiceDiscoveryClientMdns(); |
| 95 #endif // OS_MACOSX | 95 #endif // OS_MACOSX |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 void ServiceDiscoverySharedClient::GetInstanceWithoutAlert( | 99 void ServiceDiscoverySharedClient::GetInstanceWithoutAlert( |
| 100 const GetInstanceCallback& callback) { | 100 const GetInstanceCallback& callback) { |
| 101 #if !defined(OS_WIN) | 101 #if !defined(OS_WIN) |
| 102 | 102 |
| 103 scoped_refptr<ServiceDiscoverySharedClient> result = GetInstance(); | 103 scoped_refptr<ServiceDiscoverySharedClient> result = GetInstance(); |
| 104 return callback.Run(result); | 104 return callback.Run(result); |
| 105 | 105 |
| 106 #else // OS_WIN | 106 #else // OS_WIN |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 108 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what | 108 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what |
| 109 // to do with firewall for user-level installs. crbug.com/366408 | 109 // to do with firewall for user-level installs. crbug.com/366408 |
| 110 scoped_refptr<ServiceDiscoverySharedClient> result = | 110 scoped_refptr<ServiceDiscoverySharedClient> result = |
| 111 g_service_discovery_client; | 111 g_service_discovery_client; |
| 112 if (result.get()) | 112 if (result.get()) |
| 113 return callback.Run(result); | 113 return callback.Run(result); |
| 114 | 114 |
| 115 if (!g_is_firewall_state_reported) { | 115 if (!g_is_firewall_state_reported) { |
| 116 BrowserThread::PostTaskAndReply( | 116 BrowserThread::PostTaskAndReply( |
| 117 BrowserThread::FILE, | 117 BrowserThread::FILE, |
| 118 FROM_HERE, | 118 FROM_HERE, |
| 119 base::Bind(&ReportFirewallStats), | 119 base::Bind(&ReportFirewallStats), |
| 120 base::Bind(&ServiceDiscoverySharedClient::GetInstanceWithoutAlert, | 120 base::Bind(&ServiceDiscoverySharedClient::GetInstanceWithoutAlert, |
| 121 callback)); | 121 callback)); |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 | 124 |
| 125 result = | 125 result = |
| 126 g_is_firewall_ready ? GetInstance() : new ServiceDiscoveryClientUtility(); | 126 g_is_firewall_ready ? GetInstance() : new ServiceDiscoveryClientUtility(); |
| 127 callback.Run(result); | 127 callback.Run(result); |
| 128 #endif // OS_WIN | 128 #endif // OS_WIN |
| 129 } | 129 } |
| 130 | 130 |
| 131 #else | 131 #else |
| 132 | 132 |
| 133 scoped_refptr<ServiceDiscoverySharedClient> | 133 scoped_refptr<ServiceDiscoverySharedClient> |
| 134 ServiceDiscoverySharedClient::GetInstance() { | 134 ServiceDiscoverySharedClient::GetInstance() { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 136 NOTIMPLEMENTED(); | 136 NOTIMPLEMENTED(); |
| 137 return NULL; | 137 return NULL; |
| 138 } | 138 } |
| 139 | 139 |
| 140 #endif // ENABLE_MDNS | 140 #endif // ENABLE_MDNS |
| 141 | 141 |
| 142 } // namespace local_discovery | 142 } // namespace local_discovery |
| OLD | NEW |