| OLD | NEW |
| 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 "chrome/browser/policy/test/local_policy_test_server.h" | 5 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return false; | 233 return false; |
| 234 | 234 |
| 235 arguments->SetString("config-file", config_file_.AsUTF8Unsafe()); | 235 arguments->SetString("config-file", config_file_.AsUTF8Unsafe()); |
| 236 if (!policy_key_.empty()) | 236 if (!policy_key_.empty()) |
| 237 arguments->SetString("policy-key", policy_key_.AsUTF8Unsafe()); | 237 arguments->SetString("policy-key", policy_key_.AsUTF8Unsafe()); |
| 238 if (server_data_dir_.IsValid()) { | 238 if (server_data_dir_.IsValid()) { |
| 239 arguments->SetString("data-dir", server_data_dir_.path().AsUTF8Unsafe()); | 239 arguments->SetString("data-dir", server_data_dir_.path().AsUTF8Unsafe()); |
| 240 | 240 |
| 241 if (!clients_.empty()) { | 241 if (!clients_.empty()) { |
| 242 std::string json; | 242 std::string json; |
| 243 base::JSONWriter::Write(&clients_, &json); | 243 base::JSONWriter::Write(clients_, &json); |
| 244 base::FilePath client_state_file = | 244 base::FilePath client_state_file = |
| 245 server_data_dir_.path().Append(kClientStateFileName); | 245 server_data_dir_.path().Append(kClientStateFileName); |
| 246 if (base::WriteFile(client_state_file, json.c_str(), json.size()) != | 246 if (base::WriteFile(client_state_file, json.c_str(), json.size()) != |
| 247 static_cast<int>(json.size())) { | 247 static_cast<int>(json.size())) { |
| 248 return false; | 248 return false; |
| 249 } | 249 } |
| 250 arguments->SetString("client-state", client_state_file.AsUTF8Unsafe()); | 250 arguments->SetString("client-state", client_state_file.AsUTF8Unsafe()); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 return true; | 254 return true; |
| 255 } | 255 } |
| 256 | 256 |
| 257 std::string LocalPolicyTestServer::GetSelector(const std::string& type, | 257 std::string LocalPolicyTestServer::GetSelector(const std::string& type, |
| 258 const std::string& entity_id) { | 258 const std::string& entity_id) { |
| 259 std::string selector = type; | 259 std::string selector = type; |
| 260 if (!entity_id.empty()) | 260 if (!entity_id.empty()) |
| 261 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str()); | 261 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str()); |
| 262 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_'); | 262 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_'); |
| 263 return selector; | 263 return selector; |
| 264 } | 264 } |
| 265 | 265 |
| 266 } // namespace policy | 266 } // namespace policy |
| OLD | NEW |