Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / installer / setup / update_active_setup_version_work_item.cc
blob7372675a6fe013ac72632f24f30df1dfb54cb1b4
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/installer/setup/update_active_setup_version_work_item.h"
7 #include <stdint.h>
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h"
17 namespace {
19 // The major version and first component of the version identifying the work
20 // done by setup.exe --configure-user-settings on user login by way of Active
21 // Setup. Increase this value if the work done when handling Active Setup
22 // should be executed again for all existing users.
23 const base::char16 kActiveSetupMajorVersion[] = L"43";
25 } // namespace
27 UpdateActiveSetupVersionWorkItem::UpdateActiveSetupVersionWorkItem(
28 const base::string16& active_setup_path,
29 Operation operation)
30 : set_reg_value_work_item_(
31 HKEY_LOCAL_MACHINE,
32 active_setup_path,
33 WorkItem::kWow64Default,
34 L"Version",
35 base::Bind(
36 &UpdateActiveSetupVersionWorkItem::GetUpdatedActiveSetupVersion,
37 base::Unretained(this))),
38 operation_(operation) {
41 bool UpdateActiveSetupVersionWorkItem::Do() {
42 return set_reg_value_work_item_.Do();
45 void UpdateActiveSetupVersionWorkItem::Rollback() {
46 set_reg_value_work_item_.Rollback();
49 base::string16 UpdateActiveSetupVersionWorkItem::GetUpdatedActiveSetupVersion(
50 const base::string16& existing_version) {
51 std::vector<base::string16> version_components = base::SplitString(
52 existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
54 // If |existing_version| was empty or otherwise corrupted, turn it into a
55 // valid one.
56 if (version_components.size() != 4U)
57 version_components.assign(4U, L"0");
59 // Unconditionally update the major version.
60 version_components[MAJOR] = kActiveSetupMajorVersion;
62 if (operation_ == UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT) {
63 uint32_t previous_value;
64 if (!base::StringToUint(version_components[OS_UPGRADES], &previous_value)) {
65 LOG(WARNING) << "Couldn't process previous OS_UPGRADES Active Setup "
66 "version component: " << version_components[OS_UPGRADES];
67 previous_value = 0;
69 version_components[OS_UPGRADES] = base::UintToString16(previous_value + 1);
72 return base::JoinString(version_components, L",");