Chromium Code Reviews| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 std::vector<std::string> removed_profile_paths; | 104 std::vector<std::string> removed_profile_paths; |
| 105 for (ProfileList::const_iterator it = profiles_.begin(); | 105 for (ProfileList::const_iterator it = profiles_.begin(); |
| 106 it != profiles_.end(); ++it) { | 106 it != profiles_.end(); ++it) { |
| 107 if (std::find(new_profile_paths.begin(), | 107 if (std::find(new_profile_paths.begin(), |
| 108 new_profile_paths.end(), | 108 new_profile_paths.end(), |
| 109 it->path) == new_profile_paths.end()) { | 109 it->path) == new_profile_paths.end()) { |
| 110 removed_profile_paths.push_back(it->path); | 110 removed_profile_paths.push_back(it->path); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 for (std::vector<std::string>::const_iterator it = | 114 for (const std::string profile_path : removed_profile_paths) { |
|
Joao da Silva
2014/10/24 12:01:06
const&
(you can also use const auto&)
pneubeck (no reviews)
2014/10/24 12:33:52
Done.
| |
| 115 removed_profile_paths.begin(); | 115 RemoveProfile(profile_path); |
| 116 it != removed_profile_paths.end(); ++it) { | 116 // Also stop pending creations of this profile. |
| 117 RemoveProfile(*it); | 117 pending_profile_creations_.erase(profile_path); |
| 118 } | 118 } |
| 119 | 119 |
| 120 for (std::vector<std::string>::const_iterator it = new_profile_paths.begin(); | 120 for (std::vector<std::string>::const_iterator it = new_profile_paths.begin(); |
| 121 it != new_profile_paths.end(); ++it) { | 121 it != new_profile_paths.end(); ++it) { |
| 122 // Skip known profiles. The associated userhash should never change. | 122 // Skip known profiles. The associated userhash should never change. |
| 123 if (GetProfileForPath(*it)) | 123 if (GetProfileForPath(*it) || pending_profile_creations_.count(*it) > 0) |
| 124 continue; | 124 continue; |
| 125 pending_profile_creations_.insert(*it); | |
| 125 | 126 |
| 126 VLOG(2) << "Requesting properties of profile path " << *it << "."; | 127 VLOG(2) << "Requesting properties of profile path " << *it << "."; |
| 127 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( | 128 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( |
| 128 dbus::ObjectPath(*it), | 129 dbus::ObjectPath(*it), |
| 129 base::Bind(&NetworkProfileHandler::GetProfilePropertiesCallback, | 130 base::Bind(&NetworkProfileHandler::GetProfilePropertiesCallback, |
| 130 weak_ptr_factory_.GetWeakPtr(), | 131 weak_ptr_factory_.GetWeakPtr(), |
| 131 *it), | 132 *it), |
| 132 base::Bind(&LogProfileRequestError, *it)); | 133 base::Bind(&LogProfileRequestError, *it)); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 void NetworkProfileHandler::GetProfilePropertiesCallback( | 137 void NetworkProfileHandler::GetProfilePropertiesCallback( |
| 137 const std::string& profile_path, | 138 const std::string& profile_path, |
| 138 const base::DictionaryValue& properties) { | 139 const base::DictionaryValue& properties) { |
| 140 if (pending_profile_creations_.erase(profile_path) == 0) { | |
| 141 VLOG(1) << "Ignore received properties, profile was removed."; | |
| 142 return; | |
| 143 } | |
| 144 if (GetProfileForPath(profile_path)) { | |
| 145 VLOG(1) << "Ignore received properties, profile is already created."; | |
| 146 return; | |
| 147 } | |
| 139 std::string userhash; | 148 std::string userhash; |
| 140 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, &userhash); | 149 properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, &userhash); |
| 141 | 150 |
| 142 AddProfile(NetworkProfile(profile_path, userhash)); | 151 AddProfile(NetworkProfile(profile_path, userhash)); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void NetworkProfileHandler::AddProfile(const NetworkProfile& profile) { | 154 void NetworkProfileHandler::AddProfile(const NetworkProfile& profile) { |
| 146 VLOG(2) << "Adding profile " << profile.ToDebugString() << "."; | 155 VLOG(2) << "Adding profile " << profile.ToDebugString() << "."; |
| 147 profiles_.push_back(profile); | 156 profiles_.push_back(profile); |
| 148 FOR_EACH_OBSERVER(NetworkProfileObserver, observers_, | 157 FOR_EACH_OBSERVER(NetworkProfileObserver, observers_, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 base::Bind(&NetworkProfileHandler::GetManagerPropertiesCallback, | 215 base::Bind(&NetworkProfileHandler::GetManagerPropertiesCallback, |
| 207 weak_ptr_factory_.GetWeakPtr())); | 216 weak_ptr_factory_.GetWeakPtr())); |
| 208 } | 217 } |
| 209 | 218 |
| 210 NetworkProfileHandler::~NetworkProfileHandler() { | 219 NetworkProfileHandler::~NetworkProfileHandler() { |
| 211 DBusThreadManager::Get()->GetShillManagerClient()-> | 220 DBusThreadManager::Get()->GetShillManagerClient()-> |
| 212 RemovePropertyChangedObserver(this); | 221 RemovePropertyChangedObserver(this); |
| 213 } | 222 } |
| 214 | 223 |
| 215 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |