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

Side by Side Diff: common/oem_install_utils.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « common/oem_install_utils.h ('k') | common/oem_install_utils_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2007-2010 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15 //
16 //
17 // *** Documentation for OEM Installs ***
18 //
19 // A /oem install requires:
20 // * Per-machine install
21 // * Running as admin
22 // * Running in Windows audit mode (ConfigManager::IsWindowsInstalling())
23 // * Offline installer (determined in LaunchHandoffProcess())
24 //
25 // If the first three conditions are met, SetOemInstallState() writes the
26 // OemInstallTime registry value, which is used by IsOemInstalling() along with
27 // other logic to determine whether Omaha is running in an OEM install
28 // environment. Other objects use IsOemInstalling() - not
29 // ConfigureManager::IsWindowsInstalling() - to determine whether to run in a
30 // disabled mode for OEM factory installations. For example, the core exits
31 // immediately without checking for updates or Code Red events, no instances
32 // ping, and persistent IDs are not saved.
33
34 #include "omaha/common/oem_install_utils.h"
35 #include "omaha/base/debug.h"
36 #include "omaha/base/error.h"
37 #include "omaha/base/logging.h"
38 #include "omaha/base/reg_key.h"
39 #include "omaha/base/time.h"
40 #include "omaha/base/vistautil.h"
41 #include "omaha/common/config_manager.h"
42 #include "omaha/common/const_goopdate.h"
43 #include "omaha/common/goopdate_utils.h"
44
45 namespace omaha {
46
47 namespace oem_install_utils {
48
49 HRESULT SetOemInstallState(bool is_machine) {
50 bool is_windows_installing = ConfigManager::Instance()->IsWindowsInstalling();
51 if (!is_machine || !vista_util::IsUserAdmin() || !is_windows_installing) {
52 return GOOPDATE_E_OEM_NOT_MACHINE_AND_PRIVILEGED_AND_AUDIT_MODE;
53 }
54
55 const DWORD now = Time64ToInt32(GetCurrent100NSTime());
56
57 OPT_LOG(L1, (_T("[Beginning OEM install][%u]"), now));
58
59 goopdate_utils::DeleteUserId(is_machine);
60
61 return RegKey::SetValue(
62 ConfigManager::Instance()->machine_registry_update(),
63 kRegValueOemInstallTimeSec,
64 now);
65 }
66
67 HRESULT ResetOemInstallState(bool is_machine) {
68 if (!is_machine) {
69 return E_INVALIDARG;
70 }
71
72 OPT_LOG(L1, (_T("[Reset OEM install state][%u]"),
73 Time64ToInt32(GetCurrent100NSTime())));
74
75 HRESULT hr = RegKey::DeleteValue(
76 ConfigManager::Instance()->machine_registry_update(),
77 kRegValueOemInstallTimeSec);
78
79 return hr;
80 }
81
82 // Always returns false if !is_machine. This prevents ever blocking per-user
83 // instances.
84 // Returns true if OEM install time is present and it has been less than
85 // kMinOemModeSec since the OEM install.
86 // Non-OEM installs can never be blocked from updating because OEM install time
87 // will not be present.
88 bool IsOemInstalling(bool is_machine) {
89 if (!is_machine) {
90 return false;
91 }
92
93 DWORD oem_install_time_seconds = 0;
94 if (FAILED(RegKey::GetValue(MACHINE_REG_UPDATE,
95 kRegValueOemInstallTimeSec,
96 &oem_install_time_seconds))) {
97 CORE_LOG(L3, (_T("[IsOemInstalling][OemInstallTime not found]")));
98 return false;
99 }
100
101 const uint32 now_seconds = Time64ToInt32(GetCurrent100NSTime());
102 if (now_seconds < oem_install_time_seconds) {
103 CORE_LOG(LW, (_T("[possible time warp detected][now %u][last checked %u]"),
104 now_seconds, oem_install_time_seconds));
105 }
106 const int time_difference_seconds =
107 abs(static_cast<int>(now_seconds - oem_install_time_seconds));
108
109 ASSERT1(0 <= time_difference_seconds);
110 const bool result = time_difference_seconds < kMinOemModeSec ? true : false;
111
112 CORE_LOG(L3, (_T("[now %u][OEM install time %u][time difference %u][%d]"),
113 now_seconds, oem_install_time_seconds, time_difference_seconds,
114 result));
115 return result;
116 }
117
118 } // namespace oem_install_utils
119
120 } // namespace omaha
OLDNEW
« no previous file with comments | « common/oem_install_utils.h ('k') | common/oem_install_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698