Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/installer/setup/update_active_setup_version_work_item.cc

Issue 1223953003: Introduce UpdateActiveSetupVersionWorkItem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a1_active_setup_onosup_addCB_API
Patch Set: merge to r338517 add GN support for setup_unittests Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/installer/setup/update_active_setup_version_work_item.h"
6
7 #include <stdint.h>
8
9 #include <vector>
10
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"
16
17 namespace {
18
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";
24
25 } // namespace
26
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) {
39 }
40
41 bool UpdateActiveSetupVersionWorkItem::Do() {
42 return set_reg_value_work_item_.Do();
43 }
44
45 void UpdateActiveSetupVersionWorkItem::Rollback() {
46 set_reg_value_work_item_.Rollback();
47 }
48
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);
53
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");
58
59 // Unconditionally update the major version.
60 version_components[MAJOR] = kActiveSetupMajorVersion;
61
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;
68 }
69 version_components[OS_UPGRADES] = base::UintToString16(previous_value + 1);
70 }
71
72 return JoinString(version_components, L',');
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698