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

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

Issue 2850993002: [CrOS Tether] Add the HasConnectedToHost network field to NetworkStateHandler. (Closed)
Patch Set: stevenjb@ comments. 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(): No NetworkState for "
556 << "Tether network with GUID \"" << guid << "\".";
556 return false; 557 return false;
558 }
557 559
558 tether_network_state->set_carrier(carrier); 560 tether_network_state->set_carrier(carrier);
559 tether_network_state->set_battery_percentage(battery_percentage); 561 tether_network_state->set_battery_percentage(battery_percentage);
560 tether_network_state->set_signal_strength(signal_strength); 562 tether_network_state->set_signal_strength(signal_strength);
561 563
562 NotifyNetworkListChanged(); 564 NotifyNetworkListChanged();
563 return true; 565 return true;
564 } 566 }
565 567
566 void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { 568 bool NetworkStateHandler::SetTetherNetworkHasConnectedToHost(
569 const std::string& guid) {
570 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid);
571 if (!tether_network_state) {
572 NET_LOG(ERROR) << "SetTetherNetworkHasConnectedToHost(): No NetworkState "
573 << "for Tether network with GUID \"" << guid << "\".";
574 return false;
575 }
576
577 if (tether_network_state->tether_has_connected_to_host()) {
578 return false;
579 }
580
581 tether_network_state->set_tether_has_connected_to_host(true);
582 NotifyNetworkListChanged();
583 return true;
584 }
585
586 bool NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) {
567 for (auto iter = tether_network_list_.begin(); 587 for (auto iter = tether_network_list_.begin();
568 iter != tether_network_list_.end(); ++iter) { 588 iter != tether_network_list_.end(); ++iter) {
569 if (iter->get()->AsNetworkState()->guid() == guid) { 589 if (iter->get()->AsNetworkState()->guid() == guid) {
570 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid( 590 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid(
571 iter->get()->AsNetworkState()->tether_guid()); 591 iter->get()->AsNetworkState()->tether_guid());
572 if (wifi_network) 592 if (wifi_network)
573 wifi_network->set_tether_guid(std::string()); 593 wifi_network->set_tether_guid(std::string());
574 594
575 tether_network_list_.erase(iter); 595 tether_network_list_.erase(iter);
576 NotifyNetworkListChanged(); 596 NotifyNetworkListChanged();
577 return; 597 return true;
578 } 598 }
579 } 599 }
600
601 return false;
580 } 602 }
581 603
582 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( 604 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork(
583 const std::string& tether_network_guid, 605 const std::string& tether_network_guid,
584 const std::string& wifi_network_guid) { 606 const std::string& wifi_network_guid) {
585 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { 607 if (tether_technology_state_ != TECHNOLOGY_ENABLED) {
586 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " 608 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called "
587 << "when Tether networks are not enabled. Cannot " 609 << "when Tether networks are not enabled. Cannot "
588 << "associate."; 610 << "associate.";
589 return false; 611 return false;
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 if (type.MatchesType(shill::kTypeVPN)) 1443 if (type.MatchesType(shill::kTypeVPN))
1422 technologies.emplace_back(shill::kTypeVPN); 1444 technologies.emplace_back(shill::kTypeVPN);
1423 if (type.MatchesType(kTypeTether)) 1445 if (type.MatchesType(kTypeTether))
1424 technologies.emplace_back(kTypeTether); 1446 technologies.emplace_back(kTypeTether);
1425 1447
1426 CHECK_GT(technologies.size(), 0ul); 1448 CHECK_GT(technologies.size(), 0ul);
1427 return technologies; 1449 return technologies;
1428 } 1450 }
1429 1451
1430 } // namespace chromeos 1452 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state_handler.h ('k') | chromeos/network/network_state_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698