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

Unified Diff: ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc

Issue 2603863002: Remove base::ScopedPtrHashMap from ozone. (Closed)
Patch Set: fixes Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc
diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc
index 0a4cf0bb14aa23108ec5cdd7fd020baf2a237f74..e445f1a3597f57c3f99d5ee72f014d9f54964e59 100644
--- a/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc
+++ b/ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.cc
@@ -11,6 +11,7 @@
#include <string.h>
#include <algorithm>
+#include <unordered_map>
#include "base/containers/hash_tables.h"
#include "base/files/file_enumerator.h"
@@ -609,12 +610,6 @@ std::ostream& operator<<(std::ostream& os, const GesturesProp& prop) {
namespace ui {
namespace internal {
-// Mapping table from a property name to its corresponding GesturesProp
-// object pointer.
-typedef base::hash_map<std::string, GesturesProp*> PropertiesMap;
-typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<GesturesProp>>
- ScopedPropertiesMap;
-
// Struct holding properties of a device.
//
// Note that we can't define it in GesturePropertyProvider as a nested class
@@ -625,12 +620,12 @@ struct GestureDevicePropertyData {
GestureDevicePropertyData() {}
// Properties owned and being used by the device.
- ScopedPropertiesMap properties;
+ std::unordered_map<std::string, std::unique_ptr<GesturesProp>> properties;
// Unowned default properties (owned by the configuration file). Their values
// will be applied when a property of the same name is created. These are
// usually only a small portion of all properties in use.
- PropertiesMap default_properties;
+ base::hash_map<std::string, GesturesProp*> default_properties;
};
// Base class for device match criterias in conf files.
@@ -875,8 +870,7 @@ bool GesturePropertyProvider::GetDeviceIdsByType(
const EventDeviceType type,
std::vector<DeviceId>* device_ids) {
bool exists = false;
- DeviceMap::const_iterator it = device_map_.begin();
- for (; it != device_map_.end(); ++it) {
+ for (auto it = device_map_.begin(); it != device_map_.end(); ++it) {
if (IsDeviceIdOfType(it->first, type)) {
exists = true;
if (device_ids)
@@ -888,7 +882,7 @@ bool GesturePropertyProvider::GetDeviceIdsByType(
bool GesturePropertyProvider::IsDeviceIdOfType(const DeviceId device_id,
const EventDeviceType type) {
- DeviceMap::const_iterator it = device_map_.find(device_id);
+ auto it = device_map_.find(device_id);
if (it == device_map_.end())
return false;
return IsDeviceOfType(it->second, type,
@@ -903,15 +897,15 @@ GesturesProp* GesturePropertyProvider::GetProperty(const DeviceId device_id,
std::vector<std::string> GesturePropertyProvider::GetPropertyNamesById(
const DeviceId device_id) {
- internal::GestureDevicePropertyData* device_data =
- device_data_map_.get(device_id);
- if (!device_data)
+ auto it = device_data_map_.find(device_id);
+ if (it == device_data_map_.end())
return std::vector<std::string>();
+ internal::GestureDevicePropertyData* device_data = it->second.get();
+
// Dump all property names of the device.
std::vector<std::string> names;
- for (internal::ScopedPropertiesMap::const_iterator it =
- device_data->properties.begin();
+ for (auto it = device_data->properties.begin();
it != device_data->properties.end(); ++it)
names.push_back(it->first);
return names;
@@ -919,7 +913,7 @@ std::vector<std::string> GesturePropertyProvider::GetPropertyNamesById(
std::string GesturePropertyProvider::GetDeviceNameById(
const DeviceId device_id) {
- DeviceMap::const_iterator it = device_map_.find(device_id);
+ auto it = device_map_.find(device_id);
if (it == device_map_.end())
return std::string();
return std::string(it->second->info.name);
@@ -927,14 +921,14 @@ std::string GesturePropertyProvider::GetDeviceNameById(
void GesturePropertyProvider::RegisterDevice(const DeviceId id,
const DevicePtr device) {
- DeviceMap::const_iterator it = device_map_.find(id);
+ auto it = device_map_.find(id);
if (it != device_map_.end())
return;
// Setup data-structures.
device_map_[id] = device;
- device_data_map_.set(id, std::unique_ptr<internal::GestureDevicePropertyData>(
- new internal::GestureDevicePropertyData));
+ device_data_map_[id] =
+ base::MakeUnique<internal::GestureDevicePropertyData>();
// Gather default property values for the device from the parsed conf files.
SetupDefaultProperties(id, device);
@@ -942,7 +936,7 @@ void GesturePropertyProvider::RegisterDevice(const DeviceId id,
}
void GesturePropertyProvider::UnregisterDevice(const DeviceId id) {
- DeviceMap::const_iterator it = device_map_.find(id);
+ auto it = device_map_.find(id);
if (it == device_map_.end())
return;
device_data_map_.erase(id);
@@ -956,41 +950,43 @@ void GesturePropertyProvider::AddProperty(
// The look-up should never fail because ideally a property can only be
// created with GesturesPropCreate* functions from the gesture lib side.
// Therefore, we simply return on failure.
- internal::GestureDevicePropertyData* device_data =
- device_data_map_.get(device_id);
- if (device_data)
- device_data->properties.set(name, std::move(property));
+ auto it = device_data_map_.find(device_id);
+ if (it != device_data_map_.end())
+ it->second->properties[name] = std::move(property);
}
void GesturePropertyProvider::DeleteProperty(const DeviceId device_id,
const std::string& name) {
- internal::GestureDevicePropertyData* device_data =
- device_data_map_.get(device_id);
- if (device_data)
- device_data->properties.erase(name);
+ auto it = device_data_map_.find(device_id);
+ if (it != device_data_map_.end())
+ it->second->properties.erase(name);
}
GesturesProp* GesturePropertyProvider::FindProperty(const DeviceId device_id,
const std::string& name) {
- internal::GestureDevicePropertyData* device_data =
- device_data_map_.get(device_id);
- if (!device_data)
- return NULL;
- return device_data->properties.get(name);
+ auto it = device_data_map_.find(device_id);
+ if (it == device_data_map_.end())
+ return nullptr;
+
+ auto it2 = it->second->properties.find(name);
+ if (it2 == it->second->properties.end())
+ return nullptr;
+
+ return it2->second.get();
}
GesturesProp* GesturePropertyProvider::GetDefaultProperty(
const DeviceId device_id,
const std::string& name) {
- internal::GestureDevicePropertyData* device_data =
- device_data_map_.get(device_id);
- if (!device_data)
- return NULL;
- internal::PropertiesMap::const_iterator ib =
- device_data->default_properties.find(name);
- if (ib == device_data->default_properties.end())
- return NULL;
- return ib->second;
+ auto it = device_data_map_.find(device_id);
+ if (it == device_data_map_.end())
+ return nullptr;
+
+ auto it2 = it->second->default_properties.find(name);
+ if (it2 == it->second->default_properties.end())
+ return nullptr;
+
+ return it2->second;
}
void GesturePropertyProvider::LoadDeviceConfigurations() {
@@ -1007,9 +1003,7 @@ void GesturePropertyProvider::LoadDeviceConfigurations() {
DVLOG(2) << files.size() << " conf files were found";
// Parse conf files one-by-one.
- for (std::set<base::FilePath>::iterator file_iter = files.begin();
- file_iter != files.end();
- ++file_iter) {
+ for (auto file_iter = files.begin(); file_iter != files.end(); ++file_iter) {
DVLOG(2) << "Parsing conf file: " << (*file_iter).value();
std::string content;
if (!base::ReadFileToString(*file_iter, &content)) {
@@ -1279,8 +1273,7 @@ void GesturePropertyProvider::SetupDefaultProperties(const DeviceId device_id,
<< device_id << ", " << device->info.name << ")";
// Go through all parsed sections.
- internal::PropertiesMap& property_map =
- device_data_map_.get(device_id)->default_properties;
+ auto& property_map = device_data_map_[device_id]->default_properties;
for (const auto& configuration : configurations_) {
if (configuration->Match(device)) {
DVLOG(2) << "Conf section \"" << configuration->identifier

Powered by Google App Engine
This is Rietveld 408576698