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

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

Issue 773703002: Generalize network_event_log -> device_event_log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + feedback Created 6 years 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
« no previous file with comments | « chromeos/network/network_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/json/json_string_value_serializer.h"
11 #include "base/json/json_writer.h"
10 #include "base/location.h" 12 #include "base/location.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 15 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "chromeos/network/device_state.h" 19 #include "chromeos/network/device_state.h"
18 #include "chromeos/network/managed_state.h" 20 #include "chromeos/network/managed_state.h"
19 #include "chromeos/network/network_event_log.h" 21 #include "chromeos/network/network_event_log.h"
(...skipping 24 matching lines...) Expand all
44 return ""; 46 return "";
45 } 47 }
46 48
47 std::string GetLogName(const ManagedState* state) { 49 std::string GetLogName(const ManagedState* state) {
48 if (!state) 50 if (!state)
49 return "None"; 51 return "None";
50 return base::StringPrintf("%s (%s)", state->name().c_str(), 52 return base::StringPrintf("%s (%s)", state->name().c_str(),
51 state->path().c_str()); 53 state->path().c_str());
52 } 54 }
53 55
56 std::string ValueAsString(const base::Value& value) {
57 std::string vstr;
58 base::JSONWriter::WriteWithOptions(
59 &value, base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &vstr);
60 return vstr.empty() ? "''" : vstr;
61 }
62
54 } // namespace 63 } // namespace
55 64
56 const char NetworkStateHandler::kDefaultCheckPortalList[] = 65 const char NetworkStateHandler::kDefaultCheckPortalList[] =
57 "ethernet,wifi,cellular"; 66 "ethernet,wifi,cellular";
58 67
59 NetworkStateHandler::NetworkStateHandler() 68 NetworkStateHandler::NetworkStateHandler()
60 : network_list_sorted_(false) { 69 : network_list_sorted_(false) {
61 } 70 }
62 71
63 NetworkStateHandler::~NetworkStateHandler() { 72 NetworkStateHandler::~NetworkStateHandler() {
(...skipping 11 matching lines...) Expand all
75 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { 84 NetworkStateHandler* NetworkStateHandler::InitializeForTest() {
76 NetworkStateHandler* handler = new NetworkStateHandler(); 85 NetworkStateHandler* handler = new NetworkStateHandler();
77 handler->InitShillPropertyHandler(); 86 handler->InitShillPropertyHandler();
78 return handler; 87 return handler;
79 } 88 }
80 89
81 void NetworkStateHandler::AddObserver( 90 void NetworkStateHandler::AddObserver(
82 NetworkStateHandlerObserver* observer, 91 NetworkStateHandlerObserver* observer,
83 const tracked_objects::Location& from_here) { 92 const tracked_objects::Location& from_here) {
84 observers_.AddObserver(observer); 93 observers_.AddObserver(observer);
85 network_event_log::internal::AddEntry( 94 device_event_log::AddEntry(from_here.file_name(), from_here.line_number(),
86 from_here.file_name(), from_here.line_number(), 95 device_event_log::LOG_TYPE_NETWORK,
87 network_event_log::LOG_LEVEL_DEBUG, 96 device_event_log::LOG_LEVEL_DEBUG,
88 "NetworkStateHandler::AddObserver", ""); 97 "NetworkStateHandler::AddObserver");
89 } 98 }
90 99
91 void NetworkStateHandler::RemoveObserver( 100 void NetworkStateHandler::RemoveObserver(
92 NetworkStateHandlerObserver* observer, 101 NetworkStateHandlerObserver* observer,
93 const tracked_objects::Location& from_here) { 102 const tracked_objects::Location& from_here) {
94 observers_.RemoveObserver(observer); 103 observers_.RemoveObserver(observer);
95 network_event_log::internal::AddEntry( 104 device_event_log::AddEntry(from_here.file_name(), from_here.line_number(),
96 from_here.file_name(), from_here.line_number(), 105 device_event_log::LOG_TYPE_NETWORK,
97 network_event_log::LOG_LEVEL_DEBUG, 106 device_event_log::LOG_LEVEL_DEBUG,
98 "NetworkStateHandler::RemoveObserver", ""); 107 "NetworkStateHandler::RemoveObserver");
99 } 108 }
100 109
101 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( 110 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState(
102 const NetworkTypePattern& type) const { 111 const NetworkTypePattern& type) const {
103 std::string technology = GetTechnologyForType(type); 112 std::string technology = GetTechnologyForType(type);
104 TechnologyState state; 113 TechnologyState state;
105 if (shill_property_handler_->IsTechnologyEnabled(technology)) 114 if (shill_property_handler_->IsTechnologyEnabled(technology))
106 state = TECHNOLOGY_ENABLED; 115 state = TECHNOLOGY_ENABLED;
107 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 116 else if (shill_property_handler_->IsTechnologyEnabling(technology))
108 state = TECHNOLOGY_ENABLING; 117 state = TECHNOLOGY_ENABLING;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 key != shill::kWifiFrequencyListProperty && 571 key != shill::kWifiFrequencyListProperty &&
563 (key != shill::kDeviceProperty || value_str != "/")) { 572 (key != shill::kDeviceProperty || value_str != "/")) {
564 std::string log_event = "NetworkPropertyUpdated"; 573 std::string log_event = "NetworkPropertyUpdated";
565 // Trigger a default network update for interesting changes only. 574 // Trigger a default network update for interesting changes only.
566 if (network->path() == default_network_path_) { 575 if (network->path() == default_network_path_) {
567 NotifyDefaultNetworkChanged(network); 576 NotifyDefaultNetworkChanged(network);
568 log_event = "Default" + log_event; 577 log_event = "Default" + log_event;
569 } 578 }
570 // Log event. 579 // Log event.
571 std::string detail = network->name() + "." + key; 580 std::string detail = network->name() + "." + key;
572 detail += " = " + network_event_log::ValueAsString(value); 581 detail += " = " + ValueAsString(value);
573 network_event_log::LogLevel log_level; 582 device_event_log::LogLevel log_level;
574 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { 583 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) {
575 log_level = network_event_log::LOG_LEVEL_ERROR; 584 log_level = device_event_log::LOG_LEVEL_ERROR;
576 } else { 585 } else {
577 log_level = network_event_log::LOG_LEVEL_EVENT; 586 log_level = device_event_log::LOG_LEVEL_EVENT;
578 } 587 }
579 NET_LOG_LEVEL(log_level, log_event, detail); 588 NET_LOG_LEVEL(log_level, log_event, detail);
580 } 589 }
581 } 590 }
582 591
583 // All property updates signal 'NetworkPropertiesUpdated'. 592 // All property updates signal 'NetworkPropertiesUpdated'.
584 NotifyNetworkPropertiesUpdated(network); 593 NotifyNetworkPropertiesUpdated(network);
585 594
586 // If added to a Profile, request a full update so that a NetworkState 595 // If added to a Profile, request a full update so that a NetworkState
587 // gets created. 596 // gets created.
588 if (prev_profile_path.empty() && !network->profile_path().empty()) 597 if (prev_profile_path.empty() && !network->profile_path().empty())
589 RequestUpdateForNetwork(service_path); 598 RequestUpdateForNetwork(service_path);
590 } 599 }
591 600
592 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 601 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
593 const std::string& key, 602 const std::string& key,
594 const base::Value& value) { 603 const base::Value& value) {
595 DeviceState* device = GetModifiableDeviceState(device_path); 604 DeviceState* device = GetModifiableDeviceState(device_path);
596 if (!device) 605 if (!device)
597 return; 606 return;
598 if (!device->PropertyChanged(key, value)) 607 if (!device->PropertyChanged(key, value))
599 return; 608 return;
600 609
601 std::string detail = device->name() + "." + key; 610 std::string detail = device->name() + "." + key;
602 detail += " = " + network_event_log::ValueAsString(value); 611 detail += " = " + ValueAsString(value);
603 NET_LOG_EVENT("DevicePropertyUpdated", detail); 612 NET_LOG_EVENT("DevicePropertyUpdated", detail);
604 613
605 NotifyDeviceListChanged(); 614 NotifyDeviceListChanged();
606 NotifyDevicePropertiesUpdated(device); 615 NotifyDevicePropertiesUpdated(device);
607 616
608 if (key == shill::kScanningProperty && device->scanning() == false) { 617 if (key == shill::kScanningProperty && device->scanning() == false) {
609 NotifyScanCompleted(device); 618 NotifyScanCompleted(device);
610 } 619 }
611 if (key == shill::kEapAuthenticationCompletedProperty) { 620 if (key == shill::kEapAuthenticationCompletedProperty) {
612 // Notify a change for each Ethernet service using this device. 621 // Notify a change for each Ethernet service using this device.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 if (type.MatchesType(shill::kTypeBluetooth)) 952 if (type.MatchesType(shill::kTypeBluetooth))
944 technologies.push_back(new std::string(shill::kTypeBluetooth)); 953 technologies.push_back(new std::string(shill::kTypeBluetooth));
945 if (type.MatchesType(shill::kTypeVPN)) 954 if (type.MatchesType(shill::kTypeVPN))
946 technologies.push_back(new std::string(shill::kTypeVPN)); 955 technologies.push_back(new std::string(shill::kTypeVPN));
947 956
948 CHECK_GT(technologies.size(), 0ul); 957 CHECK_GT(technologies.size(), 0ul);
949 return technologies.Pass(); 958 return technologies.Pass();
950 } 959 }
951 960
952 } // namespace chromeos 961 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698