1 // Copyright (c) 2012 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 #include "base/value_conversions.h"
7 #include "base/files/file_path.h"
8 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
14 // |Value| internally stores strings in UTF-8, so we have to convert from the
15 // system native code to UTF-8 and back.
16 StringValue
* CreateFilePathValue(const FilePath
& in_value
) {
17 return new StringValue(in_value
.AsUTF8Unsafe());
20 bool GetValueAsFilePath(const Value
& value
, FilePath
* file_path
) {
22 if (!value
.GetAsString(&str
))
25 *file_path
= FilePath::FromUTF8Unsafe(str
);
29 // |Value| does not support 64-bit integers, and doubles do not have enough
30 // precision, so we store the 64-bit time value as a string instead.
31 StringValue
* CreateTimeDeltaValue(const TimeDelta
& time
) {
32 std::string string_value
= base::Int64ToString(time
.ToInternalValue());
33 return new StringValue(string_value
);
36 bool GetValueAsTimeDelta(const Value
& value
, TimeDelta
* time
) {
39 if (!value
.GetAsString(&str
) || !base::StringToInt64(str
, &int_value
))
42 *time
= TimeDelta::FromInternalValue(int_value
);