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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector.cc

Issue 1062853005: Map signal_strength from percentage to dBm per spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really fixed comment Created 5 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
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/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <cstdio> 8 #include <cstdio>
9 #include <limits> 9 #include <limits>
10 #include <sstream> 10 #include <sstream>
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (position_.altitude_accuracy >= 0.) 629 if (position_.altitude_accuracy >= 0.)
630 location->set_altitude_accuracy(position_.altitude_accuracy); 630 location->set_altitude_accuracy(position_.altitude_accuracy);
631 if (position_.heading >= 0. && position_.heading <= 360) 631 if (position_.heading >= 0. && position_.heading <= 360)
632 location->set_heading(position_.heading); 632 location->set_heading(position_.heading);
633 if (position_.speed >= 0.) 633 if (position_.speed >= 0.)
634 location->set_speed(position_.speed); 634 location->set_speed(position_.speed);
635 location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE); 635 location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE);
636 } 636 }
637 } 637 }
638 638
639 int DeviceStatusCollector::ConvertWifiSignalStrength(int signal_strength) {
640 // Shill attempts to convert WiFi signal strength from its internal dBm to a
641 // percentage range (from 0-100) by adding 120 to the raw dBm value,
642 // and then clamping the result to the range 0-100 (see
643 // shill::WiFiService::SignalToStrength()).
644 //
645 // To convert back to dBm, we subtract 120 from the percentage value to yield
646 // a clamped dBm value in the range of -119 to -20dBm.
647 //
648 // TODO(atwilson): Tunnel the raw dBm signal strength from Shill instead of
649 // doing the conversion here so we can report non-clamped values
650 // (crbug.com/463334).
651 DCHECK_GT(signal_strength, 0);
652 DCHECK_LE(signal_strength, 100);
653 return signal_strength - 120;
654 }
655
639 void DeviceStatusCollector::GetNetworkInterfaces( 656 void DeviceStatusCollector::GetNetworkInterfaces(
640 em::DeviceStatusReportRequest* request) { 657 em::DeviceStatusReportRequest* request) {
641 // Maps shill device type strings to proto enum constants. 658 // Maps shill device type strings to proto enum constants.
642 static const struct { 659 static const struct {
643 const char* type_string; 660 const char* type_string;
644 em::NetworkInterface::NetworkDeviceType type_constant; 661 em::NetworkInterface::NetworkDeviceType type_constant;
645 } kDeviceTypeMap[] = { 662 } kDeviceTypeMap[] = {
646 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, }, 663 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, },
647 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, }, 664 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, },
648 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, }, 665 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, },
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 718 }
702 719
703 // Don't write any network state if we aren't in a kiosk session. 720 // Don't write any network state if we aren't in a kiosk session.
704 if (!GetAutoLaunchedKioskSessionInfo()) 721 if (!GetAutoLaunchedKioskSessionInfo())
705 return; 722 return;
706 723
707 // Walk the various networks and store their state in the status report. 724 // Walk the various networks and store their state in the status report.
708 chromeos::NetworkStateHandler::NetworkStateList state_list; 725 chromeos::NetworkStateHandler::NetworkStateList state_list;
709 network_state_handler->GetNetworkListByType( 726 network_state_handler->GetNetworkListByType(
710 chromeos::NetworkTypePattern::Default(), 727 chromeos::NetworkTypePattern::Default(),
711 true, // configured_only 728 true, // configured_only
712 false, // visible_only, 729 false, // visible_only
713 0, // no limit to number of results 730 0, // no limit to number of results
714 &state_list); 731 &state_list);
715 732
716 for (const chromeos::NetworkState* state: state_list) { 733 for (const chromeos::NetworkState* state: state_list) {
717 // Determine the connection state and signal strength for |state|. 734 // Determine the connection state and signal strength for |state|.
718 em::NetworkState::ConnectionState connection_state_enum = 735 em::NetworkState::ConnectionState connection_state_enum =
719 em::NetworkState::UNKNOWN; 736 em::NetworkState::UNKNOWN;
720 const std::string connection_state_string(state->connection_state()); 737 const std::string connection_state_string(state->connection_state());
721 for (size_t i = 0; i < arraysize(kConnectionStateMap); ++i) { 738 for (size_t i = 0; i < arraysize(kConnectionStateMap); ++i) {
722 if (connection_state_string == kConnectionStateMap[i].state_string) { 739 if (connection_state_string == kConnectionStateMap[i].state_string) {
723 connection_state_enum = kConnectionStateMap[i].state_constant; 740 connection_state_enum = kConnectionStateMap[i].state_constant;
724 break; 741 break;
725 } 742 }
726 } 743 }
727 744
728 // Copy fields from NetworkState into the status report. 745 // Copy fields from NetworkState into the status report.
729 em::NetworkState* proto_state = request->add_network_state(); 746 em::NetworkState* proto_state = request->add_network_state();
730 proto_state->set_connection_state(connection_state_enum); 747 proto_state->set_connection_state(connection_state_enum);
731 proto_state->set_signal_strength(state->signal_strength()); 748
749 // Report signal strength for wifi connections.
750 if (state->type() == shill::kTypeWifi) {
751 // If shill has provided a signal strength, convert it to dBm and store it
752 // in the status report. A signal_strength() of 0 connotes "no signal"
753 // rather than "really weak signal", so we only report signal strength if
754 // it is non-zero.
755 if (state->signal_strength()) {
756 proto_state->set_signal_strength(
757 ConvertWifiSignalStrength(state->signal_strength()));
758 }
759 }
760
732 if (!state->device_path().empty()) 761 if (!state->device_path().empty())
733 proto_state->set_device_path(state->device_path()); 762 proto_state->set_device_path(state->device_path());
734 763
735 if (!state->ip_address().empty()) 764 if (!state->ip_address().empty())
736 proto_state->set_ip_address(state->ip_address()); 765 proto_state->set_ip_address(state->ip_address());
737 766
738 if (!state->gateway().empty()) 767 if (!state->gateway().empty())
739 proto_state->set_gateway(state->gateway()); 768 proto_state->set_gateway(state->gateway());
740 } 769 }
741 } 770 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 ScheduleGeolocationUpdateRequest(); 956 ScheduleGeolocationUpdateRequest();
928 } 957 }
929 958
930 void DeviceStatusCollector::ReceiveVolumeInfo( 959 void DeviceStatusCollector::ReceiveVolumeInfo(
931 const std::vector<em::VolumeInfo>& info) { 960 const std::vector<em::VolumeInfo>& info) {
932 if (report_hardware_status_) 961 if (report_hardware_status_)
933 volume_info_ = info; 962 volume_info_ = info;
934 } 963 }
935 964
936 } // namespace policy 965 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698