| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/network/auto_connect_handler.h" | 5 #include "chromeos/network/auto_connect_handler.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" | 
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" | 
|  | 13 #include "base/macros.h" | 
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" | 
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" | 
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" | 
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" | 
| 17 #include "chromeos/cert_loader.h" | 18 #include "chromeos/cert_loader.h" | 
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" | 
| 19 #include "chromeos/dbus/shill_device_client.h" | 20 #include "chromeos/dbus/shill_device_client.h" | 
| 20 #include "chromeos/dbus/shill_manager_client.h" | 21 #include "chromeos/dbus/shill_manager_client.h" | 
| 21 #include "chromeos/dbus/shill_profile_client.h" | 22 #include "chromeos/dbus/shill_profile_client.h" | 
| 22 #include "chromeos/dbus/shill_service_client.h" | 23 #include "chromeos/dbus/shill_service_client.h" | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 207                                             test_nssdb_.slot())); | 208                                             test_nssdb_.slot())); | 
| 208     return client_cert; | 209     return client_cert; | 
| 209   } | 210   } | 
| 210 | 211 | 
| 211   void SetupPolicy(const std::string& network_configs_json, | 212   void SetupPolicy(const std::string& network_configs_json, | 
| 212                    const base::DictionaryValue& global_config, | 213                    const base::DictionaryValue& global_config, | 
| 213                    bool user_policy) { | 214                    bool user_policy) { | 
| 214     scoped_ptr<base::ListValue> network_configs(new base::ListValue); | 215     scoped_ptr<base::ListValue> network_configs(new base::ListValue); | 
| 215     if (!network_configs_json.empty()) { | 216     if (!network_configs_json.empty()) { | 
| 216       std::string error; | 217       std::string error; | 
| 217       base::Value* network_configs_value = | 218       scoped_ptr<base::Value> network_configs_value = | 
| 218           base::JSONReader::DeprecatedReadAndReturnError( | 219           base::JSONReader::ReadAndReturnError(network_configs_json, | 
| 219               network_configs_json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, | 220                                                base::JSON_ALLOW_TRAILING_COMMAS, | 
| 220               &error); | 221                                                nullptr, &error); | 
| 221       ASSERT_TRUE(network_configs_value) << error; | 222       ASSERT_TRUE(network_configs_value) << error; | 
| 222       base::ListValue* network_configs_list = nullptr; | 223       base::ListValue* network_configs_list = nullptr; | 
| 223       ASSERT_TRUE(network_configs_value->GetAsList(&network_configs_list)); | 224       ASSERT_TRUE(network_configs_value->GetAsList(&network_configs_list)); | 
|  | 225       ignore_result(network_configs_value.release()); | 
| 224       network_configs.reset(network_configs_list); | 226       network_configs.reset(network_configs_list); | 
| 225     } | 227     } | 
| 226 | 228 | 
| 227     if (user_policy) { | 229     if (user_policy) { | 
| 228       managed_config_handler_->SetPolicy(::onc::ONC_SOURCE_USER_POLICY, | 230       managed_config_handler_->SetPolicy(::onc::ONC_SOURCE_USER_POLICY, | 
| 229                                          kUserHash, *network_configs, | 231                                          kUserHash, *network_configs, | 
| 230                                          global_config); | 232                                          global_config); | 
| 231     } else { | 233     } else { | 
| 232       managed_config_handler_->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, | 234       managed_config_handler_->SetPolicy(::onc::ONC_SOURCE_DEVICE_POLICY, | 
| 233                                          std::string(),  // no username hash | 235                                          std::string(),  // no username hash | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 462   // Applying the user policy after login would usually trigger connecting to | 464   // Applying the user policy after login would usually trigger connecting to | 
| 463   // the 'best' network. But the manual connect prevents this. | 465   // the 'best' network. But the manual connect prevents this. | 
| 464   SetupPolicy(std::string(),            // no network configs | 466   SetupPolicy(std::string(),            // no network configs | 
| 465               base::DictionaryValue(),  // no global config | 467               base::DictionaryValue(),  // no global config | 
| 466               true);                    // load as user policy | 468               true);                    // load as user policy | 
| 467   EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); | 469   EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0")); | 
| 468   EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); | 470   EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1")); | 
| 469 } | 471 } | 
| 470 | 472 | 
| 471 }  // namespace chromeos | 473 }  // namespace chromeos | 
| OLD | NEW | 
|---|