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

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

Issue 2850993002: [CrOS Tether] Add the HasConnectedToHost network field to NetworkStateHandler. (Closed)
Patch Set: Created 3 years, 7 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/command_line.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid( 493 const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
494 const std::string& guid) const { 494 const std::string& guid) const {
495 DCHECK(!guid.empty()); 495 DCHECK(!guid.empty());
496 return GetModifiableNetworkStateFromGuid(guid); 496 return GetModifiableNetworkStateFromGuid(guid);
497 } 497 }
498 498
499 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, 499 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid,
500 const std::string& name, 500 const std::string& name,
501 const std::string& carrier, 501 const std::string& carrier,
502 int battery_percentage, 502 int battery_percentage,
503 int signal_strength) { 503 int signal_strength,
504 bool has_connected_to_host) {
504 DCHECK(!guid.empty()); 505 DCHECK(!guid.empty());
505 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); 506 DCHECK(battery_percentage >= 0 && battery_percentage <= 100);
506 DCHECK(signal_strength >= 0 && signal_strength <= 100); 507 DCHECK(signal_strength >= 0 && signal_strength <= 100);
507 508
508 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { 509 if (tether_technology_state_ != TECHNOLOGY_ENABLED) {
509 NET_LOG(ERROR) << "AddTetherNetworkState() called when Tether networks " 510 NET_LOG(ERROR) << "AddTetherNetworkState() called when Tether networks "
510 << "are not enabled. Cannot add NetworkState."; 511 << "are not enabled. Cannot add NetworkState.";
511 return; 512 return;
512 } 513 }
513 514
(...skipping 10 matching lines...) Expand all
524 525
525 tether_network_state->set_name(name); 526 tether_network_state->set_name(name);
526 tether_network_state->set_type(kTypeTether); 527 tether_network_state->set_type(kTypeTether);
527 tether_network_state->SetGuid(guid); 528 tether_network_state->SetGuid(guid);
528 tether_network_state->set_visible(true); 529 tether_network_state->set_visible(true);
529 tether_network_state->set_update_received(); 530 tether_network_state->set_update_received();
530 tether_network_state->set_update_requested(false); 531 tether_network_state->set_update_requested(false);
531 tether_network_state->set_connectable(true); 532 tether_network_state->set_connectable(true);
532 tether_network_state->set_carrier(carrier); 533 tether_network_state->set_carrier(carrier);
533 tether_network_state->set_battery_percentage(battery_percentage); 534 tether_network_state->set_battery_percentage(battery_percentage);
534 // TODO(khorimoto): Add this field as a parameter to this function and set it 535 tether_network_state->set_tether_has_connected_to_host(has_connected_to_host);
535 // accordingly from the Tether component.
536 tether_network_state->set_tether_has_connected_to_host(false);
537 tether_network_state->set_signal_strength(signal_strength); 536 tether_network_state->set_signal_strength(signal_strength);
538 537
539 tether_network_list_.push_back(std::move(tether_network_state)); 538 tether_network_list_.push_back(std::move(tether_network_state));
540 NotifyNetworkListChanged(); 539 NotifyNetworkListChanged();
541 } 540 }
542 541
543 bool NetworkStateHandler::UpdateTetherNetworkProperties( 542 bool NetworkStateHandler::UpdateTetherNetworkProperties(
544 const std::string& guid, 543 const std::string& guid,
545 const std::string& carrier, 544 const std::string& carrier,
546 int battery_percentage, 545 int battery_percentage,
547 int signal_strength) { 546 int signal_strength) {
548 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { 547 if (tether_technology_state_ != TECHNOLOGY_ENABLED) {
549 NET_LOG(ERROR) << "UpdateTetherNetworkProperties() called when Tether " 548 NET_LOG(ERROR) << "UpdateTetherNetworkProperties() called when Tether "
550 << "networks are not enabled. Cannot update."; 549 << "networks are not enabled. Cannot update.";
551 return false; 550 return false;
552 } 551 }
553 552
554 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); 553 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid);
555 if (!tether_network_state) 554 if (!tether_network_state) {
555 NET_LOG(ERROR) << "UpdateTetherNetworkProperties() called for Tether "
556 << "network with GUID " << guid << ", but this network is "
557 << "not currently registered. Cannot update.";
stevenjb 2017/05/01 16:11:31 nit: Very long messages like this in the log are a
Kyle Horimoto 2017/05/01 16:56:27 Done.
556 return false; 558 return false;
559 }
557 560
558 tether_network_state->set_carrier(carrier); 561 tether_network_state->set_carrier(carrier);
559 tether_network_state->set_battery_percentage(battery_percentage); 562 tether_network_state->set_battery_percentage(battery_percentage);
560 tether_network_state->set_signal_strength(signal_strength); 563 tether_network_state->set_signal_strength(signal_strength);
561 564
562 NotifyNetworkListChanged(); 565 NotifyNetworkListChanged();
563 return true; 566 return true;
564 } 567 }
565 568
566 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { 569 bool NetworkStateHandler::SetTetherNetworkHasConnectedToHost(
570 const std::string& guid) {
571 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid);
572 if (!tether_network_state) {
573 NET_LOG(ERROR) << "SetTetherNetworkHasConnectedToHost() called for Tether "
574 << "network which is not registered. GUID: " << guid;
stevenjb 2017/05/01 16:11:31 ditto
Kyle Horimoto 2017/05/01 16:56:27 Done.
575 return false;
576 }
577
578 bool old_tether_has_connected_to_host_value =
579 tether_network_state->tether_has_connected_to_host();
580 if (old_tether_has_connected_to_host_value) {
581 return false;
582 }
stevenjb 2017/05/01 16:11:31 if (tether_network_state->tether_has_connected_to_
Kyle Horimoto 2017/05/01 16:56:27 Done.
583
584 tether_network_state->set_tether_has_connected_to_host(true);
585 NotifyNetworkListChanged();
586 return true;
587 }
588
589 bool NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) {
567 for (auto iter = tether_network_list_.begin(); 590 for (auto iter = tether_network_list_.begin();
568 iter != tether_network_list_.end(); ++iter) { 591 iter != tether_network_list_.end(); ++iter) {
569 if (iter->get()->AsNetworkState()->guid() == guid) { 592 if (iter->get()->AsNetworkState()->guid() == guid) {
570 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid( 593 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid(
571 iter->get()->AsNetworkState()->tether_guid()); 594 iter->get()->AsNetworkState()->tether_guid());
572 if (wifi_network) 595 if (wifi_network)
573 wifi_network->set_tether_guid(std::string()); 596 wifi_network->set_tether_guid(std::string());
574 597
575 tether_network_list_.erase(iter); 598 tether_network_list_.erase(iter);
576 NotifyNetworkListChanged(); 599 NotifyNetworkListChanged();
577 return; 600 return true;
578 } 601 }
579 } 602 }
603
604 return false;
580 } 605 }
581 606
582 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( 607 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork(
583 const std::string& tether_network_guid, 608 const std::string& tether_network_guid,
584 const std::string& wifi_network_guid) { 609 const std::string& wifi_network_guid) {
585 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { 610 if (tether_technology_state_ != TECHNOLOGY_ENABLED) {
586 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " 611 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called "
587 << "when Tether networks are not enabled. Cannot " 612 << "when Tether networks are not enabled. Cannot "
588 << "associate."; 613 << "associate.";
589 return false; 614 return false;
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 if (type.MatchesType(shill::kTypeVPN)) 1446 if (type.MatchesType(shill::kTypeVPN))
1422 technologies.emplace_back(shill::kTypeVPN); 1447 technologies.emplace_back(shill::kTypeVPN);
1423 if (type.MatchesType(kTypeTether)) 1448 if (type.MatchesType(kTypeTether))
1424 technologies.emplace_back(kTypeTether); 1449 technologies.emplace_back(kTypeTether);
1425 1450
1426 CHECK_GT(technologies.size(), 0ul); 1451 CHECK_GT(technologies.size(), 0ul);
1427 return technologies; 1452 return technologies;
1428 } 1453 }
1429 1454
1430 } // namespace chromeos 1455 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698