Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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/browser/chromeos/legacy_retail_mode_detector.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 12 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 14 #include "chromeos/chromeos_switches.h" | |
| 15 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 | |
| 20 namespace { | |
| 21 const int kDeviceModeFetchRetryDelayMs = 200; | |
| 22 } | |
| 23 | |
| 24 static base::LazyInstance<LegacyRetailModeDetector> g_kiosk_mode_settings = | |
| 25 LAZY_INSTANCE_INITIALIZER; | |
| 26 | |
| 27 // static | |
| 28 LegacyRetailModeDetector* LegacyRetailModeDetector::Get() { | |
| 29 return g_kiosk_mode_settings.Pointer(); | |
| 30 } | |
| 31 | |
| 32 bool LegacyRetailModeDetector::IsKioskModeEnabled() { | |
| 33 return is_kiosk_mode_; | |
| 34 } | |
| 35 | |
| 36 LegacyRetailModeDetector::LegacyRetailModeDetector() { | |
| 37 // In case we've force-enabled kiosk mode. | |
| 38 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableKioskMode)) { | |
| 39 is_kiosk_mode_ = true; | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 // Precache the value as we know it at construction time to avoid serving | |
| 44 // different values to different users. | |
| 45 if (g_browser_process) { | |
| 46 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 47 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 48 policy::DeviceMode device_mode = connector->GetDeviceMode(); | |
| 49 if (device_mode == policy::DEVICE_MODE_LEGACY_RETAIL_MODE) { | |
| 50 is_kiosk_mode_ = true; | |
| 51 return; | |
| 52 } else if (device_mode == policy::DEVICE_MODE_PENDING) { | |
|
bartfab (slow)
2014/11/27 16:25:47
Handling policy::DEVICE_MODE_PENDING is unnecessar
rkc
2014/12/01 19:15:04
Acknowledged.
| |
| 53 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | |
| 54 base::Bind(&LegacyRetailModeDetector::VerifyModeIsKnown, | |
| 55 base::Unretained(this))); | |
| 56 } | |
| 57 } | |
| 58 is_kiosk_mode_ = false; | |
| 59 } | |
| 60 | |
| 61 LegacyRetailModeDetector::~LegacyRetailModeDetector() { | |
| 62 } | |
| 63 | |
| 64 void LegacyRetailModeDetector::VerifyModeIsKnown( | |
| 65 DeviceSettingsService::OwnershipStatus status) { | |
| 66 if (status != DeviceSettingsService::OWNERSHIP_TAKEN) | |
| 67 return; | |
| 68 | |
| 69 if (g_browser_process) { | |
| 70 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 71 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 72 policy::DeviceMode device_mode = connector->GetDeviceMode(); | |
| 73 // We retry asking for the mode until it becomes known. | |
| 74 switch (device_mode) { | |
| 75 case policy::DEVICE_MODE_PENDING: | |
| 76 content::BrowserThread::PostDelayedTask( | |
| 77 content::BrowserThread::UI, FROM_HERE, | |
| 78 base::Bind(&LegacyRetailModeDetector::VerifyModeIsKnown, | |
| 79 base::Unretained(this), status), | |
| 80 base::TimeDelta::FromMilliseconds(kDeviceModeFetchRetryDelayMs)); | |
| 81 break; | |
| 82 case policy::DEVICE_MODE_LEGACY_RETAIL_MODE: | |
| 83 chrome::AttemptRestart(); | |
| 84 break; | |
| 85 default: | |
| 86 break; | |
| 87 } | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 } // namespace chromeos | |
| OLD | NEW |