Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: base/value_conversions.cc

Issue 2773513002: Stop passing raw pointers to DictionaryValue::Set, part 1 (Closed)
Patch Set: Fix compilation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/value_conversions.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/value_conversions.h" 5 #include "base/value_conversions.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 // |Value| internally stores strings in UTF-8, so we have to convert from the 19 // |Value| internally stores strings in UTF-8, so we have to convert from the
19 // system native code to UTF-8 and back. 20 // system native code to UTF-8 and back.
20 Value* CreateFilePathValue(const FilePath& in_value) { 21 std::unique_ptr<Value> CreateFilePathValue(const FilePath& in_value) {
21 return new Value(in_value.AsUTF8Unsafe()); 22 return base::MakeUnique<Value>(in_value.AsUTF8Unsafe());
22 } 23 }
23 24
24 bool GetValueAsFilePath(const Value& value, FilePath* file_path) { 25 bool GetValueAsFilePath(const Value& value, FilePath* file_path) {
25 std::string str; 26 std::string str;
26 if (!value.GetAsString(&str)) 27 if (!value.GetAsString(&str))
27 return false; 28 return false;
28 if (file_path) 29 if (file_path)
29 *file_path = FilePath::FromUTF8Unsafe(str); 30 *file_path = FilePath::FromUTF8Unsafe(str);
30 return true; 31 return true;
31 } 32 }
32 33
33 // |Value| does not support 64-bit integers, and doubles do not have enough 34 // |Value| does not support 64-bit integers, and doubles do not have enough
34 // precision, so we store the 64-bit time value as a string instead. 35 // precision, so we store the 64-bit time value as a string instead.
35 Value* CreateTimeDeltaValue(const TimeDelta& time) { 36 std::unique_ptr<Value> CreateTimeDeltaValue(const TimeDelta& time) {
36 std::string string_value = base::Int64ToString(time.ToInternalValue()); 37 std::string string_value = base::Int64ToString(time.ToInternalValue());
37 return new Value(string_value); 38 return base::MakeUnique<Value>(string_value);
38 } 39 }
39 40
40 bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) { 41 bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) {
41 std::string str; 42 std::string str;
42 int64_t int_value; 43 int64_t int_value;
43 if (!value.GetAsString(&str) || !base::StringToInt64(str, &int_value)) 44 if (!value.GetAsString(&str) || !base::StringToInt64(str, &int_value))
44 return false; 45 return false;
45 if (time) 46 if (time)
46 *time = TimeDelta::FromInternalValue(int_value); 47 *time = TimeDelta::FromInternalValue(int_value);
47 return true; 48 return true;
48 } 49 }
49 50
50 } // namespace base 51 } // namespace base
OLDNEW
« no previous file with comments | « base/value_conversions.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698