From d973b822b933d740467c358dbf90ec277c6abe8b Mon Sep 17 00:00:00 2001 From: Hidehiko Abe Date: Tue, 29 May 2018 01:28:57 +0900 Subject: Remove unused files. event_types.h and id_map.h are moved out from base/ in Chrome ToT. Becuase these are unused, remove them. Bug: 79557560 Test: Ran treehugger. Change-Id: I012f39a51396987bbb87d6978cc53b74d4568c0c --- Android.bp | 1 - base/event_types.h | 37 ----- base/id_map.h | 254 -------------------------------- base/id_map_unittest.cc | 377 ------------------------------------------------ 4 files changed, 669 deletions(-) delete mode 100644 base/event_types.h delete mode 100644 base/id_map.h delete mode 100644 base/id_map_unittest.cc diff --git a/Android.bp b/Android.bp index 6c7c89fa9f..55efa6a35f 100644 --- a/Android.bp +++ b/Android.bp @@ -483,7 +483,6 @@ cc_test { "base/files/scoped_temp_dir_unittest.cc", "base/gmock_unittest.cc", "base/guid_unittest.cc", - "base/id_map_unittest.cc", "base/json/json_parser_unittest.cc", "base/json/json_reader_unittest.cc", "base/json/json_value_converter_unittest.cc", diff --git a/base/event_types.h b/base/event_types.h deleted file mode 100644 index 9905800d2e..0000000000 --- a/base/event_types.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_EVENT_TYPES_H_ -#define BASE_EVENT_TYPES_H_ - -#include "build/build_config.h" - -#if defined(OS_WIN) -#include -#elif defined(USE_X11) -typedef union _XEvent XEvent; -#elif defined(OS_MACOSX) -#if defined(__OBJC__) -@class NSEvent; -#else // __OBJC__ -class NSEvent; -#endif // __OBJC__ -#endif - -namespace base { - -// Cross platform typedefs for native event types. -#if defined(OS_WIN) -typedef MSG NativeEvent; -#elif defined(USE_X11) -typedef XEvent* NativeEvent; -#elif defined(OS_MACOSX) -typedef NSEvent* NativeEvent; -#else -typedef void* NativeEvent; -#endif - -} // namespace base - -#endif // BASE_EVENT_TYPES_H_ diff --git a/base/id_map.h b/base/id_map.h deleted file mode 100644 index d171fb14c1..0000000000 --- a/base/id_map.h +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_ID_MAP_H_ -#define BASE_ID_MAP_H_ - -#include -#include -#include -#include -#include -#include - -#include "base/containers/hash_tables.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/sequence_checker.h" - -// This object maintains a list of IDs that can be quickly converted to -// pointers to objects. It is implemented as a hash table, optimized for -// relatively small data sets (in the common case, there will be exactly one -// item in the list). -// -// Items can be inserted into the container with arbitrary ID, but the caller -// must ensure they are unique. Inserting IDs and relying on automatically -// generated ones is not allowed because they can collide. - -// The map's value type (the V param) can be any dereferenceable type, such as a -// raw pointer or smart pointer -template -class IDMap final { - public: - using KeyType = K; - - private: - using T = typename std::remove_reference::type; - using HashTable = base::hash_map; - - public: - IDMap() : iteration_depth_(0), next_id_(1), check_on_null_data_(false) { - // A number of consumers of IDMap create it on one thread but always - // access it from a different, but consistent, thread (or sequence) - // post-construction. The first call to CalledOnValidSequence() will re-bind - // it. - sequence_checker_.DetachFromSequence(); - } - - ~IDMap() { - // Many IDMap's are static, and hence will be destroyed on the main - // thread. However, all the accesses may take place on another thread (or - // sequence), such as the IO thread. Detaching again to clean this up. - sequence_checker_.DetachFromSequence(); - } - - // Sets whether Add and Replace should DCHECK if passed in NULL data. - // Default is false. - void set_check_on_null_data(bool value) { check_on_null_data_ = value; } - - // Adds a view with an automatically generated unique ID. See AddWithID. - KeyType Add(V data) { return AddInternal(std::move(data)); } - - // Adds a new data member with the specified ID. The ID must not be in - // the list. The caller either must generate all unique IDs itself and use - // this function, or allow this object to generate IDs and call Add. These - // two methods may not be mixed, or duplicate IDs may be generated. - void AddWithID(V data, KeyType id) { AddWithIDInternal(std::move(data), id); } - - void Remove(KeyType id) { - DCHECK(sequence_checker_.CalledOnValidSequence()); - typename HashTable::iterator i = data_.find(id); - if (i == data_.end()) { - NOTREACHED() << "Attempting to remove an item not in the list"; - return; - } - - if (iteration_depth_ == 0) { - data_.erase(i); - } else { - removed_ids_.insert(id); - } - } - - // Replaces the value for |id| with |new_data| and returns the existing value. - // Should only be called with an already added id. - V Replace(KeyType id, V new_data) { - DCHECK(sequence_checker_.CalledOnValidSequence()); - DCHECK(!check_on_null_data_ || new_data); - typename HashTable::iterator i = data_.find(id); - DCHECK(i != data_.end()); - - std::swap(i->second, new_data); - return new_data; - } - - void Clear() { - DCHECK(sequence_checker_.CalledOnValidSequence()); - if (iteration_depth_ == 0) { - data_.clear(); - } else { - for (typename HashTable::iterator i = data_.begin(); - i != data_.end(); ++i) - removed_ids_.insert(i->first); - } - } - - bool IsEmpty() const { - DCHECK(sequence_checker_.CalledOnValidSequence()); - return size() == 0u; - } - - T* Lookup(KeyType id) const { - DCHECK(sequence_checker_.CalledOnValidSequence()); - typename HashTable::const_iterator i = data_.find(id); - if (i == data_.end()) - return nullptr; - return &*i->second; - } - - size_t size() const { - DCHECK(sequence_checker_.CalledOnValidSequence()); - return data_.size() - removed_ids_.size(); - } - -#if defined(UNIT_TEST) - int iteration_depth() const { - return iteration_depth_; - } -#endif // defined(UNIT_TEST) - - // It is safe to remove elements from the map during iteration. All iterators - // will remain valid. - template - class Iterator { - public: - Iterator(IDMap* map) : map_(map), iter_(map_->data_.begin()) { - Init(); - } - - Iterator(const Iterator& iter) - : map_(iter.map_), - iter_(iter.iter_) { - Init(); - } - - const Iterator& operator=(const Iterator& iter) { - map_ = iter.map; - iter_ = iter.iter; - Init(); - return *this; - } - - ~Iterator() { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - - // We're going to decrement iteration depth. Make sure it's greater than - // zero so that it doesn't become negative. - DCHECK_LT(0, map_->iteration_depth_); - - if (--map_->iteration_depth_ == 0) - map_->Compact(); - } - - bool IsAtEnd() const { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - return iter_ == map_->data_.end(); - } - - KeyType GetCurrentKey() const { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - return iter_->first; - } - - ReturnType* GetCurrentValue() const { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - return &*iter_->second; - } - - void Advance() { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - ++iter_; - SkipRemovedEntries(); - } - - private: - void Init() { - DCHECK(map_->sequence_checker_.CalledOnValidSequence()); - ++map_->iteration_depth_; - SkipRemovedEntries(); - } - - void SkipRemovedEntries() { - while (iter_ != map_->data_.end() && - map_->removed_ids_.find(iter_->first) != - map_->removed_ids_.end()) { - ++iter_; - } - } - - IDMap* map_; - typename HashTable::const_iterator iter_; - }; - - typedef Iterator iterator; - typedef Iterator const_iterator; - - private: - KeyType AddInternal(V data) { - DCHECK(sequence_checker_.CalledOnValidSequence()); - DCHECK(!check_on_null_data_ || data); - KeyType this_id = next_id_; - DCHECK(data_.find(this_id) == data_.end()) << "Inserting duplicate item"; - data_[this_id] = std::move(data); - next_id_++; - return this_id; - } - - void AddWithIDInternal(V data, KeyType id) { - DCHECK(sequence_checker_.CalledOnValidSequence()); - DCHECK(!check_on_null_data_ || data); - DCHECK(data_.find(id) == data_.end()) << "Inserting duplicate item"; - data_[id] = std::move(data); - } - - void Compact() { - DCHECK_EQ(0, iteration_depth_); - for (const auto& i : removed_ids_) - Remove(i); - removed_ids_.clear(); - } - - // Keep track of how many iterators are currently iterating on us to safely - // handle removing items during iteration. - int iteration_depth_; - - // Keep set of IDs that should be removed after the outermost iteration has - // finished. This way we manage to not invalidate the iterator when an element - // is removed. - std::set removed_ids_; - - // The next ID that we will return from Add() - KeyType next_id_; - - HashTable data_; - - // See description above setter. - bool check_on_null_data_; - - base::SequenceChecker sequence_checker_; - - DISALLOW_COPY_AND_ASSIGN(IDMap); -}; - -#endif // BASE_ID_MAP_H_ diff --git a/base/id_map_unittest.cc b/base/id_map_unittest.cc deleted file mode 100644 index 42949bb5b9..0000000000 --- a/base/id_map_unittest.cc +++ /dev/null @@ -1,377 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/id_map.h" - -#include - -#include - -#include "base/memory/ptr_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class TestObject { -}; - -class DestructorCounter { - public: - explicit DestructorCounter(int* counter) : counter_(counter) {} - ~DestructorCounter() { ++(*counter_); } - - private: - int* counter_; -}; - -TEST(IDMapTest, Basic) { - IDMap map; - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); - - TestObject obj1; - TestObject obj2; - - int32_t id1 = map.Add(&obj1); - EXPECT_FALSE(map.IsEmpty()); - EXPECT_EQ(1U, map.size()); - EXPECT_EQ(&obj1, map.Lookup(id1)); - - int32_t id2 = map.Add(&obj2); - EXPECT_FALSE(map.IsEmpty()); - EXPECT_EQ(2U, map.size()); - - EXPECT_EQ(&obj1, map.Lookup(id1)); - EXPECT_EQ(&obj2, map.Lookup(id2)); - - map.Remove(id1); - EXPECT_FALSE(map.IsEmpty()); - EXPECT_EQ(1U, map.size()); - - map.Remove(id2); - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); - - map.AddWithID(&obj1, 1); - map.AddWithID(&obj2, 2); - EXPECT_EQ(&obj1, map.Lookup(1)); - EXPECT_EQ(&obj2, map.Lookup(2)); - - EXPECT_EQ(&obj2, map.Replace(2, &obj1)); - EXPECT_EQ(&obj1, map.Lookup(2)); - - EXPECT_EQ(0, map.iteration_depth()); -} - -TEST(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) { - IDMap map; - - TestObject obj1; - TestObject obj2; - TestObject obj3; - - map.Add(&obj1); - map.Add(&obj2); - map.Add(&obj3); - - { - IDMap::const_iterator iter(&map); - - EXPECT_EQ(1, map.iteration_depth()); - - while (!iter.IsAtEnd()) { - map.Remove(iter.GetCurrentKey()); - iter.Advance(); - } - - // Test that while an iterator is still in scope, we get the map emptiness - // right (http://crbug.com/35571). - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); - } - - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); - - EXPECT_EQ(0, map.iteration_depth()); -} - -TEST(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { - IDMap map; - - const int kCount = 5; - TestObject obj[kCount]; - - for (int i = 0; i < kCount; i++) - map.Add(&obj[i]); - - // IDMap uses a hash_map, which has no predictable iteration order. - int32_t ids_in_iteration_order[kCount]; - const TestObject* objs_in_iteration_order[kCount]; - int counter = 0; - for (IDMap::const_iterator iter(&map); !iter.IsAtEnd(); - iter.Advance()) { - ids_in_iteration_order[counter] = iter.GetCurrentKey(); - objs_in_iteration_order[counter] = iter.GetCurrentValue(); - counter++; - } - - counter = 0; - for (IDMap::const_iterator iter(&map); !iter.IsAtEnd(); - iter.Advance()) { - EXPECT_EQ(1, map.iteration_depth()); - - switch (counter) { - case 0: - EXPECT_EQ(ids_in_iteration_order[0], iter.GetCurrentKey()); - EXPECT_EQ(objs_in_iteration_order[0], iter.GetCurrentValue()); - map.Remove(ids_in_iteration_order[1]); - break; - case 1: - EXPECT_EQ(ids_in_iteration_order[2], iter.GetCurrentKey()); - EXPECT_EQ(objs_in_iteration_order[2], iter.GetCurrentValue()); - map.Remove(ids_in_iteration_order[3]); - break; - case 2: - EXPECT_EQ(ids_in_iteration_order[4], iter.GetCurrentKey()); - EXPECT_EQ(objs_in_iteration_order[4], iter.GetCurrentValue()); - map.Remove(ids_in_iteration_order[0]); - break; - default: - FAIL() << "should not have that many elements"; - break; - } - - counter++; - } - - EXPECT_EQ(0, map.iteration_depth()); -} - -TEST(IDMapTest, CopyIterator) { - IDMap map; - - TestObject obj1; - TestObject obj2; - TestObject obj3; - - map.Add(&obj1); - map.Add(&obj2); - map.Add(&obj3); - - EXPECT_EQ(0, map.iteration_depth()); - - { - IDMap::const_iterator iter1(&map); - EXPECT_EQ(1, map.iteration_depth()); - - // Make sure that copying the iterator correctly increments - // map's iteration depth. - IDMap::const_iterator iter2(iter1); - EXPECT_EQ(2, map.iteration_depth()); - } - - // Make sure after destroying all iterators the map's iteration depth - // returns to initial state. - EXPECT_EQ(0, map.iteration_depth()); -} - -TEST(IDMapTest, AssignIterator) { - IDMap map; - - TestObject obj1; - TestObject obj2; - TestObject obj3; - - map.Add(&obj1); - map.Add(&obj2); - map.Add(&obj3); - - EXPECT_EQ(0, map.iteration_depth()); - - { - IDMap::const_iterator iter1(&map); - EXPECT_EQ(1, map.iteration_depth()); - - IDMap::const_iterator iter2(&map); - EXPECT_EQ(2, map.iteration_depth()); - - // Make sure that assigning the iterator correctly updates - // map's iteration depth (-1 for destruction, +1 for assignment). - EXPECT_EQ(2, map.iteration_depth()); - } - - // Make sure after destroying all iterators the map's iteration depth - // returns to initial state. - EXPECT_EQ(0, map.iteration_depth()); -} - -TEST(IDMapTest, IteratorRemainsValidWhenClearing) { - IDMap map; - - const int kCount = 5; - TestObject obj[kCount]; - - for (int i = 0; i < kCount; i++) - map.Add(&obj[i]); - - // IDMap uses a hash_map, which has no predictable iteration order. - int32_t ids_in_iteration_order[kCount]; - const TestObject* objs_in_iteration_order[kCount]; - int counter = 0; - for (IDMap::const_iterator iter(&map); !iter.IsAtEnd(); - iter.Advance()) { - ids_in_iteration_order[counter] = iter.GetCurrentKey(); - objs_in_iteration_order[counter] = iter.GetCurrentValue(); - counter++; - } - - counter = 0; - for (IDMap::const_iterator iter(&map); !iter.IsAtEnd(); - iter.Advance()) { - switch (counter) { - case 0: - EXPECT_EQ(ids_in_iteration_order[0], iter.GetCurrentKey()); - EXPECT_EQ(objs_in_iteration_order[0], iter.GetCurrentValue()); - break; - case 1: - EXPECT_EQ(ids_in_iteration_order[1], iter.GetCurrentKey()); - EXPECT_EQ(objs_in_iteration_order[1], iter.GetCurrentValue()); - map.Clear(); - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); - break; - default: - FAIL() << "should not have that many elements"; - break; - } - counter++; - } - - EXPECT_TRUE(map.IsEmpty()); - EXPECT_EQ(0U, map.size()); -} - -TEST(IDMapTest, OwningPointersDeletesThemOnRemove) { - const int kCount = 3; - - int external_del_count = 0; - DestructorCounter* external_obj[kCount]; - int map_external_ids[kCount]; - - int owned_del_count = 0; - int map_owned_ids[kCount]; - - IDMap map_external; - IDMap> map_owned; - - for (int i = 0; i < kCount; ++i) { - external_obj[i] = new DestructorCounter(&external_del_count); - map_external_ids[i] = map_external.Add(external_obj[i]); - - map_owned_ids[i] = - map_owned.Add(base::MakeUnique(&owned_del_count)); - } - - for (int i = 0; i < kCount; ++i) { - EXPECT_EQ(external_del_count, 0); - EXPECT_EQ(owned_del_count, i); - - map_external.Remove(map_external_ids[i]); - map_owned.Remove(map_owned_ids[i]); - } - - for (int i = 0; i < kCount; ++i) { - delete external_obj[i]; - } - - EXPECT_EQ(external_del_count, kCount); - EXPECT_EQ(owned_del_count, kCount); -} - -TEST(IDMapTest, OwningPointersDeletesThemOnClear) { - const int kCount = 3; - - int external_del_count = 0; - DestructorCounter* external_obj[kCount]; - - int owned_del_count = 0; - - IDMap map_external; - IDMap> map_owned; - - for (int i = 0; i < kCount; ++i) { - external_obj[i] = new DestructorCounter(&external_del_count); - map_external.Add(external_obj[i]); - - map_owned.Add(base::MakeUnique(&owned_del_count)); - } - - EXPECT_EQ(external_del_count, 0); - EXPECT_EQ(owned_del_count, 0); - - map_external.Clear(); - map_owned.Clear(); - - EXPECT_EQ(external_del_count, 0); - EXPECT_EQ(owned_del_count, kCount); - - for (int i = 0; i < kCount; ++i) { - delete external_obj[i]; - } - - EXPECT_EQ(external_del_count, kCount); - EXPECT_EQ(owned_del_count, kCount); -} - -TEST(IDMapTest, OwningPointersDeletesThemOnDestruct) { - const int kCount = 3; - - int external_del_count = 0; - DestructorCounter* external_obj[kCount]; - - int owned_del_count = 0; - - { - IDMap map_external; - IDMap> map_owned; - - for (int i = 0; i < kCount; ++i) { - external_obj[i] = new DestructorCounter(&external_del_count); - map_external.Add(external_obj[i]); - - map_owned.Add(base::MakeUnique(&owned_del_count)); - } - } - - EXPECT_EQ(external_del_count, 0); - - for (int i = 0; i < kCount; ++i) { - delete external_obj[i]; - } - - EXPECT_EQ(external_del_count, kCount); - EXPECT_EQ(owned_del_count, kCount); -} - -TEST(IDMapTest, Int64KeyType) { - IDMap map; - TestObject obj1; - const int64_t kId1 = 999999999999999999; - - map.AddWithID(&obj1, kId1); - EXPECT_EQ(&obj1, map.Lookup(kId1)); - - IDMap::const_iterator iter(&map); - ASSERT_FALSE(iter.IsAtEnd()); - EXPECT_EQ(kId1, iter.GetCurrentKey()); - EXPECT_EQ(&obj1, iter.GetCurrentValue()); - iter.Advance(); - ASSERT_TRUE(iter.IsAtEnd()); - - map.Remove(kId1); - EXPECT_TRUE(map.IsEmpty()); -} - -} // namespace -- cgit v1.2.3