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