OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/setup/update_active_setup_version_work_item.h" | 5 #include "chrome/installer/setup/update_active_setup_version_work_item.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // The major version and first component of the version identifying the work | 20 // 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 // 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 // Setup. Increase this value if the work done when handling Active Setup |
22 // should be executed again for all existing users. | 23 // should be executed again for all existing users. |
23 const base::char16 kActiveSetupMajorVersion[] = L"43"; | 24 #define ACTIVE_SETUP_MAJOR_VERSION 43 |
25 | |
26 #define AsChar16String2(m) L#m | |
27 #define AsChar16String(m) AsChar16String2(m) | |
gab
2017/05/23 16:07:06
?? How does that itoa?
grt (UTC plus 2)
2017/05/23 19:46:03
It creates a string literal containing the expansi
gab
2017/05/23 22:09:50
Interesting... how does that get the quotes in pla
grt (UTC plus 2)
2017/05/24 12:00:39
The # operator: http://en.cppreference.com/w/cpp/p
| |
28 | |
29 constexpr base::char16 kActiveSetupMajorVersion[] = | |
30 AsChar16String(ACTIVE_SETUP_MAJOR_VERSION); | |
31 | |
32 #undef AsString | |
33 #undef AsString2 | |
gab
2017/05/23 22:09:50
#undef is undefining wrong thing
grt (UTC plus 2)
2017/05/24 12:00:39
Ooops. Fixing in a followon CL.
| |
24 | 34 |
25 } // namespace | 35 } // namespace |
26 | 36 |
27 UpdateActiveSetupVersionWorkItem::UpdateActiveSetupVersionWorkItem( | 37 UpdateActiveSetupVersionWorkItem::UpdateActiveSetupVersionWorkItem( |
28 const base::string16& active_setup_path, | 38 const base::string16& active_setup_path, |
29 Operation operation) | 39 Operation operation) |
30 : set_reg_value_work_item_( | 40 : set_reg_value_work_item_( |
31 HKEY_LOCAL_MACHINE, | 41 HKEY_LOCAL_MACHINE, |
32 active_setup_path, | 42 active_setup_path, |
33 WorkItem::kWow64Default, | 43 WorkItem::kWow64Default, |
(...skipping 13 matching lines...) Expand all Loading... | |
47 void UpdateActiveSetupVersionWorkItem::RollbackImpl() { | 57 void UpdateActiveSetupVersionWorkItem::RollbackImpl() { |
48 set_reg_value_work_item_.Rollback(); | 58 set_reg_value_work_item_.Rollback(); |
49 } | 59 } |
50 | 60 |
51 base::string16 UpdateActiveSetupVersionWorkItem::GetUpdatedActiveSetupVersion( | 61 base::string16 UpdateActiveSetupVersionWorkItem::GetUpdatedActiveSetupVersion( |
52 const base::string16& existing_version) { | 62 const base::string16& existing_version) { |
53 std::vector<base::string16> version_components = base::SplitString( | 63 std::vector<base::string16> version_components = base::SplitString( |
54 existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 64 existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
55 | 65 |
56 // If |existing_version| was empty or otherwise corrupted, turn it into a | 66 // If |existing_version| was empty or otherwise corrupted, turn it into a |
57 // valid one. | 67 // valid one by extending with up to four zeros or truncating to only four |
68 // components. | |
58 if (version_components.size() != 4U) | 69 if (version_components.size() != 4U) |
59 version_components.assign(4U, L"0"); | 70 version_components.resize(4U, L"0"); |
71 | |
72 uint32_t previous_major; | |
73 if (!base::StringToUint(version_components[MAJOR], &previous_major)) | |
74 previous_major = 0; | |
60 | 75 |
61 // Unconditionally update the major version. | 76 // Unconditionally update the major version. |
62 version_components[MAJOR] = kActiveSetupMajorVersion; | 77 version_components[MAJOR] = kActiveSetupMajorVersion; |
63 | 78 |
64 if (operation_ == UPDATE_AND_BUMP_OS_UPGRADES_COMPONENT) { | 79 // Clear the other components if the major version increased. No extra work is |
80 // needed for UPDATE_AND_BUMP_SELECTIVE_TRIGGER in this case since all | |
81 // users will re-run active setup. | |
82 if (ACTIVE_SETUP_MAJOR_VERSION > previous_major) { | |
83 std::fill_n(++version_components.begin(), 3, base::string16(L"0")); | |
84 } else if (operation_ == UPDATE_AND_BUMP_SELECTIVE_TRIGGER) { | |
65 uint32_t previous_value; | 85 uint32_t previous_value; |
66 if (!base::StringToUint(version_components[OS_UPGRADES], &previous_value)) { | 86 if (!base::StringToUint(version_components[SELECTIVE_TRIGGER], |
67 LOG(WARNING) << "Couldn't process previous OS_UPGRADES Active Setup " | 87 &previous_value)) { |
68 "version component: " << version_components[OS_UPGRADES]; | 88 LOG(WARNING) << "Couldn't process previous SELECTIVE_TRIGGER Active " |
89 "Setup version component: " | |
90 << version_components[SELECTIVE_TRIGGER]; | |
69 previous_value = 0; | 91 previous_value = 0; |
70 } | 92 } |
71 version_components[OS_UPGRADES] = base::UintToString16(previous_value + 1); | 93 version_components[SELECTIVE_TRIGGER] = |
94 base::UintToString16(previous_value + 1); | |
72 } | 95 } |
73 | 96 |
74 return base::JoinString(version_components, L","); | 97 return base::JoinString(version_components, L","); |
75 } | 98 } |
OLD | NEW |