OLD | NEW |
---|---|
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 Loading... | |
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::ConvertSignalStrength(int signal_strength) { | |
640 // Shill attempts to convert attempts to convert from its internal dBm to a | |
Thiemo Nagel
2015/04/16 15:16:33
Please remove duplicate "attempts to convert".
Andrew T Wilson (Slow)
2015/04/17 14:41:02
Done.
| |
641 // percentage range (from 1-100) by subtracting 120 from the raw dBm value, | |
Thiemo Nagel
2015/04/16 15:16:33
s/1-100/0-100/
s/substracting 120 from/adding 120
Andrew T Wilson (Slow)
2015/04/17 14:41:02
Done.
| |
642 // and then clamping the result to the range 1-100. | |
Thiemo Nagel
2015/04/16 15:16:33
s/1-100/0-100/
I'd suggest to include some kind o
Andrew T Wilson (Slow)
2015/04/17 14:41:02
Done.
| |
643 // | |
644 // To convert back to dBm, we subtract 120 from the percentage value to yield | |
645 // a clamped dBm value in the range of -119 to -20dBm. | |
646 // | |
647 // TODO(atwilson): Tunnel the raw dBm signal strength from Shill instead of | |
648 // doing the conversion here so we can report non-clamped values | |
649 // (crbug.com/463334). | |
650 DCHECK_GT(signal_strength, 0); | |
651 DCHECK_LE(signal_strength, 100); | |
652 return signal_strength - 120; | |
653 } | |
654 | |
639 void DeviceStatusCollector::GetNetworkInterfaces( | 655 void DeviceStatusCollector::GetNetworkInterfaces( |
640 em::DeviceStatusReportRequest* request) { | 656 em::DeviceStatusReportRequest* request) { |
641 // Maps shill device type strings to proto enum constants. | 657 // Maps shill device type strings to proto enum constants. |
642 static const struct { | 658 static const struct { |
643 const char* type_string; | 659 const char* type_string; |
644 em::NetworkInterface::NetworkDeviceType type_constant; | 660 em::NetworkInterface::NetworkDeviceType type_constant; |
645 } kDeviceTypeMap[] = { | 661 } kDeviceTypeMap[] = { |
646 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, }, | 662 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, }, |
647 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, }, | 663 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, }, |
648 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, }, | 664 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, }, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 } | 717 } |
702 | 718 |
703 // Don't write any network state if we aren't in a kiosk session. | 719 // Don't write any network state if we aren't in a kiosk session. |
704 if (!GetAutoLaunchedKioskSessionInfo()) | 720 if (!GetAutoLaunchedKioskSessionInfo()) |
705 return; | 721 return; |
706 | 722 |
707 // Walk the various networks and store their state in the status report. | 723 // Walk the various networks and store their state in the status report. |
708 chromeos::NetworkStateHandler::NetworkStateList state_list; | 724 chromeos::NetworkStateHandler::NetworkStateList state_list; |
709 network_state_handler->GetNetworkListByType( | 725 network_state_handler->GetNetworkListByType( |
710 chromeos::NetworkTypePattern::Default(), | 726 chromeos::NetworkTypePattern::Default(), |
711 true, // configured_only | 727 true, // configured_only |
Thiemo Nagel
2015/04/16 15:16:33
At that occasion: Please insert a blank in front o
Andrew T Wilson (Slow)
2015/04/17 14:41:01
Done.
Thiemo Nagel
2015/04/17 15:04:49
You fixed it in the other file, but not here. :)
Andrew T Wilson (Slow)
2015/04/17 15:37:51
Gah, fixed here too.
| |
712 false, // visible_only, | 728 false, // visible_only, |
713 0, // no limit to number of results | 729 0, // no limit to number of results |
714 &state_list); | 730 &state_list); |
715 | 731 |
716 for (const chromeos::NetworkState* state: state_list) { | 732 for (const chromeos::NetworkState* state: state_list) { |
717 // Determine the connection state and signal strength for |state|. | 733 // Determine the connection state and signal strength for |state|. |
718 em::NetworkState::ConnectionState connection_state_enum = | 734 em::NetworkState::ConnectionState connection_state_enum = |
719 em::NetworkState::UNKNOWN; | 735 em::NetworkState::UNKNOWN; |
720 const std::string connection_state_string(state->connection_state()); | 736 const std::string connection_state_string(state->connection_state()); |
721 for (size_t i = 0; i < arraysize(kConnectionStateMap); ++i) { | 737 for (size_t i = 0; i < arraysize(kConnectionStateMap); ++i) { |
722 if (connection_state_string == kConnectionStateMap[i].state_string) { | 738 if (connection_state_string == kConnectionStateMap[i].state_string) { |
723 connection_state_enum = kConnectionStateMap[i].state_constant; | 739 connection_state_enum = kConnectionStateMap[i].state_constant; |
724 break; | 740 break; |
725 } | 741 } |
726 } | 742 } |
727 | 743 |
728 // Copy fields from NetworkState into the status report. | 744 // Copy fields from NetworkState into the status report. |
729 em::NetworkState* proto_state = request->add_network_state(); | 745 em::NetworkState* proto_state = request->add_network_state(); |
730 proto_state->set_connection_state(connection_state_enum); | 746 proto_state->set_connection_state(connection_state_enum); |
731 proto_state->set_signal_strength(state->signal_strength()); | 747 // If shill has provided a signal strength, convert it to dBm and store it |
Thiemo Nagel
2015/04/16 15:16:33
As far as I can see, this specific conversion shou
Andrew T Wilson (Slow)
2015/04/17 14:41:02
Only report this now for wifi networks.
| |
748 // in the status report. | |
749 if (state->signal_strength()) { | |
750 proto_state->set_signal_strength( | |
751 ConvertSignalStrength(state->signal_strength())); | |
752 } | |
732 if (!state->device_path().empty()) | 753 if (!state->device_path().empty()) |
733 proto_state->set_device_path(state->device_path()); | 754 proto_state->set_device_path(state->device_path()); |
734 | 755 |
735 if (!state->ip_address().empty()) | 756 if (!state->ip_address().empty()) |
736 proto_state->set_ip_address(state->ip_address()); | 757 proto_state->set_ip_address(state->ip_address()); |
737 | 758 |
738 if (!state->gateway().empty()) | 759 if (!state->gateway().empty()) |
739 proto_state->set_gateway(state->gateway()); | 760 proto_state->set_gateway(state->gateway()); |
740 } | 761 } |
741 } | 762 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 ScheduleGeolocationUpdateRequest(); | 948 ScheduleGeolocationUpdateRequest(); |
928 } | 949 } |
929 | 950 |
930 void DeviceStatusCollector::ReceiveVolumeInfo( | 951 void DeviceStatusCollector::ReceiveVolumeInfo( |
931 const std::vector<em::VolumeInfo>& info) { | 952 const std::vector<em::VolumeInfo>& info) { |
932 if (report_hardware_status_) | 953 if (report_hardware_status_) |
933 volume_info_ = info; | 954 volume_info_ = info; |
934 } | 955 } |
935 | 956 |
936 } // namespace policy | 957 } // namespace policy |
OLD | NEW |