// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/ios/ios_util.h"

#include "base/sys_info.h"

namespace {
// Return a 3 elements array containing the major, minor and bug fix version of
// the OS.
const int32* OSVersionAsArray() {
  int32* digits = new int32[3];
  base::SysInfo::OperatingSystemVersionNumbers(
      &digits[0], &digits[1], &digits[2]);
  return digits;
}
}  // namespace

namespace base {
namespace ios {

bool IsRunningOnIOS8OrLater() {
  return IsRunningOnOrLater(8, 0, 0);
}

bool IsRunningOnOrLater(int32 major, int32 minor, int32 bug_fix) {
  static const int32* current_version = OSVersionAsArray();
  int32 version[] = { major, minor, bug_fix };
  for (size_t i = 0; i < arraysize(version); i++) {
    if (current_version[i] != version[i])
      return current_version[i] > version[i];
  }
  return true;
}

}  // namespace ios
}  // namespace base

// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/ios/ios_util.h"

#include "base/sys_info.h"

namespace {
// Return a 3 elements array containing the major, minor and bug fix version of
// the OS.
const int32* OSVersionAsArray() {
  int32* digits = new int32[3];
  base::SysInfo::OperatingSystemVersionNumbers(
      &digits[0], &digits[1], &digits[2]);
  return digits;
}
}  // namespace

namespace base {
namespace ios {

// When dropping iOS7 support, also address issues listed in crbug.com/502968.
bool IsRunningOnIOS8OrLater() {
  return IsRunningOnOrLater(8, 0, 0);
}

bool IsRunningOnOrLater(int32 major, int32 minor, int32 bug_fix) {
  static const int32* current_version = OSVersionAsArray();
  int32 version[] = { major, minor, bug_fix };
  for (size_t i = 0; i < arraysize(version); i++) {
    if (current_version[i] != version[i])
      return current_version[i] > version[i];
  }
  return true;
}

}  // namespace ios
}  // namespace base

Add mention of iOS7-support-drop TODO list.
Add mention of iOS7-support-drop TODO list.

BUG=502968

Review URL: https://codereview.chromium.org/1198633003

Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#335481}
