OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/chromeos/login/enrollment/auto_enrollment_controller.h" | 5 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 if (int_value > policy::AutoEnrollmentClient::kMaximumPower) { | 49 if (int_value > policy::AutoEnrollmentClient::kMaximumPower) { |
50 LOG(ERROR) << "Switch \"" << switch_name << "\" can't be greater than " | 50 LOG(ERROR) << "Switch \"" << switch_name << "\" can't be greater than " |
51 << policy::AutoEnrollmentClient::kMaximumPower << ". Using " | 51 << policy::AutoEnrollmentClient::kMaximumPower << ". Using " |
52 << policy::AutoEnrollmentClient::kMaximumPower; | 52 << policy::AutoEnrollmentClient::kMaximumPower; |
53 return policy::AutoEnrollmentClient::kMaximumPower; | 53 return policy::AutoEnrollmentClient::kMaximumPower; |
54 } | 54 } |
55 return int_value; | 55 return int_value; |
56 } | 56 } |
57 | 57 |
58 // Returns whether the auto-enrollment check is required. When | |
59 // kCheckEnrollmentKey VPD entry is present, it is explicitly stating whether | |
60 // the forced re-enrollment is required or not. Otherwise, for backward | |
61 // compatibility with devices upgrading from an older version of Chrome OS, the | |
62 // kActivateDateKey VPD entry is queried. If it's missing, FRE is not required. | |
63 // This enables factories to start full guest sessions for testing, see | |
64 // http://crbug.com/397354 for more context. The requirement for the machine | |
65 // serial number to be present is a sanity-check to ensure that the VPD has | |
66 // actually been read successfully. If VPD read failed, the FRE check is | |
67 // required. | |
68 AutoEnrollmentController::FRERequirement GetFRERequirement() { | |
69 std::string check_enrollment_value; | |
70 system::StatisticsProvider* provider = | |
71 system::StatisticsProvider::GetInstance(); | |
72 bool fre_flag_found = provider->GetMachineStatistic( | |
73 system::kCheckEnrollmentKey, &check_enrollment_value); | |
74 | |
75 if (fre_flag_found) { | |
76 if (check_enrollment_value == "0") | |
77 return AutoEnrollmentController::EXPLICITLY_NOT_REQUIRED; | |
78 if (check_enrollment_value == "1") | |
79 return AutoEnrollmentController::EXPLICITLY_REQUIRED; | |
80 } | |
81 if (!provider->GetMachineStatistic(system::kActivateDateKey, nullptr) && | |
82 !provider->GetEnterpriseMachineID().empty()) { | |
83 return AutoEnrollmentController::NOT_REQUIRED; | |
84 } | |
85 return AutoEnrollmentController::REQUIRED; | |
86 } | |
87 | |
88 std::string FRERequirementToString( | 58 std::string FRERequirementToString( |
89 AutoEnrollmentController::FRERequirement requirement) { | 59 AutoEnrollmentController::FRERequirement requirement) { |
90 switch (requirement) { | 60 switch (requirement) { |
91 case AutoEnrollmentController::REQUIRED: | 61 case AutoEnrollmentController::REQUIRED: |
92 return "Auto-enrollment required."; | 62 return "Auto-enrollment required."; |
93 case AutoEnrollmentController::NOT_REQUIRED: | 63 case AutoEnrollmentController::NOT_REQUIRED: |
94 return "Auto-enrollment disabled: first setup."; | 64 return "Auto-enrollment disabled: first setup."; |
95 case AutoEnrollmentController::EXPLICITLY_REQUIRED: | 65 case AutoEnrollmentController::EXPLICITLY_REQUIRED: |
96 return "Auto-enrollment required: flag in VPD."; | 66 return "Auto-enrollment required: flag in VPD."; |
97 case AutoEnrollmentController::EXPLICITLY_NOT_REQUIRED: | 67 case AutoEnrollmentController::EXPLICITLY_NOT_REQUIRED: |
98 return "Auto-enrollment disabled: flag in VPD."; | 68 return "Auto-enrollment disabled: flag in VPD."; |
99 } | 69 } |
100 | 70 |
101 NOTREACHED(); | 71 NOTREACHED(); |
102 return std::string(); | 72 return std::string(); |
103 } | 73 } |
104 | 74 |
105 } // namespace | 75 } // namespace |
106 | 76 |
107 const char AutoEnrollmentController::kForcedReEnrollmentAlways[] = "always"; | 77 const char AutoEnrollmentController::kForcedReEnrollmentAlways[] = "always"; |
108 const char AutoEnrollmentController::kForcedReEnrollmentNever[] = "never"; | 78 const char AutoEnrollmentController::kForcedReEnrollmentNever[] = "never"; |
109 const char AutoEnrollmentController::kForcedReEnrollmentOfficialBuild[] = | 79 const char AutoEnrollmentController::kForcedReEnrollmentOfficialBuild[] = |
110 "official"; | 80 "official"; |
111 | 81 |
| 82 // static |
112 AutoEnrollmentController::Mode AutoEnrollmentController::GetMode() { | 83 AutoEnrollmentController::Mode AutoEnrollmentController::GetMode() { |
113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 84 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
114 | 85 |
115 std::string command_line_mode = command_line->GetSwitchValueASCII( | 86 std::string command_line_mode = command_line->GetSwitchValueASCII( |
116 switches::kEnterpriseEnableForcedReEnrollment); | 87 switches::kEnterpriseEnableForcedReEnrollment); |
117 if (command_line_mode == kForcedReEnrollmentAlways) { | 88 if (command_line_mode == kForcedReEnrollmentAlways) { |
118 return MODE_FORCED_RE_ENROLLMENT; | 89 return MODE_FORCED_RE_ENROLLMENT; |
119 } else if (command_line_mode.empty() || | 90 } else if (command_line_mode.empty() || |
120 command_line_mode == kForcedReEnrollmentOfficialBuild) { | 91 command_line_mode == kForcedReEnrollmentOfficialBuild) { |
121 #if defined(OFFICIAL_BUILD) | 92 #if defined(OFFICIAL_BUILD) |
122 std::string firmware_type; | 93 std::string firmware_type; |
123 const bool non_chrome_firmware = | 94 const bool non_chrome_firmware = |
124 system::StatisticsProvider::GetInstance()->GetMachineStatistic( | 95 system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
125 system::kFirmwareTypeKey, &firmware_type) && | 96 system::kFirmwareTypeKey, &firmware_type) && |
126 firmware_type == system::kFirmwareTypeValueNonchrome; | 97 firmware_type == system::kFirmwareTypeValueNonchrome; |
127 return non_chrome_firmware ? MODE_NONE : MODE_FORCED_RE_ENROLLMENT; | 98 return non_chrome_firmware ? MODE_NONE : MODE_FORCED_RE_ENROLLMENT; |
128 #else | 99 #else |
129 return MODE_NONE; | 100 return MODE_NONE; |
130 #endif | 101 #endif |
131 } else if (command_line_mode == kForcedReEnrollmentNever) { | 102 } else if (command_line_mode == kForcedReEnrollmentNever) { |
132 return MODE_NONE; | 103 return MODE_NONE; |
133 } | 104 } |
134 | 105 |
135 LOG(FATAL) << "Unknown auto-enrollment mode " << command_line_mode; | 106 LOG(FATAL) << "Unknown auto-enrollment mode " << command_line_mode; |
136 return MODE_NONE; | 107 return MODE_NONE; |
137 } | 108 } |
138 | 109 |
| 110 // static |
| 111 AutoEnrollmentController::FRERequirement |
| 112 AutoEnrollmentController::GetFRERequirement() { |
| 113 std::string check_enrollment_value; |
| 114 system::StatisticsProvider* provider = |
| 115 system::StatisticsProvider::GetInstance(); |
| 116 bool fre_flag_found = provider->GetMachineStatistic( |
| 117 system::kCheckEnrollmentKey, &check_enrollment_value); |
| 118 |
| 119 if (fre_flag_found) { |
| 120 if (check_enrollment_value == "0") |
| 121 return AutoEnrollmentController::EXPLICITLY_NOT_REQUIRED; |
| 122 if (check_enrollment_value == "1") |
| 123 return AutoEnrollmentController::EXPLICITLY_REQUIRED; |
| 124 } |
| 125 if (!provider->GetMachineStatistic(system::kActivateDateKey, nullptr) && |
| 126 !provider->GetEnterpriseMachineID().empty()) { |
| 127 return AutoEnrollmentController::NOT_REQUIRED; |
| 128 } |
| 129 return AutoEnrollmentController::REQUIRED; |
| 130 } |
| 131 |
139 AutoEnrollmentController::AutoEnrollmentController() {} | 132 AutoEnrollmentController::AutoEnrollmentController() {} |
140 | 133 |
141 AutoEnrollmentController::~AutoEnrollmentController() {} | 134 AutoEnrollmentController::~AutoEnrollmentController() {} |
142 | 135 |
143 void AutoEnrollmentController::Start() { | 136 void AutoEnrollmentController::Start() { |
144 switch (state_) { | 137 switch (state_) { |
145 case policy::AUTO_ENROLLMENT_STATE_PENDING: | 138 case policy::AUTO_ENROLLMENT_STATE_PENDING: |
146 // Abort re-start if the check is still running. | 139 // Abort re-start if the check is still running. |
147 return; | 140 return; |
148 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | 141 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Cancelling the |client_| allows it to determine whether | 344 // Cancelling the |client_| allows it to determine whether |
352 // its protocol finished before login was complete. | 345 // its protocol finished before login was complete. |
353 client_.release()->CancelAndDeleteSoon(); | 346 client_.release()->CancelAndDeleteSoon(); |
354 } | 347 } |
355 | 348 |
356 // Make sure to nuke pending |client_| start sequences. | 349 // Make sure to nuke pending |client_| start sequences. |
357 client_start_weak_factory_.InvalidateWeakPtrs(); | 350 client_start_weak_factory_.InvalidateWeakPtrs(); |
358 } | 351 } |
359 | 352 |
360 } // namespace chromeos | 353 } // namespace chromeos |
OLD | NEW |