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

Side by Side Diff: base/sys_info_android.cc

Issue 10832235: Move Android user agent generation to native code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved Android OS info function over to webkit_glue Created 8 years, 4 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
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/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <sys/system_properties.h> 7 #include <sys/system_properties.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 #include "base/stringprintf.h"
12 13
13 namespace { 14 namespace {
14 15
16 // Parse out the OS version numbers from the system properties.
17 void ParseOSVersionNumbers(const char* os_version_str,
18 int *major_version,
19 int *minor_version,
20 int *bugfix_version) {
21 if (strlen(os_version_str) > 0) {
22 // Try to parse out the version numbers from the string.
23 int num_read = sscanf(os_version_str, "%d.%d.%d", major_version,
24 minor_version, bugfix_version);
jar (doing other things) 2012/08/15 23:35:17 nit: better to wrap to paren when you can (and you
gone 2012/08/16 00:29:31 Ah, wasn't sure whether the style guide allowed it
25
26 if (num_read > 0) {
27 // If we don't have a full set of version numbers, make the extras 0.
28 if (num_read < 2) *minor_version = 0;
29 if (num_read < 3) *bugfix_version = 0;
30 return;
31 }
32 }
33
34 // For some reason, we couldn't parse the version number string.
35 *major_version = base::SysInfo::kDefaultAndroidMajorVersion;
36 *minor_version = base::SysInfo::kDefaultAndroidMinorVersion;
37 *bugfix_version = base::SysInfo::kDefaultAndroidBugfixVersion;
38 }
39
15 int ParseHeapSize(const base::StringPiece& str) { 40 int ParseHeapSize(const base::StringPiece& str) {
16 const int64 KB = 1024; 41 const int64 KB = 1024;
17 const int64 MB = 1024 * KB; 42 const int64 MB = 1024 * KB;
18 const int64 GB = 1024 * MB; 43 const int64 GB = 1024 * MB;
19 CHECK_GT(str.size(), 0u); 44 CHECK_GT(str.size(), 0u);
20 int64 factor = 1; 45 int64 factor = 1;
21 size_t length = str.size(); 46 size_t length = str.size();
22 if (str[length - 1] == 'k') { 47 if (str[length - 1] == 'k') {
23 factor = KB; 48 factor = KB;
24 length--; 49 length--;
(...skipping 19 matching lines...) Expand all
44 int GetDalvikHeapSizeMB() { 69 int GetDalvikHeapSizeMB() {
45 char heap_size_str[PROP_VALUE_MAX]; 70 char heap_size_str[PROP_VALUE_MAX];
46 __system_property_get("dalvik.vm.heapsize", heap_size_str); 71 __system_property_get("dalvik.vm.heapsize", heap_size_str);
47 return ParseHeapSize(heap_size_str); 72 return ParseHeapSize(heap_size_str);
48 } 73 }
49 74
50 } // anonymous namespace 75 } // anonymous namespace
51 76
52 namespace base { 77 namespace base {
53 78
79 std::string SysInfo::GetAndroidBuildCodename() {
80 char os_version_codename_str[PROP_VALUE_MAX];
81 __system_property_get("ro.build.version.codename", os_version_codename_str);
82 return std::string(os_version_codename_str);
83 }
84
85 std::string SysInfo::GetAndroidBuildID() {
86 char os_build_id_str[PROP_VALUE_MAX];
87 __system_property_get("ro.build.id", os_build_id_str);
88 return std::string(os_build_id_str);
89 }
90
91 std::string SysInfo::GetDeviceName() {
92 char device_model_str[PROP_VALUE_MAX];
93 __system_property_get("ro.product.model", device_model_str);
94 return std::string(device_model_str);
95 }
96
97 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
98 int32* minor_version,
99 int32* bugfix_version) {
100 // Read the version number string out from the properties.
101 char os_version_str[PROP_VALUE_MAX];
102 __system_property_get("ro.build.version.release", os_version_str);
103
104 // Parse out the numbers.
105 int internal_major_version, internal_minor_version, internal_bugfix_version;
jar (doing other things) 2012/08/15 23:35:17 What is the advantage of having these temporaries?
gone 2012/08/16 00:29:31 They're defined as int32s for all of the other pla
106 ParseOSVersionNumbers(os_version_str, &internal_major_version,
107 &internal_minor_version, &internal_bugfix_version);
108 *major_version = internal_major_version;
109 *minor_version = internal_minor_version;
110 *bugfix_version = internal_bugfix_version;
111 }
112
54 int SysInfo::DalvikHeapSizeMB() { 113 int SysInfo::DalvikHeapSizeMB() {
55 static int heap_size = GetDalvikHeapSizeMB(); 114 static int heap_size = GetDalvikHeapSizeMB();
56 return heap_size; 115 return heap_size;
57 } 116 }
58 117
59 } // namespace base 118 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698