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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 2765363004: Stop passing raw pointers to DictionaryValue::Set, part 2 (Closed)
Patch Set: Fix comments Created 3 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/display/display_preferences.h" 5 #include "chrome/browser/chromeos/display/display_preferences.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(!name.empty()); 121 DCHECK(!name.empty());
122 122
123 base::DictionaryValue* pref_data = update.Get(); 123 base::DictionaryValue* pref_data = update.Get();
124 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); 124 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue());
125 if (pref_data->HasKey(name)) { 125 if (pref_data->HasKey(name)) {
126 base::Value* value = nullptr; 126 base::Value* value = nullptr;
127 if (pref_data->Get(name, &value) && value != nullptr) 127 if (pref_data->Get(name, &value) && value != nullptr)
128 layout_value.reset(value->DeepCopy()); 128 layout_value.reset(value->DeepCopy());
129 } 129 }
130 if (display::DisplayLayoutToJson(display_layout, layout_value.get())) 130 if (display::DisplayLayoutToJson(display_layout, layout_value.get()))
131 pref_data->Set(name, layout_value.release()); 131 pref_data->Set(name, std::move(layout_value));
132 } 132 }
133 133
134 void StoreDisplayPropertyForList(const display::DisplayIdList& list, 134 void StoreDisplayPropertyForList(const display::DisplayIdList& list,
135 std::string key, 135 std::string key,
136 std::unique_ptr<base::Value> value) { 136 std::unique_ptr<base::Value> value) {
137 std::string name = display::DisplayIdListToString(list); 137 std::string name = display::DisplayIdListToString(list);
138 138
139 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); 139 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays);
140 base::DictionaryValue* pref_data = update.Get(); 140 base::DictionaryValue* pref_data = update.Get();
141 141
142 if (pref_data->HasKey(name)) { 142 if (pref_data->HasKey(name)) {
143 base::Value* layout_value = nullptr; 143 base::Value* layout_value = nullptr;
144 pref_data->Get(name, &layout_value); 144 pref_data->Get(name, &layout_value);
145 if (layout_value) 145 if (layout_value)
146 static_cast<base::DictionaryValue*>(layout_value) 146 static_cast<base::DictionaryValue*>(layout_value)
147 ->Set(key, std::move(value)); 147 ->Set(key, std::move(value));
148 } else { 148 } else {
149 std::unique_ptr<base::DictionaryValue> layout_value( 149 std::unique_ptr<base::DictionaryValue> layout_value(
150 new base::DictionaryValue()); 150 new base::DictionaryValue());
151 layout_value->SetBoolean(key, value != nullptr); 151 layout_value->SetBoolean(key, value != nullptr);
152 pref_data->Set(name, layout_value.release()); 152 pref_data->Set(name, std::move(layout_value));
153 } 153 }
154 } 154 }
155 155
156 void StoreDisplayBoolPropertyForList(const display::DisplayIdList& list, 156 void StoreDisplayBoolPropertyForList(const display::DisplayIdList& list,
157 const std::string& key, 157 const std::string& key,
158 bool value) { 158 bool value) {
159 StoreDisplayPropertyForList(list, key, 159 StoreDisplayPropertyForList(list, key,
160 base::MakeUnique<base::Value>(value)); 160 base::MakeUnique<base::Value>(value));
161 } 161 }
162 162
163 void StoreDisplayLayoutPrefForList(const display::DisplayIdList& list, 163 void StoreDisplayLayoutPrefForList(const display::DisplayIdList& list,
164 display::DisplayPlacement::Position layout, 164 display::DisplayPlacement::Position layout,
165 int offset) { 165 int offset) {
166 StoreDisplayLayoutPrefForList(list, layout, offset, list[0]); 166 StoreDisplayLayoutPrefForList(list, layout, offset, list[0]);
167 } 167 }
168 168
169 void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) { 169 void StoreDisplayOverscan(int64_t id, const gfx::Insets& insets) {
170 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); 170 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties);
171 const std::string name = base::Int64ToString(id); 171 const std::string name = base::Int64ToString(id);
172 172
173 base::DictionaryValue* pref_data = update.Get(); 173 base::DictionaryValue* pref_data = update.Get();
174 base::DictionaryValue* insets_value = new base::DictionaryValue(); 174 auto insets_value = base::MakeUnique<base::DictionaryValue>();
175 insets_value->SetInteger("insets_top", insets.top()); 175 insets_value->SetInteger("insets_top", insets.top());
176 insets_value->SetInteger("insets_left", insets.left()); 176 insets_value->SetInteger("insets_left", insets.left());
177 insets_value->SetInteger("insets_bottom", insets.bottom()); 177 insets_value->SetInteger("insets_bottom", insets.bottom());
178 insets_value->SetInteger("insets_right", insets.right()); 178 insets_value->SetInteger("insets_right", insets.right());
179 pref_data->Set(name, insets_value); 179 pref_data->Set(name, std::move(insets_value));
180 } 180 }
181 181
182 void StoreColorProfile(int64_t id, const std::string& profile) { 182 void StoreColorProfile(int64_t id, const std::string& profile) {
183 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); 183 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties);
184 const std::string name = base::Int64ToString(id); 184 const std::string name = base::Int64ToString(id);
185 185
186 base::DictionaryValue* pref_data = update.Get(); 186 base::DictionaryValue* pref_data = update.Get();
187 base::DictionaryValue* property = new base::DictionaryValue(); 187 auto property = base::MakeUnique<base::DictionaryValue>();
188 property->SetString("color_profile_name", profile); 188 property->SetString("color_profile_name", profile);
189 pref_data->Set(name, property); 189 pref_data->Set(name, std::move(property));
190 } 190 }
191 191
192 void StoreDisplayRotationPrefsForTest(bool rotation_lock, 192 void StoreDisplayRotationPrefsForTest(bool rotation_lock,
193 display::Display::Rotation rotation) { 193 display::Display::Rotation rotation) {
194 DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock); 194 DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock);
195 base::DictionaryValue* pref_data = update.Get(); 195 base::DictionaryValue* pref_data = update.Get();
196 pref_data->SetBoolean("lock", rotation_lock); 196 pref_data->SetBoolean("lock", rotation_lock);
197 pref_data->SetInteger("orientation", static_cast<int>(rotation)); 197 pref_data->SetInteger("orientation", static_cast<int>(rotation));
198 } 198 }
199 199
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1156
1157 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), 1157 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
1158 display_manager()->GetDisplayForId(list[0]).bounds()); 1158 display_manager()->GetDisplayForId(list[0]).bounds());
1159 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), 1159 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200),
1160 display_manager()->GetDisplayForId(list[1]).bounds()); 1160 display_manager()->GetDisplayForId(list[1]).bounds());
1161 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), 1161 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300),
1162 display_manager()->GetDisplayForId(list[2]).bounds()); 1162 display_manager()->GetDisplayForId(list[2]).bounds());
1163 } 1163 }
1164 1164
1165 } // namespace chromeos 1165 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698