summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles/chrome_version_service.cc
blob: 7133139a14c01e513243bb1c10757122416f4d0b (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
// Copyright (c) 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 "chrome/browser/profiles/chrome_version_service.h"

#include "base/prefs/pref_service.h"
#include "base/version.h"
#include "chrome/browser/prefs/pref_registry_syncable.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"

// static
void ChromeVersionService::RegisterUserPrefs(PrefRegistrySyncable* registry) {
  registry->RegisterStringPref(prefs::kProfileCreatedByVersion,
                               "1.0.0.0",
                               PrefRegistrySyncable::UNSYNCABLE_PREF);
}

// static
void ChromeVersionService::SetVersion(PrefService* prefs,
                                      const std::string& version) {
  prefs->SetString(prefs::kProfileCreatedByVersion, version);
}

// static
std::string ChromeVersionService::GetVersion(PrefService* prefs) {
  return prefs->GetString(prefs::kProfileCreatedByVersion);
}

// static
void ChromeVersionService::OnProfileLoaded(PrefService* prefs,
                                           bool is_new_profile) {
  // Obtain the Chrome version info.
  chrome::VersionInfo version_info;

  // If this is a new profile set version to current version, otherwise
  // (pre-existing profile), leave pref at default value (1.0.0.0) to
  // avoid any first-run behavior.
  std::string version = version_info.Version();
  if (prefs->FindPreference(prefs::kProfileCreatedByVersion)->
      IsDefaultValue() && is_new_profile) {
    SetVersion(prefs, version);
  }
}