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

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

Issue 1562593002: Fix potential crashes in NetworkHandler code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test
Patch Set: Call NetworkStateHandler::Shutdown in destructor for unit tests Created 4 years, 11 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/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::JSONWriter::WriteWithOptions( 60 base::JSONWriter::WriteWithOptions(
61 value, base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &vstr); 61 value, base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &vstr);
62 return vstr.empty() ? "''" : vstr; 62 return vstr.empty() ? "''" : vstr;
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 const char NetworkStateHandler::kDefaultCheckPortalList[] = 67 const char NetworkStateHandler::kDefaultCheckPortalList[] =
68 "ethernet,wifi,cellular"; 68 "ethernet,wifi,cellular";
69 69
70 NetworkStateHandler::NetworkStateHandler() : network_list_sorted_(false) { 70 NetworkStateHandler::NetworkStateHandler() {}
71
72 NetworkStateHandler::~NetworkStateHandler() {
oshima 2016/01/06 22:57:23 I believe Shutodnw() must have been called at this
stevenjb 2016/01/06 23:28:31 So, -usually- Shutdown will get called. However, i
oshima 2016/01/07 00:21:12 Yeah, I prefer to have the same code path on test
stevenjb 2016/01/07 17:07:47 So do I. Unfortunately sometimes that conflicts w
oshima 2016/01/07 18:14:17 There are multiple principals (minimizing divergen
73 Shutdown();
74 STLDeleteContainerPointers(network_list_.begin(), network_list_.end());
75 STLDeleteContainerPointers(device_list_.begin(), device_list_.end());
71 } 76 }
72 77
73 NetworkStateHandler::~NetworkStateHandler() { 78 void NetworkStateHandler::Shutdown() {
79 if (did_shutdown_)
80 return;
81 did_shutdown_ = true;
74 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, IsShuttingDown()); 82 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, IsShuttingDown());
75 STLDeleteContainerPointers(network_list_.begin(), network_list_.end());
76 STLDeleteContainerPointers(device_list_.begin(), device_list_.end());
77 } 83 }
78 84
79 void NetworkStateHandler::InitShillPropertyHandler() { 85 void NetworkStateHandler::InitShillPropertyHandler() {
80 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); 86 shill_property_handler_.reset(new internal::ShillPropertyHandler(this));
81 shill_property_handler_->Init(); 87 shill_property_handler_->Init();
82 } 88 }
83 89
84 // static 90 // static
85 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { 91 NetworkStateHandler* NetworkStateHandler::InitializeForTest() {
86 NetworkStateHandler* handler = new NetworkStateHandler(); 92 NetworkStateHandler* handler = new NetworkStateHandler();
87 handler->InitShillPropertyHandler(); 93 handler->InitShillPropertyHandler();
88 return handler; 94 return handler;
89 } 95 }
90 96
91 void NetworkStateHandler::AddObserver( 97 void NetworkStateHandler::AddObserver(
92 NetworkStateHandlerObserver* observer, 98 NetworkStateHandlerObserver* observer,
93 const tracked_objects::Location& from_here) { 99 const tracked_objects::Location& from_here) {
94 observers_.AddObserver(observer); 100 observers_.AddObserver(observer);
95 device_event_log::AddEntry(from_here.file_name(), from_here.line_number(), 101 device_event_log::AddEntry(
96 device_event_log::LOG_TYPE_NETWORK, 102 from_here.file_name(), from_here.line_number(),
97 device_event_log::LOG_LEVEL_DEBUG, 103 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG,
98 "NetworkStateHandler::AddObserver"); 104 base::StringPrintf("NetworkStateHandler::AddObserver: 0x%p", observer));
105
106 LOG(ERROR) << "ADD Observer: " << from_here.file_name() << ":"
107 << from_here.line_number() << ": " << observer;
99 } 108 }
100 109
101 void NetworkStateHandler::RemoveObserver( 110 void NetworkStateHandler::RemoveObserver(
102 NetworkStateHandlerObserver* observer, 111 NetworkStateHandlerObserver* observer,
103 const tracked_objects::Location& from_here) { 112 const tracked_objects::Location& from_here) {
104 observers_.RemoveObserver(observer); 113 observers_.RemoveObserver(observer);
105 device_event_log::AddEntry(from_here.file_name(), from_here.line_number(), 114 device_event_log::AddEntry(
106 device_event_log::LOG_TYPE_NETWORK, 115 from_here.file_name(), from_here.line_number(),
107 device_event_log::LOG_LEVEL_DEBUG, 116 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG,
108 "NetworkStateHandler::RemoveObserver"); 117 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p",
118 observer));
119
120 LOG(ERROR) << "REM Observer: " << from_here.file_name() << ":"
121 << from_here.line_number() << ": " << observer;
109 } 122 }
110 123
111 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( 124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState(
112 const NetworkTypePattern& type) const { 125 const NetworkTypePattern& type) const {
113 std::string technology = GetTechnologyForType(type); 126 std::string technology = GetTechnologyForType(type);
114 TechnologyState state; 127 TechnologyState state;
115 if (shill_property_handler_->IsTechnologyEnabled(technology)) 128 if (shill_property_handler_->IsTechnologyEnabled(technology))
116 state = TECHNOLOGY_ENABLED; 129 state = TECHNOLOGY_ENABLED;
117 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 130 else if (shill_property_handler_->IsTechnologyEnabling(technology))
118 state = TECHNOLOGY_ENABLING; 131 state = TECHNOLOGY_ENABLING;
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 if (type.MatchesType(shill::kTypeBluetooth)) 1009 if (type.MatchesType(shill::kTypeBluetooth))
997 technologies.push_back(new std::string(shill::kTypeBluetooth)); 1010 technologies.push_back(new std::string(shill::kTypeBluetooth));
998 if (type.MatchesType(shill::kTypeVPN)) 1011 if (type.MatchesType(shill::kTypeVPN))
999 technologies.push_back(new std::string(shill::kTypeVPN)); 1012 technologies.push_back(new std::string(shill::kTypeVPN));
1000 1013
1001 CHECK_GT(technologies.size(), 0ul); 1014 CHECK_GT(technologies.size(), 0ul);
1002 return technologies; 1015 return technologies;
1003 } 1016 }
1004 1017
1005 } // namespace chromeos 1018 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698