summaryrefslogtreecommitdiffstats
path: root/chromium/components/policy/core/common/values_util.cc
blob: c2b269f38d8cc186b43cfc5b6972600ecad102c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/policy/core/common/values_util.h"

#include <vector>

namespace policy {

base::flat_set<std::string> ValueToStringSet(const base::Value* value) {
  if (!value || !value->is_list())
    return base::flat_set<std::string>();

  const auto& items = value->GetListDeprecated();

  std::vector<std::string> item_vector;
  item_vector.reserve(items.size());

  for (const auto& item : items) {
    if (item.is_string())
      item_vector.emplace_back(item.GetString());
  }

  return base::flat_set<std::string>(std::move(item_vector));
}

}  // namespace policy