Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ios/ios_util.h" | 5 #include "base/ios/ios_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Return a 3 elements array containing the major, minor and bug fix version of | 15 // Return a 3 elements array containing the major, minor and bug fix version of |
| 16 // the OS. | 16 // the OS. |
| 17 const int32_t* OSVersionAsArray() { | 17 const int32_t* OSVersionAsArray() { |
| 18 int32_t* digits = new int32_t[3]; | 18 int32_t* digits = new int32_t[3]; |
| 19 base::SysInfo::OperatingSystemVersionNumbers( | 19 base::SysInfo::OperatingSystemVersionNumbers( |
| 20 &digits[0], &digits[1], &digits[2]); | 20 &digits[0], &digits[1], &digits[2]); |
| 21 return digits; | 21 return digits; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Caches the result of IsRunningOnIOS10OrLater(). | |
|
rohitrao (ping after 24h)
2017/06/14 01:10:13
We'll be adding IsRunningOnIOS11OrLater() shortly,
| |
| 25 enum { kUnknown, kIos9orEarlier, kIos10orLater } g_ios_version = kUnknown; | |
|
Eugene But (OOO till 7-30)
2017/06/14 00:59:48
Should we cache the result of OSVersionAsArray ins
rohitrao (ping after 24h)
2017/06/14 01:10:13
Can you clarify what issue might "show up again la
Eugene But (OOO till 7-30)
2017/06/14 01:31:53
Sorry, I meant IsRunningOnIOS11(12/13/etc..)OrLate
| |
| 26 | |
| 24 std::string* g_icudtl_path_override = nullptr; | 27 std::string* g_icudtl_path_override = nullptr; |
| 25 | 28 |
| 26 } // namespace | 29 } // namespace |
| 27 | 30 |
| 28 namespace base { | 31 namespace base { |
| 29 namespace ios { | 32 namespace ios { |
| 30 | 33 |
| 31 bool IsRunningOnIOS10OrLater() { | 34 bool IsRunningOnIOS10OrLater() { |
| 32 return IsRunningOnOrLater(10, 0, 0); | 35 if (g_ios_version == kUnknown) { |
|
Eugene But (OOO till 7-30)
2017/06/14 00:59:48
This makes the function non-thread safe, which you
| |
| 36 g_ios_version = | |
| 37 IsRunningOnOrLater(10, 0, 0) ? kIos10orLater : kIos9orEarlier; | |
| 38 } | |
| 39 return g_ios_version == kIos10orLater; | |
| 33 } | 40 } |
| 34 | 41 |
| 35 bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) { | 42 bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) { |
| 36 static const int32_t* current_version = OSVersionAsArray(); | 43 static const int32_t* current_version = OSVersionAsArray(); |
| 37 int32_t version[] = {major, minor, bug_fix}; | 44 int32_t version[] = {major, minor, bug_fix}; |
| 38 for (size_t i = 0; i < arraysize(version); i++) { | 45 for (size_t i = 0; i < arraysize(version); i++) { |
| 39 if (current_version[i] != version[i]) | 46 if (current_version[i] != version[i]) |
| 40 return current_version[i] > version[i]; | 47 return current_version[i] > version[i]; |
| 41 } | 48 } |
| 42 return true; | 49 return true; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 54 | 61 |
| 55 FilePath FilePathOfEmbeddedICU() { | 62 FilePath FilePathOfEmbeddedICU() { |
| 56 if (g_icudtl_path_override) { | 63 if (g_icudtl_path_override) { |
| 57 return FilePath(*g_icudtl_path_override); | 64 return FilePath(*g_icudtl_path_override); |
| 58 } | 65 } |
| 59 return FilePath(); | 66 return FilePath(); |
| 60 } | 67 } |
| 61 | 68 |
| 62 } // namespace ios | 69 } // namespace ios |
| 63 } // namespace base | 70 } // namespace base |
| OLD | NEW |