OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_profile_handler.h" | 5 #include "chromeos/network/network_profile_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/dbus/shill_manager_client.h" | 13 #include "chromeos/dbus/shill_manager_client.h" |
14 #include "chromeos/dbus/shill_profile_client.h" | 14 #include "chromeos/dbus/shill_profile_client.h" |
15 #include "chromeos/network/network_profile_observer.h" | 15 #include "chromeos/network/network_profile_observer.h" |
16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
20 | 20 |
21 static NetworkProfileHandler* g_profile_handler_instance = NULL; | |
22 | |
23 namespace { | 21 namespace { |
24 | 22 |
25 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 23 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
26 std::vector<std::string>* result) { | 24 std::vector<std::string>* result) { |
27 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 25 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
28 std::string str; | 26 std::string str; |
29 if (!string_list.GetString(i, &str)) | 27 if (!string_list.GetString(i, &str)) |
30 return false; | 28 return false; |
31 result->push_back(str); | 29 result->push_back(str); |
32 } | 30 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 65 } |
68 | 66 |
69 virtual ~NetworkProfileHandlerImpl() { | 67 virtual ~NetworkProfileHandlerImpl() { |
70 DBusThreadManager::Get()->GetShillManagerClient()-> | 68 DBusThreadManager::Get()->GetShillManagerClient()-> |
71 RemovePropertyChangedObserver(this); | 69 RemovePropertyChangedObserver(this); |
72 } | 70 } |
73 }; | 71 }; |
74 | 72 |
75 } // namespace | 73 } // namespace |
76 | 74 |
77 // static | |
78 NetworkProfileHandler* NetworkProfileHandler::Initialize() { | |
79 CHECK(!g_profile_handler_instance); | |
80 g_profile_handler_instance = new NetworkProfileHandlerImpl(); | |
81 return g_profile_handler_instance; | |
82 } | |
83 | |
84 // static | |
85 bool NetworkProfileHandler::IsInitialized() { | |
86 return g_profile_handler_instance; | |
87 } | |
88 | |
89 // static | |
90 void NetworkProfileHandler::Shutdown() { | |
91 CHECK(g_profile_handler_instance); | |
92 delete g_profile_handler_instance; | |
93 g_profile_handler_instance = NULL; | |
94 } | |
95 | |
96 // static | |
97 NetworkProfileHandler* NetworkProfileHandler::Get() { | |
98 CHECK(g_profile_handler_instance); | |
99 return g_profile_handler_instance; | |
100 } | |
101 | |
102 void NetworkProfileHandler::AddObserver(NetworkProfileObserver* observer) { | 75 void NetworkProfileHandler::AddObserver(NetworkProfileObserver* observer) { |
103 observers_.AddObserver(observer); | 76 observers_.AddObserver(observer); |
104 } | 77 } |
105 | 78 |
106 void NetworkProfileHandler::RemoveObserver(NetworkProfileObserver* observer) { | 79 void NetworkProfileHandler::RemoveObserver(NetworkProfileObserver* observer) { |
107 observers_.RemoveObserver(observer); | 80 observers_.RemoveObserver(observer); |
108 } | 81 } |
109 | 82 |
110 void NetworkProfileHandler::GetManagerPropertiesCallback( | 83 void NetworkProfileHandler::GetManagerPropertiesCallback( |
111 DBusMethodCallStatus call_status, | 84 DBusMethodCallStatus call_status, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void NetworkProfileHandler::GetProfilePropertiesCallback( | 148 void NetworkProfileHandler::GetProfilePropertiesCallback( |
176 const std::string& profile_path, | 149 const std::string& profile_path, |
177 const base::DictionaryValue& properties) { | 150 const base::DictionaryValue& properties) { |
178 std::string userhash; | 151 std::string userhash; |
179 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, | 152 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, |
180 &userhash); | 153 &userhash); |
181 | 154 |
182 AddProfile(NetworkProfile(profile_path, userhash)); | 155 AddProfile(NetworkProfile(profile_path, userhash)); |
183 } | 156 } |
184 | 157 |
| 158 void NetworkProfileHandler::AddProfileForTest(const NetworkProfile& profile) { |
| 159 AddProfile(profile); |
| 160 } |
| 161 |
185 void NetworkProfileHandler::AddProfile(const NetworkProfile& profile) { | 162 void NetworkProfileHandler::AddProfile(const NetworkProfile& profile) { |
186 VLOG(2) << "Adding profile " << profile.ToDebugString() << "."; | 163 VLOG(2) << "Adding profile " << profile.ToDebugString() << "."; |
187 profiles_.push_back(profile); | 164 profiles_.push_back(profile); |
188 FOR_EACH_OBSERVER(NetworkProfileObserver, observers_, | 165 FOR_EACH_OBSERVER(NetworkProfileObserver, observers_, |
189 OnProfileAdded(profiles_.back())); | 166 OnProfileAdded(profiles_.back())); |
190 } | 167 } |
191 | 168 |
192 void NetworkProfileHandler::RemoveProfile(const std::string& profile_path) { | 169 void NetworkProfileHandler::RemoveProfile(const std::string& profile_path) { |
193 VLOG(2) << "Removing profile for path " << profile_path << "."; | 170 VLOG(2) << "Removing profile for path " << profile_path << "."; |
194 ProfileList::iterator found = std::find_if(profiles_.begin(), profiles_.end(), | 171 ProfileList::iterator found = std::find_if(profiles_.begin(), profiles_.end(), |
(...skipping 29 matching lines...) Expand all Loading... |
224 } | 201 } |
225 | 202 |
226 NetworkProfileHandler::NetworkProfileHandler() | 203 NetworkProfileHandler::NetworkProfileHandler() |
227 : weak_ptr_factory_(this) { | 204 : weak_ptr_factory_(this) { |
228 } | 205 } |
229 | 206 |
230 NetworkProfileHandler::~NetworkProfileHandler() { | 207 NetworkProfileHandler::~NetworkProfileHandler() { |
231 } | 208 } |
232 | 209 |
233 } // namespace chromeos | 210 } // namespace chromeos |
OLD | NEW |