Commit dfcc90f1 authored by avi's avatar avi Committed by Commit bot

Remove stl_util's deletion functions from chromeos/.

BUG=555865

Review-Url: https://codereview.chromium.org/2387783002
Cr-Commit-Position: refs/heads/master@{#422979}
parent 03e1338d
......@@ -149,12 +149,10 @@ namespace system {
// Creates a list of pairs of each timezone's ID and name.
std::unique_ptr<base::ListValue> GetTimezoneList() {
const std::vector<icu::TimeZone*> &timezones =
const auto& timezones =
chromeos::system::TimezoneSettings::GetInstance()->GetTimezoneList();
std::unique_ptr<base::ListValue> timezoneList(new base::ListValue());
for (std::vector<icu::TimeZone*>::const_iterator iter = timezones.begin();
iter != timezones.end(); ++iter) {
const icu::TimeZone* timezone = *iter;
for (const auto& timezone : timezones) {
auto option = base::MakeUnique<base::ListValue>();
option->AppendString(
chromeos::system::TimezoneSettings::GetTimezoneID(*timezone));
......
......@@ -7,8 +7,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "chromeos/dbus/dbus_thread_manager.h"
......@@ -37,15 +37,11 @@ void PassDictionary(
} // namespace
FakeShillProfileClient::FakeShillProfileClient() {
}
FakeShillProfileClient::FakeShillProfileClient() {}
FakeShillProfileClient::~FakeShillProfileClient() {
base::STLDeleteValues(&profiles_);
}
FakeShillProfileClient::~FakeShillProfileClient() {}
void FakeShillProfileClient::Init(dbus::Bus* bus) {
}
void FakeShillProfileClient::Init(dbus::Bus* bus) {}
void FakeShillProfileClient::AddPropertyChangedObserver(
const dbus::ObjectPath& profile_path,
......@@ -131,10 +127,11 @@ void FakeShillProfileClient::AddProfile(const std::string& profile_path,
if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback()))
return;
ProfileProperties* profile = new ProfileProperties;
std::unique_ptr<ProfileProperties> profile =
base::MakeUnique<ProfileProperties>();
profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty,
userhash);
profiles_[profile_path] = profile;
profiles_[profile_path] = std::move(profile);
DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
AddProfile(profile_path);
}
......@@ -214,19 +211,16 @@ bool FakeShillProfileClient::AddOrUpdateServiceImpl(
void FakeShillProfileClient::GetProfilePaths(
std::vector<std::string>* profiles) {
for (ProfileMap::iterator iter = profiles_.begin();
iter != profiles_.end(); ++iter) {
for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter)
profiles->push_back(iter->first);
}
}
bool FakeShillProfileClient::GetService(const std::string& service_path,
std::string* profile_path,
base::DictionaryValue* properties) {
properties->Clear();
for (ProfileMap::const_iterator iter = profiles_.begin();
iter != profiles_.end(); ++iter) {
const ProfileProperties* profile = iter->second;
for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) {
const ProfileProperties* profile = iter->second.get();
const base::DictionaryValue* entry;
if (!profile->entries.GetDictionaryWithoutPathExpansion(
service_path, &entry)) {
......@@ -240,20 +234,20 @@ bool FakeShillProfileClient::GetService(const std::string& service_path,
}
void FakeShillProfileClient::ClearProfiles() {
base::STLDeleteValues(&profiles_);
profiles_.clear();
}
FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile(
const dbus::ObjectPath& profile_path,
const ErrorCallback& error_callback) {
ProfileMap::const_iterator found = profiles_.find(profile_path.value());
auto found = profiles_.find(profile_path.value());
if (found == profiles_.end()) {
if (!error_callback.is_null())
error_callback.Run("Error.InvalidProfile", "Invalid profile");
return NULL;
return nullptr;
}
return found->second;
return found->second.get();
}
} // namespace chromeos
......@@ -6,6 +6,7 @@
#define CHROMEOS_DBUS_FAKE_SHILL_PROFILE_CLIENT_H_
#include <map>
#include <memory>
#include <string>
#include "base/macros.h"
......@@ -62,7 +63,7 @@ class CHROMEOS_EXPORT FakeShillProfileClient :
private:
struct ProfileProperties;
typedef std::map<std::string, ProfileProperties*> ProfileMap;
using ProfileMap = std::map<std::string, std::unique_ptr<ProfileProperties>>;
bool AddOrUpdateServiceImpl(const std::string& profile_path,
const std::string& service_path,
......@@ -71,8 +72,6 @@ class CHROMEOS_EXPORT FakeShillProfileClient :
ProfileProperties* GetProfile(const dbus::ObjectPath& profile_path,
const ErrorCallback& error_callback);
// The values are owned by this class and are explicitly destroyed where
// necessary.
ProfileMap profiles_;
DISALLOW_COPY_AND_ASSIGN(FakeShillProfileClient);
......
......@@ -52,7 +52,8 @@ class NetworkPolicyObserver;
// user consumption.
class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler {
public:
using GuidToPolicyMap = std::map<std::string, const base::DictionaryValue*>;
using GuidToPolicyMap =
std::map<std::string, std::unique_ptr<base::DictionaryValue>>;
virtual ~ManagedNetworkConfigurationHandler();
......@@ -61,7 +62,7 @@ class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler {
// Provides the properties of the network with |service_path| to |callback|.
// |userhash| is used to set the "Source" property. If not provided then
// user polcies will be ignored.
// user policies will be ignored.
virtual void GetProperties(
const std::string& userhash,
const std::string& service_path,
......
......@@ -14,7 +14,6 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "chromeos/dbus/shill_manager_client.h"
......@@ -82,10 +81,10 @@ void LogErrorWithDict(const tracked_objects::Location& from_where,
const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies,
const std::string& guid) {
GuidToPolicyMap::const_iterator it = policies.find(guid);
auto it = policies.find(guid);
if (it == policies.end())
return NULL;
return it->second;
return it->second.get();
}
} // namespace
......@@ -97,9 +96,7 @@ struct ManagedNetworkConfigurationHandlerImpl::Policies {
base::DictionaryValue global_network_config;
};
ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() {
base::STLDeleteValues(&per_network_config);
}
ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() {}
void ManagedNetworkConfigurationHandlerImpl::AddObserver(
NetworkPolicyObserver* observer) {
......@@ -430,7 +427,7 @@ void ManagedNetworkConfigurationHandlerImpl::SetPolicy(
::onc::global_network_config::kDisableNetworkTypes,
&prohibited_list) &&
prohibited_technologies_handler_) {
// Prohobited technologies are only allowed in user policy.
// Prohibited technologies are only allowed in user policy.
DCHECK_EQ(::onc::ONC_SOURCE_DEVICE_POLICY, onc_source);
prohibited_technologies_handler_->SetProhibitedTechnologies(
......@@ -445,7 +442,7 @@ void ManagedNetworkConfigurationHandlerImpl::SetPolicy(
for (base::ListValue::const_iterator it = network_configs_onc.begin();
it != network_configs_onc.end(); ++it) {
const base::DictionaryValue* network = NULL;
base::DictionaryValue* network = NULL;
(*it)->GetAsDictionary(&network);
DCHECK(network);
......@@ -456,17 +453,16 @@ void ManagedNetworkConfigurationHandlerImpl::SetPolicy(
if (policies->per_network_config.count(guid) > 0) {
NET_LOG_ERROR("ONC from " + ToDebugString(onc_source, userhash) +
" contains several entries for the same GUID ", guid);
delete policies->per_network_config[guid];
}
const base::DictionaryValue* new_entry = network->DeepCopy();
policies->per_network_config[guid] = new_entry;
base::DictionaryValue* new_entry = network->DeepCopy();
policies->per_network_config[guid] = base::WrapUnique(new_entry);
const base::DictionaryValue* old_entry = old_per_network_config[guid];
base::DictionaryValue* old_entry = old_per_network_config[guid].get();
if (!old_entry || !old_entry->Equals(new_entry))
modified_policies.insert(guid);
}
base::STLDeleteValues(&old_per_network_config);
old_per_network_config.clear();
ApplyOrQueuePolicies(userhash, &modified_policies);
FOR_EACH_OBSERVER(NetworkPolicyObserver, observers_,
PoliciesChanged(userhash));
......@@ -530,8 +526,7 @@ void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded(
}
std::set<std::string> policy_guids;
for (GuidToPolicyMap::const_iterator it =
policies->per_network_config.begin();
for (auto it = policies->per_network_config.begin();
it != policies->per_network_config.end(); ++it) {
policy_guids.insert(it->first);
}
......
......@@ -10,7 +10,7 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/memory/ptr_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_profile_client.h"
#include "chromeos/network/network_type_pattern.h"
......@@ -36,10 +36,10 @@ void LogErrorMessage(const tracked_objects::Location& from_where,
const base::DictionaryValue* GetByGUID(
const PolicyApplicator::GuidToPolicyMap& policies,
const std::string& guid) {
PolicyApplicator::GuidToPolicyMap::const_iterator it = policies.find(guid);
auto it = policies.find(guid);
if (it == policies.end())
return NULL;
return it->second;
return it->second.get();
}
} // namespace
......@@ -53,14 +53,13 @@ PolicyApplicator::PolicyApplicator(
: handler_(handler), profile_(profile), weak_ptr_factory_(this) {
global_network_config_.MergeDictionary(&global_network_config);
remaining_policies_.swap(*modified_policies);
for (GuidToPolicyMap::const_iterator it = all_policies.begin();
it != all_policies.end(); ++it) {
all_policies_.insert(std::make_pair(it->first, it->second->DeepCopy()));
for (const auto& policy_pair : all_policies) {
all_policies_.insert(std::make_pair(policy_pair.first,
policy_pair.second->CreateDeepCopy()));
}
}
PolicyApplicator::~PolicyApplicator() {
base::STLDeleteValues(&all_policies_);
VLOG(1) << "Destroying PolicyApplicator for " << profile_.userhash;
}
......
......@@ -47,7 +47,8 @@ class PolicyApplicator {
DISALLOW_ASSIGN(ConfigurationHandler);
};
typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap;
using GuidToPolicyMap =
std::map<std::string, std::unique_ptr<base::DictionaryValue>>;
// |handler| must outlive this object.
// |modified_policies| must not be NULL and will be empty afterwards.
......
......@@ -25,7 +25,7 @@ namespace policy_util {
namespace {
// This fake credential contains a random postfix which is extremly unlikely to
// This fake credential contains a random postfix which is extremely unlikely to
// be used by any user.
const char kFakeCredential[] = "FAKE_CREDENTIAL_VPaJDV9x";
......@@ -53,7 +53,7 @@ void RemoveFakeCredentials(
if (field_signature)
RemoveFakeCredentials(*field_signature->value_signature, nested_object);
else
LOG(ERROR) << "ONC has unrecoginzed field: " << field_name;
LOG(ERROR) << "ONC has unrecognized field: " << field_name;
continue;
}
......@@ -288,11 +288,11 @@ void SetShillPropertiesForGlobalPolicy(
if (shill_dictionary.GetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, &old_autoconnect) &&
!old_autoconnect) {
// Autoconnect is already explictly disabled. No need to set it again.
// Autoconnect is already explicitly disabled. No need to set it again.
return;
}
// If autconnect is not explicitly set yet, it might automatically be enabled
// If autoconnect is not explicitly set yet, it might automatically be enabled
// by Shill. To prevent that, disable it explicitly.
shill_properties_to_update->SetBooleanWithoutPathExpansion(
shill::kAutoConnectProperty, false);
......@@ -398,10 +398,9 @@ std::unique_ptr<base::DictionaryValue> CreateShillConfiguration(
const base::DictionaryValue* FindMatchingPolicy(
const GuidToPolicyMap& policies,
const base::DictionaryValue& actual_network) {
for (GuidToPolicyMap::const_iterator it = policies.begin();
it != policies.end(); ++it) {
for (auto it = policies.begin(); it != policies.end(); ++it) {
if (IsPolicyMatching(*it->second, actual_network))
return it->second;
return it->second.get();
}
return NULL;
}
......
......@@ -9,7 +9,6 @@
#include <memory>
#include <string>
namespace base {
class DictionaryValue;
}
......@@ -20,7 +19,8 @@ struct NetworkProfile;
namespace policy_util {
typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap;
using GuidToPolicyMap =
std::map<std::string, std::unique_ptr<base::DictionaryValue>>;
// Creates a managed ONC dictionary from the given arguments. Depending on the
// profile type, the policies are assumed to come from the user or device policy
......@@ -36,7 +36,7 @@ std::unique_ptr<base::DictionaryValue> CreateManagedONC(
const NetworkProfile* profile);
// Adds properties to |shill_properties_to_update|, which are enforced on an
// unamaged network by the global config |global_network_policy| of the policy.
// unmanaged network by the global config |global_network_policy| of the policy.
// |shill_dictionary| are the network's current properties read from Shill.
void SetShillPropertiesForGlobalPolicy(
const base::DictionaryValue& shill_dictionary,
......
......@@ -15,9 +15,9 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
......@@ -279,7 +279,8 @@ class TimezoneSettingsBaseImpl : public chromeos::system::TimezoneSettings {
void SetTimezoneFromID(const base::string16& timezone_id) override;
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
const std::vector<icu::TimeZone*>& GetTimezoneList() const override;
const std::vector<std::unique_ptr<icu::TimeZone>>& GetTimezoneList()
const override;
protected:
TimezoneSettingsBaseImpl();
......@@ -295,7 +296,7 @@ class TimezoneSettingsBaseImpl : public chromeos::system::TimezoneSettings {
const icu::TimeZone& timezone) const;
base::ObserverList<Observer> observers_;
std::vector<icu::TimeZone*> timezones_;
std::vector<std::unique_ptr<icu::TimeZone>> timezones_;
std::unique_ptr<icu::TimeZone> timezone_;
private:
......@@ -335,7 +336,6 @@ class TimezoneSettingsStubImpl : public TimezoneSettingsBaseImpl {
};
TimezoneSettingsBaseImpl::~TimezoneSettingsBaseImpl() {
base::STLDeleteElements(&timezones_);
}
const icu::TimeZone& TimezoneSettingsBaseImpl::GetTimezone() {
......@@ -361,15 +361,15 @@ void TimezoneSettingsBaseImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
const std::vector<icu::TimeZone*>&
const std::vector<std::unique_ptr<icu::TimeZone>>&
TimezoneSettingsBaseImpl::GetTimezoneList() const {
return timezones_;
}
TimezoneSettingsBaseImpl::TimezoneSettingsBaseImpl() {
for (size_t i = 0; i < arraysize(kTimeZones); ++i) {
timezones_.push_back(icu::TimeZone::createTimeZone(
icu::UnicodeString(kTimeZones[i], -1, US_INV)));
timezones_.push_back(base::WrapUnique(icu::TimeZone::createTimeZone(
icu::UnicodeString(kTimeZones[i], -1, US_INV))));
}
}
......
......@@ -42,7 +42,8 @@ class CHROMEOS_EXPORT TimezoneSettings {
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual const std::vector<icu::TimeZone*>& GetTimezoneList() const = 0;
virtual const std::vector<std::unique_ptr<icu::TimeZone>>& GetTimezoneList()
const = 0;
// Gets timezone ID which is also used as timezone pref value.
static base::string16 GetTimezoneID(const icu::TimeZone& timezone);
......
......@@ -12,16 +12,16 @@ namespace system {
CHROMEOS_EXPORT const icu::TimeZone* GetKnownTimezoneOrNull(
const icu::TimeZone& timezone,
const std::vector<icu::TimeZone*>& timezone_list) {
const icu::TimeZone* known_timezone = NULL;
const std::vector<std::unique_ptr<icu::TimeZone>>& timezone_list) {
const icu::TimeZone* known_timezone = nullptr;
icu::UnicodeString id, canonical_id;
timezone.getID(id);
UErrorCode status = U_ZERO_ERROR;
icu::TimeZone::getCanonicalID(id, canonical_id, status);
DCHECK(U_SUCCESS(status));
for (const auto* entry : timezone_list) {
if (*entry == timezone)
return entry;
for (const auto& entry : timezone_list) {
if (*entry.get() == timezone)
return entry.get();
// Compare the canonical IDs as well.
// For instance, Asia/Ulan_Bator -> Asia/Ulaanbaatar or
// Canada/Pacific -> America/Vancouver
......@@ -30,14 +30,14 @@ CHROMEOS_EXPORT const icu::TimeZone* GetKnownTimezoneOrNull(
icu::TimeZone::getCanonicalID(entry_id, entry_canonical_id, status);
DCHECK(U_SUCCESS(status));
if (entry_canonical_id == canonical_id)
return entry;
return entry.get();
// Last resort: If no match is found, the last timezone in the list
// with matching rules will be returned.
if (entry->hasSameRules(timezone))
known_timezone = entry;
known_timezone = entry.get();
}
// May return NULL if we did not find a matching timezone in our list.
// May return null if we did not find a matching timezone in our list.
return known_timezone;
}
......
......@@ -5,6 +5,7 @@
#ifndef CHROMEOS_SETTINGS_TIMEZONE_SETTINGS_HELPER_H_
#define CHROMEOS_SETTINGS_TIMEZONE_SETTINGS_HELPER_H_
#include <memory>
#include <vector>
#include "third_party/icu/source/i18n/unicode/timezone.h"
......@@ -17,7 +18,7 @@ namespace system {
// the same rules. Otherwise, return null.
const icu::TimeZone* GetKnownTimezoneOrNull(
const icu::TimeZone& timezone,
const std::vector<icu::TimeZone*>& timezone_list);
const std::vector<std::unique_ptr<icu::TimeZone>>& timezone_list);
} // namespace system
} // namespace chromeos
......
......@@ -4,7 +4,7 @@
#include <memory>
#include "base/stl_util.h"
#include "base/memory/ptr_util.h"
#include "chromeos/settings/timezone_settings_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/icu/source/common/unicode/unistr.h"
......@@ -36,14 +36,13 @@ class KnownTimeZoneTest : public testing::Test {
void SetUp() override {
for (const char* id : kTimeZones) {
timezones_.push_back(TimeZone::createTimeZone(UnicodeString(id)));
timezones_.push_back(
base::WrapUnique(TimeZone::createTimeZone(UnicodeString(id))));
}
}
void TearDown() override { base::STLDeleteElements(&timezones_); }
protected:
std::vector<TimeZone*> timezones_;
std::vector<std::unique_ptr<TimeZone>> timezones_;
};
TEST_F(KnownTimeZoneTest, IdMatch) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment