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

Side by Side Diff: chromeos/network/managed_network_configuration_handler_unittest.cc

Issue 2871653002: Remove raw base::DictionaryValue::SetWithoutPathExpansion in //chromeos (Closed)
Patch Set: Minor Fix Created 3 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <iostream> 5 #include <iostream>
6 #include <memory> 6 #include <memory>
7 #include <sstream> 7 #include <sstream>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 16 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 18 #include "base/stl_util.h"
17 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/values.h" 20 #include "base/values.h"
19 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/dbus/mock_shill_manager_client.h" 22 #include "chromeos/dbus/mock_shill_manager_client.h"
21 #include "chromeos/dbus/mock_shill_profile_client.h" 23 #include "chromeos/dbus/mock_shill_profile_client.h"
22 #include "chromeos/dbus/mock_shill_service_client.h" 24 #include "chromeos/dbus/mock_shill_service_client.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 public: 94 public:
93 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus 95 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus
94 DictionaryValueCallbackWithoutStatus; 96 DictionaryValueCallbackWithoutStatus;
95 typedef ShillClientHelper::ErrorCallback ErrorCallback; 97 typedef ShillClientHelper::ErrorCallback ErrorCallback;
96 98
97 void AddProfile(const std::string& profile_path, 99 void AddProfile(const std::string& profile_path,
98 const std::string& userhash) { 100 const std::string& userhash) {
99 if (profile_entries_.HasKey(profile_path)) 101 if (profile_entries_.HasKey(profile_path))
100 return; 102 return;
101 103
102 base::DictionaryValue* profile = new base::DictionaryValue; 104 profile_entries_.SetWithoutPathExpansion(
103 profile_entries_.SetWithoutPathExpansion(profile_path, profile); 105 profile_path, base::MakeUnique<base::DictionaryValue>());
104 profile_to_user_[profile_path] = userhash; 106 profile_to_user_[profile_path] = userhash;
105 } 107 }
106 108
107 void AddEntry(const std::string& profile_path, 109 void AddEntry(const std::string& profile_path,
108 const std::string& entry_path, 110 const std::string& entry_path,
109 const base::DictionaryValue& entry) { 111 const base::DictionaryValue& entry) {
110 base::DictionaryValue* entries = NULL; 112 base::DictionaryValue* entries = NULL;
111 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path, &entries); 113 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path, &entries);
112 ASSERT_TRUE(entries); 114 ASSERT_TRUE(entries);
113 115
114 base::DictionaryValue* new_entry = entry.DeepCopy(); 116 auto new_entry = base::MakeUnique<base::DictionaryValue>(entry);
115 new_entry->SetStringWithoutPathExpansion(shill::kProfileProperty, 117 new_entry->SetStringWithoutPathExpansion(shill::kProfileProperty,
116 profile_path); 118 profile_path);
117 entries->SetWithoutPathExpansion(entry_path, new_entry); 119 entries->SetWithoutPathExpansion(entry_path, std::move(new_entry));
118 } 120 }
119 121
120 void GetProperties(const dbus::ObjectPath& profile_path, 122 void GetProperties(const dbus::ObjectPath& profile_path,
121 const DictionaryValueCallbackWithoutStatus& callback, 123 const DictionaryValueCallbackWithoutStatus& callback,
122 const ErrorCallback& error_callback) { 124 const ErrorCallback& error_callback) {
123 base::DictionaryValue* entries = NULL; 125 base::DictionaryValue* entries = NULL;
124 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(), 126 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(),
125 &entries); 127 &entries);
126 ASSERT_TRUE(entries); 128 ASSERT_TRUE(entries);
127 129
128 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); 130 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
129 base::ListValue* entry_paths = new base::ListValue; 131 auto entry_paths = base::MakeUnique<base::ListValue>();
130 result->SetWithoutPathExpansion(shill::kEntriesProperty, entry_paths);
131 for (base::DictionaryValue::Iterator it(*entries); !it.IsAtEnd(); 132 for (base::DictionaryValue::Iterator it(*entries); !it.IsAtEnd();
132 it.Advance()) { 133 it.Advance()) {
133 entry_paths->AppendString(it.key()); 134 entry_paths->AppendString(it.key());
134 } 135 }
136 result->SetWithoutPathExpansion(shill::kEntriesProperty,
137 std::move(entry_paths));
135 138
136 ASSERT_TRUE(base::ContainsKey(profile_to_user_, profile_path.value())); 139 ASSERT_TRUE(base::ContainsKey(profile_to_user_, profile_path.value()));
137 const std::string& userhash = profile_to_user_[profile_path.value()]; 140 const std::string& userhash = profile_to_user_[profile_path.value()];
138 result->SetStringWithoutPathExpansion(shill::kUserHashProperty, userhash); 141 result->SetStringWithoutPathExpansion(shill::kUserHashProperty, userhash);
139 142
140 base::ThreadTaskRunnerHandle::Get()->PostTask( 143 base::ThreadTaskRunnerHandle::Get()->PostTask(
141 FROM_HERE, base::Bind(&DereferenceAndCall, callback, 144 FROM_HERE, base::Bind(&DereferenceAndCall, callback,
142 base::Owned(result.release()))); 145 base::Owned(result.release())));
143 } 146 }
144 147
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 EXPECT_CALL(*mock_profile_client_, 982 EXPECT_CALL(*mock_profile_client_,
980 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _)); 983 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
981 984
982 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc"); 985 SetPolicy(::onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
983 managed_network_configuration_handler_->RemoveObserver(&policy_observer_); 986 managed_network_configuration_handler_->RemoveObserver(&policy_observer_);
984 managed_network_configuration_handler_.reset(); 987 managed_network_configuration_handler_.reset();
985 base::RunLoop().RunUntilIdle(); 988 base::RunLoop().RunUntilIdle();
986 } 989 }
987 990
988 } // namespace chromeos 991 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698