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

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 2701463003: Create a Tether section in the system tray network list. (Closed)
Patch Set: Remove hack. Created 3 years, 10 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 (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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "base/format_macros.h" 11 #include "base/format_macros.h"
11 #include "base/guid.h" 12 #include "base/guid.h"
12 #include "base/json/json_string_value_serializer.h" 13 #include "base/json/json_string_value_serializer.h"
13 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/values.h" 22 #include "base/values.h"
23 #include "chromeos/chromeos_switches.h"
22 #include "chromeos/network/device_state.h" 24 #include "chromeos/network/device_state.h"
23 #include "chromeos/network/network_event_log.h" 25 #include "chromeos/network/network_event_log.h"
24 #include "chromeos/network/network_state.h" 26 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler_observer.h" 27 #include "chromeos/network/network_state_handler_observer.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h" 28 #include "third_party/cros_system_api/dbus/service_constants.h"
27 29
28 namespace chromeos { 30 namespace chromeos {
29 31
30 namespace { 32 namespace {
31 33
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (shill_property_handler_->IsTechnologyEnabled(technology)) 128 if (shill_property_handler_->IsTechnologyEnabled(technology))
127 state = TECHNOLOGY_ENABLED; 129 state = TECHNOLOGY_ENABLED;
128 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 130 else if (shill_property_handler_->IsTechnologyEnabling(technology))
129 state = TECHNOLOGY_ENABLING; 131 state = TECHNOLOGY_ENABLING;
130 else if (shill_property_handler_->IsTechnologyProhibited(technology)) 132 else if (shill_property_handler_->IsTechnologyProhibited(technology))
131 state = TECHNOLOGY_PROHIBITED; 133 state = TECHNOLOGY_PROHIBITED;
132 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) 134 else if (shill_property_handler_->IsTechnologyUninitialized(technology))
133 state = TECHNOLOGY_UNINITIALIZED; 135 state = TECHNOLOGY_UNINITIALIZED;
134 else if (shill_property_handler_->IsTechnologyAvailable(technology)) 136 else if (shill_property_handler_->IsTechnologyAvailable(technology))
135 state = TECHNOLOGY_AVAILABLE; 137 state = TECHNOLOGY_AVAILABLE;
136 else 138 else if (technology == kTypeTether) {
139 bool isTetherAvailable = base::CommandLine::ForCurrentProcess()->HasSwitch(
140 chromeos::switches::kEnableTether);
141 if (isTetherAvailable) {
142 // TODO (hansberry): Figure this one out.
143 bool isTetherEnabled = true;
144 if (isTetherEnabled) {
145 return TECHNOLOGY_ENABLED;
146 }
147 return TECHNOLOGY_AVAILABLE;
stevenjb 2017/02/16 22:56:35 Avoid the placeholder code, just return TECHNOLOGY
Ryan Hansberry 2017/02/17 19:29:42 Done. Added testing.
148 }
149 } else
137 state = TECHNOLOGY_UNAVAILABLE; 150 state = TECHNOLOGY_UNAVAILABLE;
138 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; 151 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state;
139 return state; 152 return state;
140 } 153 }
141 154
142 void NetworkStateHandler::SetTechnologyEnabled( 155 void NetworkStateHandler::SetTechnologyEnabled(
143 const NetworkTypePattern& type, 156 const NetworkTypePattern& type,
144 bool enabled, 157 bool enabled,
145 const network_handler::ErrorCallback& error_callback) { 158 const network_handler::ErrorCallback& error_callback) {
146 std::vector<std::string> technologies = GetTechnologiesForType(type); 159 std::vector<std::string> technologies = GetTechnologiesForType(type);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 295 }
283 296
284 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, 297 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
285 bool configured_only, 298 bool configured_only,
286 bool visible_only, 299 bool visible_only,
287 int limit, 300 int limit,
288 NetworkStateList* list) { 301 NetworkStateList* list) {
289 DCHECK(list); 302 DCHECK(list);
290 list->clear(); 303 list->clear();
291 int count = 0; 304 int count = 0;
305
306 if (NetworkTypePattern::Tether().MatchesPattern(type)) {
307 for (auto iter = tether_network_list_.begin();
308 iter != tether_network_list_.end(); ++iter) {
309 list->push_back((*iter)->AsNetworkState());
310 if (limit > 0 && ++count >= limit)
311 return;
312 }
313 }
314
292 // Sort the network list if necessary. 315 // Sort the network list if necessary.
293 if (!network_list_sorted_) 316 if (!network_list_sorted_)
294 SortNetworkList(); 317 SortNetworkList();
295 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { 318 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) {
296 const NetworkState* network = (*iter)->AsNetworkState(); 319 const NetworkState* network = (*iter)->AsNetworkState();
297 DCHECK(network); 320 DCHECK(network);
298 if (!network->update_received() || !network->Matches(type)) 321 if (!network->update_received() || !network->Matches(type))
299 continue; 322 continue;
300 if (configured_only && !network->IsInProfile()) 323 if (configured_only && !network->IsInProfile())
301 continue; 324 continue;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 364 }
342 365
343 return nullptr; 366 return nullptr;
344 } 367 }
345 368
346 const std::string NetworkStateHandler::CreateTetherNetworkState( 369 const std::string NetworkStateHandler::CreateTetherNetworkState(
347 const std::string& name) { 370 const std::string& name) {
348 const std::string& guid = base::GenerateGUID(); 371 const std::string& guid = base::GenerateGUID();
349 372
350 std::unique_ptr<NetworkState> tether_managed_state = 373 std::unique_ptr<NetworkState> tether_managed_state =
351 base::MakeUnique<NetworkState>(base::GenerateGUID()); 374 base::MakeUnique<NetworkState>(base::GenerateGUID());
stevenjb 2017/02/16 22:56:35 Thinking about this some more, I think that the Te
Ryan Hansberry 2017/02/17 19:29:42 You're right, oops. Done.
352 375
353 tether_managed_state->set_name(name); 376 tether_managed_state->set_name(name);
354 tether_managed_state->set_type(kTypeTether); 377 tether_managed_state->set_type(kTypeTether);
355 tether_managed_state->SetGuid(guid); 378 tether_managed_state->SetGuid(guid);
356 tether_managed_state->set_update_received(); 379 tether_managed_state->set_update_received();
357 380
358 tether_network_list_.push_back(std::move(tether_managed_state)); 381 tether_network_list_.push_back(std::move(tether_managed_state));
359 NotifyNetworkListChanged(); 382 NotifyNetworkListChanged();
360 383
361 return guid; 384 return guid;
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1044
1022 // Prefer Wimax over Cellular only if it's available. 1045 // Prefer Wimax over Cellular only if it's available.
1023 if (type.MatchesType(shill::kTypeWimax) && 1046 if (type.MatchesType(shill::kTypeWimax) &&
1024 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) { 1047 shill_property_handler_->IsTechnologyAvailable(shill::kTypeWimax)) {
1025 return shill::kTypeWimax; 1048 return shill::kTypeWimax;
1026 } 1049 }
1027 1050
1028 if (type.MatchesType(shill::kTypeCellular)) 1051 if (type.MatchesType(shill::kTypeCellular))
1029 return shill::kTypeCellular; 1052 return shill::kTypeCellular;
1030 1053
1054 if (type.MatchesType(kTypeTether))
1055 return kTypeTether;
1056
1031 NOTREACHED(); 1057 NOTREACHED();
1032 return std::string(); 1058 return std::string();
1033 } 1059 }
1034 1060
1035 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( 1061 std::vector<std::string> NetworkStateHandler::GetTechnologiesForType(
1036 const NetworkTypePattern& type) const { 1062 const NetworkTypePattern& type) const {
1037 std::vector<std::string> technologies; 1063 std::vector<std::string> technologies;
1038 if (type.MatchesType(shill::kTypeEthernet)) 1064 if (type.MatchesType(shill::kTypeEthernet))
1039 technologies.emplace_back(shill::kTypeEthernet); 1065 technologies.emplace_back(shill::kTypeEthernet);
1040 if (type.MatchesType(shill::kTypeWifi)) 1066 if (type.MatchesType(shill::kTypeWifi))
1041 technologies.emplace_back(shill::kTypeWifi); 1067 technologies.emplace_back(shill::kTypeWifi);
1042 if (type.MatchesType(shill::kTypeWimax)) 1068 if (type.MatchesType(shill::kTypeWimax))
1043 technologies.emplace_back(shill::kTypeWimax); 1069 technologies.emplace_back(shill::kTypeWimax);
1044 if (type.MatchesType(shill::kTypeCellular)) 1070 if (type.MatchesType(shill::kTypeCellular))
1045 technologies.emplace_back(shill::kTypeCellular); 1071 technologies.emplace_back(shill::kTypeCellular);
1046 if (type.MatchesType(shill::kTypeBluetooth)) 1072 if (type.MatchesType(shill::kTypeBluetooth))
1047 technologies.emplace_back(shill::kTypeBluetooth); 1073 technologies.emplace_back(shill::kTypeBluetooth);
1048 if (type.MatchesType(shill::kTypeVPN)) 1074 if (type.MatchesType(shill::kTypeVPN))
1049 technologies.emplace_back(shill::kTypeVPN); 1075 technologies.emplace_back(shill::kTypeVPN);
1050 1076
1051 CHECK_GT(technologies.size(), 0ul); 1077 CHECK_GT(technologies.size(), 0ul);
1052 return technologies; 1078 return technologies;
1053 } 1079 }
1054 1080
1055 } // namespace chromeos 1081 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698