summaryrefslogtreecommitdiffstats
path: root/chrome/installer/util/version.cc
blob: 7618e7dedcab8aac90d25cfbb115916ce44012a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2010 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 "chrome/installer/util/version.h"

#include <vector>

#include "base/format_macros.h"
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/installer/util/version.h"

installer::Version::Version(int64 major, int64 minor, int64 build,
                            int64 patch)
    : major_(major),
      minor_(minor),
      build_(build),
      patch_(patch) {
  version_str_ = ASCIIToUTF16(
      StringPrintf("%" PRId64 ".%" PRId64 ".%" PRId64 ".%" PRId64,
                   major_, minor_, build_, patch_));
}

installer::Version::~Version() {
}

bool installer::Version::IsHigherThan(const installer::Version* other) const {
  return ((major_ > other->major_) ||
          ((major_ == other->major_) && (minor_ > other->minor_)) ||
          ((major_ == other->major_) && (minor_ == other->minor_)
                                     && (build_ > other->build_)) ||
          ((major_ == other->major_) && (minor_ == other->minor_)
                                     && (build_ == other->build_)
                                     && (patch_ > other->patch_)));
}

installer::Version* installer::Version::GetVersionFromString(
    const string16& version_str) {
  std::vector<string16> numbers;
  base::SplitString(version_str, '.', &numbers);

  if (numbers.size() != 4) {
    LOG(ERROR) << "Invalid version string: " << version_str;
    return NULL;
  }

  int64 v0, v1, v2, v3;
  base::StringToInt64(numbers[0], &v0);
  base::StringToInt64(numbers[1], &v1);
  base::StringToInt64(numbers[2], &v2);
  base::StringToInt64(numbers[3], &v3);
  return new Version(v0, v1, v2, v3);
}