OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "webkit/glue/dalvik_heap_size_android.h" | |
jamesr
2012/04/20 00:44:26
i can't figure out why this class is here. it has
ulan
2012/04/20 08:55:43
Moved it to webkitplatformsupport_impl.cc, where i
| |
6 | |
7 #include <sys/system_properties.h> | |
8 | |
9 #include "base/memory/singleton.h" | |
10 #include "base/string_number_conversions.h" | |
11 | |
12 namespace webkit_glue { | |
13 | |
14 DalvikHeapSize* DalvikHeapSize::GetInstance() { | |
15 return Singleton<DalvikHeapSize>::get(); | |
16 } | |
17 | |
18 DalvikHeapSize::DalvikHeapSize() : heap_size_mb_(0) { | |
19 char heap_size_str[PROP_VALUE_MAX]; | |
20 __system_property_get("dalvik.vm.heapsize", heap_size_str); | |
21 heap_size_mb_ = ParseHeapSize(std::string(heap_size_str)); | |
22 } | |
23 | |
24 DalvikHeapSize::~DalvikHeapSize() {} | |
25 | |
26 int DalvikHeapSize::HeapSizeMB() const { return heap_size_mb_; } | |
27 | |
28 int DalvikHeapSize::ParseHeapSize(const std::string& str) const { | |
29 CHECK_GT(str.size(), 0u); | |
30 DCHECK_EQ('m', str[str.size() - 1]); | |
jamesr
2012/04/20 00:44:26
this seems a bit fragile - you can't have a value
ulan
2012/04/20 08:55:43
Added handling of 'k', 'g' and switched to int64 t
| |
31 int result = 0; | |
32 base::StringToInt(str.substr(0, str.size() - 1), &result); | |
jamesr
2012/04/20 00:44:26
base::StringToInt() returns a bool indicating if t
ulan
2012/04/20 08:55:43
Done.
| |
33 DCHECK_GT(result, 0); | |
34 // dalvik.vm.heapsize property is writable by user, | |
35 // truncate it to reasonable value to avoid overflows later. | |
36 return std::min(std::max(32, result), 1024); | |
37 } | |
38 | |
39 } // webkit_glue namespace | |
OLD | NEW |