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

Unified Diff: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc

Issue 408013003: Move device requisition to EnterpriseEnrollmentHandlerChromeOS. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/policy/enrollment_handler_chromeos.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
diff --git a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
index 67728038e73c5d549a43c0c26adb7d6aeaac673a..d731e00e6c2705114852f3dca778661702f6a5de 100644
--- a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
+++ b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
@@ -8,14 +8,19 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
+#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
+#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h"
+#include "chromeos/system/statistics_provider.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/http/http_status_code.h"
@@ -37,9 +42,28 @@ const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes.
// testing DMServer implementations.
const char kTestingRobotToken[] = "test-token";
+// Device requisition constants.
+const char kNoRequisition[] = "none";
+const char kRemoraRequisition[] = "remora";
+const char kSharkRequisition[] = "shark";
+
+
+// Gets a machine flag from StatisticsProvider, returns the given
+// |default_value| if not present.
+bool GetMachineFlag(const std::string& key, bool default_value) {
+ bool value = default_value;
+ chromeos::system::StatisticsProvider* provider =
+ chromeos::system::StatisticsProvider::GetInstance();
+ if (!provider->GetMachineFlag(key, &value))
+ return default_value;
+
+ return value;
+}
+
} // namespace
EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
+ PrefService* local_state,
DeviceCloudPolicyStoreChromeOS* store,
EnterpriseInstallAttributes* install_attributes,
ServerBackedStateKeysBroker* state_keys_broker,
@@ -48,10 +72,10 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
const std::string& auth_token,
const std::string& client_id,
bool is_auto_enrollment,
- const std::string& requisition,
const AllowedDeviceModes& allowed_device_modes,
const EnrollmentCallback& completion_callback)
- : store_(store),
+ : local_state_(local_state),
+ store_(store),
install_attributes_(install_attributes),
state_keys_broker_(state_keys_broker),
client_(client.Pass()),
@@ -59,7 +83,6 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
auth_token_(auth_token),
client_id_(client_id),
is_auto_enrollment_(is_auto_enrollment),
- requisition_(requisition),
allowed_device_modes_(allowed_device_modes),
completion_callback_(completion_callback),
device_mode_(DEVICE_MODE_NOT_SET),
@@ -68,6 +91,7 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
weak_ptr_factory_(this) {
CHECK(!client_->is_registered());
CHECK_EQ(DM_STATUS_SUCCESS, client_->status());
+ InitializeRequisition();
store_->AddObserver(this);
client_->AddObserver(this);
client_->AddNamespaceToFetch(PolicyNamespaceKey(
@@ -219,7 +243,7 @@ void EnrollmentHandlerChromeOS::AttemptRegistration() {
enrollment_step_ = STEP_REGISTRATION;
client_->Register(em::DeviceRegisterRequest::DEVICE,
auth_token_, client_id_, is_auto_enrollment_,
- requisition_, current_state_key_);
+ GetDeviceRequisition(), current_state_key_);
}
}
@@ -415,4 +439,91 @@ void EnrollmentHandlerChromeOS::ReportResult(EnrollmentStatus status) {
callback.Run(status);
}
+// static
+void EnrollmentHandlerChromeOS::RegisterPrefs(
+ PrefRegistrySimple* registry) {
+ registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition,
+ std::string());
+ registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false);
+ registry->RegisterBooleanPref(prefs::kDeviceEnrollmentCanExit, true);
+ registry->RegisterDictionaryPref(prefs::kServerBackedDeviceState);
+}
+
+void Foo(PersistentPrefStore::PrefReadError) {}
+
+void EnrollmentHandlerChromeOS::InitializeRequisition() {
+ // OEM statistics are only loaded when OOBE is not completed.
+ if (chromeos::StartupUtils::IsOobeCompleted())
+ return;
+
+ const PrefService::Preference* pref = local_state_->FindPreference(
+ prefs::kDeviceEnrollmentRequisition);
+ if (pref->IsDefaultValue()) {
+ std::string requisition;
+ chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic(
+ chromeos::system::kOemDeviceRequisitionKey, &requisition);
+
+ if (!requisition.empty()) {
+ local_state_->SetString(prefs::kDeviceEnrollmentRequisition,
+ requisition);
+ if (requisition == kRemoraRequisition ||
+ requisition == kSharkRequisition) {
+ local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true);
+ local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false);
+ } else {
+ local_state_->SetBoolean(
+ prefs::kDeviceEnrollmentAutoStart,
+ GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey,
+ false));
+ local_state_->SetBoolean(
+ prefs::kDeviceEnrollmentCanExit,
+ GetMachineFlag(chromeos::system::kOemCanExitEnterpriseEnrollmentKey,
+ false));
+ }
+ }
+ }
+}
+
+std::string EnrollmentHandlerChromeOS::GetDeviceRequisition() const {
+ std::string requisition;
+ const PrefService::Preference* pref = local_state_->FindPreference(
+ prefs::kDeviceEnrollmentRequisition);
+ if (!pref->IsDefaultValue())
+ pref->GetValue()->GetAsString(&requisition);
+
+ if (requisition == kNoRequisition)
+ requisition.clear();
+
+ return requisition;
+}
+
+void EnrollmentHandlerChromeOS::SetDeviceRequisition(
+ const std::string& requisition) {
+ VLOG(1) << "SetDeviceRequisition " << requisition;
+ if (local_state_) {
+ if (requisition.empty()) {
+ local_state_->ClearPref(prefs::kDeviceEnrollmentRequisition);
+ local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart);
+ local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit);
+ } else {
+ local_state_->SetString(prefs::kDeviceEnrollmentRequisition, requisition);
+ if (requisition == kNoRequisition) {
+ local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart);
+ local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit);
+ } else {
+ local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true);
+ local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false);
+ }
+ }
+ }
+}
+
+bool EnrollmentHandlerChromeOS::IsRemoraRequisition() const {
+ return GetDeviceRequisition() == kRemoraRequisition;
+}
+
+bool EnrollmentHandlerChromeOS::IsSharkRequisition() const {
+ return GetDeviceRequisition() == kSharkRequisition;
+}
+
} // namespace policy
« no previous file with comments | « chrome/browser/chromeos/policy/enrollment_handler_chromeos.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698