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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handler.h"
6 #include "components/prefs/pref_value_map.h"
7 
8 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest.h"
9 
10 namespace extensions {
11 
NativeMessagingHostListPolicyHandler(const char * policy_name,const char * pref_path,bool allow_wildcards)12 NativeMessagingHostListPolicyHandler::NativeMessagingHostListPolicyHandler(
13     const char* policy_name,
14     const char* pref_path,
15     bool allow_wildcards)
16     : policy::ListPolicyHandler(policy_name, base::Value::Type::STRING),
17       pref_path_(pref_path),
18       allow_wildcards_(allow_wildcards) {}
19 
~NativeMessagingHostListPolicyHandler()20 NativeMessagingHostListPolicyHandler::~NativeMessagingHostListPolicyHandler() {}
21 
CheckListEntry(const base::Value & value)22 bool NativeMessagingHostListPolicyHandler::CheckListEntry(
23     const base::Value& value) {
24   const std::string& str = value.GetString();
25   if (allow_wildcards_ && str == "*")
26     return true;
27 
28   return NativeMessagingHostManifest::IsValidName(str);
29 }
30 
ApplyList(base::Value filtered_list,PrefValueMap * prefs)31 void NativeMessagingHostListPolicyHandler::ApplyList(base::Value filtered_list,
32                                                      PrefValueMap* prefs) {
33   DCHECK(filtered_list.is_list());
34   prefs->SetValue(pref_path_, std::move(filtered_list));
35 }
36 
37 }  // namespace extensions
38