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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/network_state_informer.cc

Issue 2836453003: tray: Show warning in network tray when VPN or proxy used. (Closed)
Patch Set: Fixed patch set 1 errors. Created 3 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/network_state_informer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/chromeos/login/network_state_informer.h" 5 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 11 matching lines...) Expand all
22 namespace chromeos { 22 namespace chromeos {
23 23
24 namespace { 24 namespace {
25 25
26 const char kNetworkStateOffline[] = "offline"; 26 const char kNetworkStateOffline[] = "offline";
27 const char kNetworkStateOnline[] = "online"; 27 const char kNetworkStateOnline[] = "online";
28 const char kNetworkStateCaptivePortal[] = "behind captive portal"; 28 const char kNetworkStateCaptivePortal[] = "behind captive portal";
29 const char kNetworkStateConnecting[] = "connecting"; 29 const char kNetworkStateConnecting[] = "connecting";
30 const char kNetworkStateProxyAuthRequired[] = "proxy auth required"; 30 const char kNetworkStateProxyAuthRequired[] = "proxy auth required";
31 31
32 bool HasDefaultNetworkProxyConfigured() {
33 const NetworkState* network =
34 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
35 if (!network)
36 return false;
37 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
38 std::unique_ptr<ProxyConfigDictionary> proxy_dict =
39 proxy_config::GetProxyConfigForNetwork(
40 NULL, g_browser_process->local_state(), *network, &onc_source);
41 ProxyPrefs::ProxyMode mode;
42 return (proxy_dict && proxy_dict->GetMode(&mode) &&
43 mode == ProxyPrefs::MODE_FIXED_SERVERS);
44 }
45
46 NetworkStateInformer::State GetStateForDefaultNetwork() { 32 NetworkStateInformer::State GetStateForDefaultNetwork() {
47 const NetworkState* network = 33 const NetworkState* network =
48 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 34 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
49 if (!network) 35 if (!network)
50 return NetworkStateInformer::OFFLINE; 36 return NetworkStateInformer::OFFLINE;
51 37
52 if (network_portal_detector::GetInstance()->IsEnabled()) { 38 if (network_portal_detector::GetInstance()->IsEnabled()) {
53 NetworkPortalDetector::CaptivePortalState state = 39 NetworkPortalDetector::CaptivePortalState state =
54 network_portal_detector::GetInstance()->GetCaptivePortalState( 40 network_portal_detector::GetInstance()->GetCaptivePortalState(
55 network->guid()); 41 network->guid());
56 NetworkPortalDetector::CaptivePortalStatus status = state.status; 42 NetworkPortalDetector::CaptivePortalStatus status = state.status;
57 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && 43 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN &&
58 NetworkState::StateIsConnecting(network->connection_state())) { 44 NetworkState::StateIsConnecting(network->connection_state())) {
59 return NetworkStateInformer::CONNECTING; 45 return NetworkStateInformer::CONNECTING;
60 } 46 }
61 // For proxy-less networks rely on shill's online state if 47 // For proxy-less networks rely on shill's online state if
62 // NetworkPortalDetector's state of current network is unknown. 48 // NetworkPortalDetector's state of current network is unknown.
63 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE || 49 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE ||
64 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && 50 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN &&
65 !HasDefaultNetworkProxyConfigured() && 51 !NetworkStateInformer::HasDefaultNetworkProxyConfigured() &&
66 network->connection_state() == shill::kStateOnline)) { 52 network->connection_state() == shill::kStateOnline)) {
67 return NetworkStateInformer::ONLINE; 53 return NetworkStateInformer::ONLINE;
68 } 54 }
69 if (status == 55 if (status ==
70 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED && 56 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED &&
71 HasDefaultNetworkProxyConfigured()) { 57 NetworkStateInformer::HasDefaultNetworkProxyConfigured()) {
72 return NetworkStateInformer::PROXY_AUTH_REQUIRED; 58 return NetworkStateInformer::PROXY_AUTH_REQUIRED;
73 } 59 }
74 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL || 60 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL ||
75 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN && 61 (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN &&
76 network->is_captive_portal())) 62 network->is_captive_portal()))
77 return NetworkStateInformer::CAPTIVE_PORTAL; 63 return NetworkStateInformer::CAPTIVE_PORTAL;
78 } else { 64 } else {
79 if (NetworkState::StateIsConnecting(network->connection_state())) 65 if (NetworkState::StateIsConnecting(network->connection_state()))
80 return NetworkStateInformer::CONNECTING; 66 return NetworkStateInformer::CONNECTING;
81 if (network->connection_state() == shill::kStateOnline) 67 if (network->connection_state() == shill::kStateOnline)
(...skipping 10 matching lines...) Expand all
92 policy::BrowserPolicyConnectorChromeOS* connector = 78 policy::BrowserPolicyConnectorChromeOS* connector =
93 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 79 g_browser_process->platform_part()->browser_policy_connector_chromeos();
94 if (connector->IsActiveDirectoryManaged()) 80 if (connector->IsActiveDirectoryManaged())
95 return NetworkStateInformer::ONLINE; 81 return NetworkStateInformer::ONLINE;
96 82
97 return NetworkStateInformer::OFFLINE; 83 return NetworkStateInformer::OFFLINE;
98 } 84 }
99 85
100 } // namespace 86 } // namespace
101 87
88 // static
89 bool NetworkStateInformer::HasDefaultNetworkProxyConfigured() {
90 const NetworkState* network =
91 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
92 if (!network)
93 return false;
94 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
95 std::unique_ptr<ProxyConfigDictionary> proxy_dict =
96 proxy_config::GetProxyConfigForNetwork(
97 NULL, g_browser_process->local_state(), *network, &onc_source);
stevenjb 2017/04/21 17:30:52 Ugh, yeah, this is a pain. However, we deal with t
98 ProxyPrefs::ProxyMode mode;
99 return (proxy_dict && proxy_dict->GetMode(&mode) &&
100 mode == ProxyPrefs::MODE_FIXED_SERVERS);
101 }
102
102 NetworkStateInformer::NetworkStateInformer() 103 NetworkStateInformer::NetworkStateInformer()
103 : state_(OFFLINE), 104 : state_(OFFLINE),
104 weak_ptr_factory_(this) { 105 weak_ptr_factory_(this) {
105 } 106 }
106 107
107 NetworkStateInformer::~NetworkStateInformer() { 108 NetworkStateInformer::~NetworkStateInformer() {
108 if (NetworkHandler::IsInitialized()) { 109 if (NetworkHandler::IsInitialized()) {
109 NetworkHandler::Get()->network_state_handler()->RemoveObserver( 110 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
110 this, FROM_HERE); 111 this, FROM_HERE);
111 } 112 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 SendStateToObservers(NetworkError::ERROR_REASON_UPDATE); 216 SendStateToObservers(NetworkError::ERROR_REASON_UPDATE);
216 } 217 }
217 218
218 void NetworkStateInformer::SendStateToObservers( 219 void NetworkStateInformer::SendStateToObservers(
219 NetworkError::ErrorReason reason) { 220 NetworkError::ErrorReason reason) {
220 for (NetworkStateInformerObserver& observer : observers_) 221 for (NetworkStateInformerObserver& observer : observers_)
221 observer.UpdateState(reason); 222 observer.UpdateState(reason);
222 } 223 }
223 224
224 } // namespace chromeos 225 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/network_state_informer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698