Fix race in WebRTC logging.
[chromium-blink-merge.git] / ppapi / shared_impl / var_value_conversions.h
blobdfbda50334a1f3fe6abd420d10426de1b5a66b59
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_SHARED_IMPL_VAR_VALUE_CONVERSIONS_H_
6 #define PPAPI_SHARED_IMPL_VAR_VALUE_CONVERSIONS_H_
8 #include <vector>
10 #include "ppapi/c/pp_var.h"
11 #include "ppapi/shared_impl/ppapi_shared_export.h"
13 namespace base {
14 class ListValue;
15 class Value;
18 namespace ppapi {
20 // Converts a PP_Var to a base::Value object. The caller takes ownership of the
21 // returned object.
23 // Both PP_VARTYPE_UNDEFINED and PP_VARTYPE_NULL are converted to
24 // base::Value::TYPE_NULL. In dictionary vars, key-value pairs whose value is
25 // undefined (PP_VARTYPE_UNDEFINED) or null (PP_VARTYPE_NULL) are ignored. If a
26 // node in |var| appears more than once, it is duplicated in the result. For
27 // example, if |var| is an array and it has two elements pointing to the same
28 // dictionary, the resulting list value will have two copies of the dictionary.
30 // The conversion fails and returns NULL if
31 // - |var| is object (PP_VARTYPE_OBJECT); or
32 // - |var| is an array or dictionary, and calling CreateValueFromVar() on any of
33 // the array elements or dictionary values fails; or
34 // - there exist circular references, i.e., an array or dictionary is its own
35 // ancestor/descendant.
36 PPAPI_SHARED_EXPORT base::Value* CreateValueFromVar(const PP_Var& var);
38 // The returned var has had 1 ref added on behalf of the caller.
39 // Returns an undefined var if the conversion fails.
40 PPAPI_SHARED_EXPORT PP_Var CreateVarFromValue(const base::Value& value);
42 // Calls CreateValueFromVar() on each element of |vars| and puts them in a
43 // base::ListValue. The caller takes ownership of the returned object.
45 // The conversion fails and returns NULL if any of the calls to
46 // CreateValueFromVar() fails.
47 PPAPI_SHARED_EXPORT base::ListValue* CreateListValueFromVarVector(
48 const std::vector<PP_Var>& vars);
50 // Calls CreateVarFromValue() on each element of |list_value| and puts them in
51 // |vars|. The returned vars have had 1 ref added on behalf of the caller.
53 // The conversion fails and returns false if any of the calls to
54 // CreateVarFromValue() fails. In that case, |vars| is untouched.
55 PPAPI_SHARED_EXPORT bool CreateVarVectorFromListValue(
56 const base::ListValue& list_value,
57 std::vector<PP_Var>* vars);
59 } // namespace ppapi
61 #endif // PPAPI_SHARED_IMPL_VAR_VALUE_CONVERSIONS_H_