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

Side by Side Diff: ui/base/class_property.cc

Issue 2632543003: Refactor and push window properties up to class properties. (Closed)
Patch Set: More build fixes Created 3 years, 10 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/base/class_property.h"
6
7 #include <algorithm>
8 #include <utility>
9
10 namespace ui {
11
12 PropertyHandler::PropertyHandler() {}
13
14 PropertyHandler::~PropertyHandler() {
15 ClearProperties();
16 }
17
18 int64_t PropertyHandler::SetPropertyInternal(const void* key,
19 const char* name,
20 PropertyDeallocator deallocator,
21 int64_t value,
22 int64_t default_value) {
23 // This code may be called before |port_| has been created.
24 std::unique_ptr<PropertyData> data = BeforePropertyChange(key);
25 int64_t old = GetPropertyInternal(key, default_value);
26 if (value == default_value) {
27 prop_map_.erase(key);
28 } else {
29 Value prop_value;
30 prop_value.name = name;
31 prop_value.value = value;
32 prop_value.deallocator = deallocator;
33 prop_map_[key] = prop_value;
34 }
35 AfterPropertyChange(key, old, std::move(data));
36 return old;
37 }
38
39 std::unique_ptr<PropertyData> PropertyHandler::BeforePropertyChange(
40 const void* key) {
41 return nullptr;
42 }
43
44 void PropertyHandler::ClearProperties() {
45 // Clear properties.
46 for (std::map<const void*, Value>::const_iterator iter = prop_map_.begin();
47 iter != prop_map_.end();
48 ++iter) {
49 if (iter->second.deallocator)
50 (*iter->second.deallocator)(iter->second.value);
51 }
52 prop_map_.clear();
53 }
54
55 int64_t PropertyHandler::GetPropertyInternal(const void* key,
56 int64_t default_value) const {
57 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
58 if (iter == prop_map_.end())
59 return default_value;
60 return iter->second.value;
61 }
62
63 std::set<const void*> PropertyHandler::GetAllPropertyKeys() const {
64 std::set<const void*> keys;
65 for (auto& pair : prop_map_)
66 keys.insert(pair.first);
67 return keys;
68 }
69
70 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698