Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/local_discovery/service_discovery_shared_client.cc

Issue 504223005: Check Firewall state only initializing mDns from PrintPreview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tue Aug 26 18:22:17 PDT 2014 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 #if defined(ENABLE_MDNS) 22 #if defined(ENABLE_MDNS)
23 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h" 23 #include "chrome/browser/local_discovery/service_discovery_client_mdns.h"
24 #include "chrome/browser/local_discovery/service_discovery_client_utility.h" 24 #include "chrome/browser/local_discovery/service_discovery_client_utility.h"
25 #endif // ENABLE_MDNS 25 #endif // ENABLE_MDNS
26 26
27 namespace { 27 namespace {
28 28
29 #if defined(OS_WIN) 29 #if defined(OS_WIN)
30 30
31 bool g_is_firewall_ready = false; 31 bool g_is_firewall_ready = false;
32 bool g_is_firewall_state_reported = false;
32 33
33 void ReportFirewallStats() { 34 void ReportFirewallStats() {
35 if (g_is_firewall_state_reported)
36 return;
37 g_is_firewall_state_reported = true;
34 base::FilePath exe_path; 38 base::FilePath exe_path;
35 if (!PathService::Get(base::FILE_EXE, &exe_path)) 39 if (!PathService::Get(base::FILE_EXE, &exe_path))
36 return; 40 return;
37 base::ElapsedTimer timer; 41 base::ElapsedTimer timer;
38 scoped_ptr<installer::FirewallManager> manager = 42 scoped_ptr<installer::FirewallManager> manager =
39 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(), 43 installer::FirewallManager::Create(BrowserDistribution::GetDistribution(),
40 exe_path); 44 exe_path);
41 if (!manager) 45 if (!manager)
42 return; 46 return;
43 g_is_firewall_ready = manager->CanUseLocalPorts(); 47 g_is_firewall_ready = manager->CanUseLocalPorts();
(...skipping 29 matching lines...) Expand all
73 ServiceDiscoverySharedClient::GetInstance() { 77 ServiceDiscoverySharedClient::GetInstance() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 79
76 if (g_service_discovery_client) 80 if (g_service_discovery_client)
77 return g_service_discovery_client; 81 return g_service_discovery_client;
78 82
79 #if defined(OS_MACOSX) 83 #if defined(OS_MACOSX)
80 return ServiceDiscoveryClientMacFactory::CreateInstance(); 84 return ServiceDiscoveryClientMacFactory::CreateInstance();
81 #else // OS_MACOSX 85 #else // OS_MACOSX
82 86
83 #if defined(OS_WIN) 87 return new ServiceDiscoveryClientMdns();
Noam Samuel 2014/08/27 17:58:56 Maybe do if (g_is_firewall_state_reported) { ret
Vitaly Buka (NO REVIEWS) 2014/08/27 18:08:27 Goal is always use ServiceDiscoveryClientMdns. Onl
84 static bool reported = 88 #endif // OS_MACOSX
85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 89 }
86 base::Bind(&ReportFirewallStats)); 90
91 // static
92 void ServiceDiscoverySharedClient::GetInstanceWithoutAlert(
93 const GetInstanceCallback& callback) {
94 #if !defined(OS_WIN)
95
96 scoped_refptr<ServiceDiscoverySharedClient> result = GetInstance();
97 return callback.Run(result);
98
99 #else // OS_WIN
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
87 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what 101 // TODO(vitalybuka): Switch to |ServiceDiscoveryClientMdns| after we find what
88 // to do with firewall for user-level installs. crbug.com/366408 102 // to do with firewall for user-level installs. crbug.com/366408
89 if (!g_is_firewall_ready) 103 scoped_refptr<ServiceDiscoverySharedClient> result =
90 return new ServiceDiscoveryClientUtility(); 104 g_service_discovery_client;
105 if (result)
106 return callback.Run(result);
107
108 if (!g_is_firewall_state_reported) {
109 BrowserThread::PostTaskAndReply(
110 BrowserThread::FILE,
111 FROM_HERE,
112 base::Bind(&ReportFirewallStats),
113 base::Bind(&ServiceDiscoverySharedClient::GetInstanceWithoutAlert,
114 callback));
115 return;
116 }
117
118 result =
119 g_is_firewall_ready ? GetInstance() : new ServiceDiscoveryClientUtility();
120 callback.Run(result);
91 #endif // OS_WIN 121 #endif // OS_WIN
92
93 return new ServiceDiscoveryClientMdns();
94 #endif // OS_MACOSX
95 } 122 }
96 123
97 #else 124 #else
98 125
99 scoped_refptr<ServiceDiscoverySharedClient> 126 scoped_refptr<ServiceDiscoverySharedClient>
100 ServiceDiscoverySharedClient::GetInstance() { 127 ServiceDiscoverySharedClient::GetInstance() {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
102 NOTIMPLEMENTED(); 129 NOTIMPLEMENTED();
103 return NULL; 130 return NULL;
104 } 131 }
105 132
106 #endif // ENABLE_MDNS 133 #endif // ENABLE_MDNS
107 134
108 } // namespace local_discovery 135 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698