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

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

Issue 907323002: Implemented DeviceStatusCollector::GetDeviceSessionStatus() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge ToT Created 5 years, 10 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
Index: chrome/browser/chromeos/policy/device_status_collector.cc
diff --git a/chrome/browser/chromeos/policy/device_status_collector.cc b/chrome/browser/chromeos/policy/device_status_collector.cc
index 4057373232673aaad18937726a7f468463544187..1b602bc0bbf43c116b2ca5bd05b7d3a56f3753d8 100644
--- a/chrome/browser/chromeos/policy/device_status_collector.cc
+++ b/chrome/browser/chromeos/policy/device_status_collector.cc
@@ -25,7 +25,10 @@
#include "base/task_runner_util.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_local_account.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
@@ -40,6 +43,8 @@
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension.h"
#include "policy/proto/device_management_backend.pb.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
@@ -106,6 +111,30 @@ std::vector<em::VolumeInfo> GetVolumeInfo(
return result;
}
+// Returns the DeviceLocalAccount associated with the current kiosk session.
+// Returns null if there is no active kiosk session, or if that kiosk
+// session has been removed from policy since the session started, in which
+// case we won't report its status).
+scoped_ptr<policy::DeviceLocalAccount>
+GetCurrentKioskDeviceLocalAccount(chromeos::CrosSettings* settings) {
+ if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp())
+ return scoped_ptr<policy::DeviceLocalAccount>();
+ user_manager::User* const user =
bartfab (slow) 2015/02/16 13:30:33 Nit 1: #include "components/user_manager/user.h" N
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ user_manager::UserManager::Get()->GetActiveUser();
+ const std::string user_id = user->GetUserID();
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Isn't it already const?
+ const std::vector<policy::DeviceLocalAccount> accounts =
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 can't cast std::vector<policy::DeviceLocalAccount>
bartfab (slow) 2015/03/10 13:12:03 Sorry, the three "const" comments were dupes of co
+ policy::GetDeviceLocalAccounts(settings);
+
+ for (const auto& device_local_account : accounts) {
+ if (device_local_account.user_id == user_id) {
+ return make_scoped_ptr(
+ new policy::DeviceLocalAccount(device_local_account)).Pass();
+ }
+ }
+ LOG(WARNING) << "Kiosk app not found in list of device-local accounts";
+ return scoped_ptr<policy::DeviceLocalAccount>();
+}
+
} // namespace
namespace policy {
@@ -240,34 +269,35 @@ void DeviceStatusCollector::UpdateReportingSettings() {
// All reporting settings default to 'enabled'.
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceVersionInfo, &report_version_info_)) {
+ chromeos::kReportDeviceVersionInfo, &report_version_info_)) {
report_version_info_ = true;
}
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceActivityTimes, &report_activity_times_)) {
+ chromeos::kReportDeviceActivityTimes, &report_activity_times_)) {
report_activity_times_ = true;
}
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceBootMode, &report_boot_mode_)) {
+ chromeos::kReportDeviceBootMode, &report_boot_mode_)) {
report_boot_mode_ = true;
}
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_)) {
+ chromeos::kReportDeviceNetworkInterfaces,
+ &report_network_interfaces_)) {
report_network_interfaces_ = true;
}
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceUsers, &report_users_)) {
+ chromeos::kReportDeviceUsers, &report_users_)) {
report_users_ = true;
}
const bool already_reporting_hardware_status = report_hardware_status_;
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) {
+ chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) {
report_hardware_status_ = true;
}
if (!cros_settings_->GetBoolean(
- chromeos::kReportDeviceSessionStatus, &report_session_status_)) {
+ chromeos::kReportDeviceSessionStatus, &report_session_status_)) {
report_session_status_ = true;
}
@@ -389,10 +419,20 @@ void DeviceStatusCollector::IdleStateCallback(ui::IdleState state) {
last_idle_check_ = now;
}
-bool DeviceStatusCollector::IsAutoLaunchedKioskSession() {
- // TODO(atwilson): Determine if the currently active session is an
- // autolaunched kiosk session (http://crbug.com/452968).
- return false;
+scoped_ptr<DeviceLocalAccount>
+DeviceStatusCollector::GetAutoLaunchedKioskSessionInfo() {
+ scoped_ptr<DeviceLocalAccount> account =
+ GetCurrentKioskDeviceLocalAccount(cros_settings_);
+ if (account) {
+ chromeos::KioskAppManager::App current_app;
+ if (chromeos::KioskAppManager::Get()->GetApp(account->kiosk_app_id,
+ &current_app) &&
+ current_app.was_auto_launched_with_zero_delay) {
+ return account.Pass();
+ }
+ }
+ // No auto-launched kiosk session active.
+ return scoped_ptr<DeviceLocalAccount>();
}
void DeviceStatusCollector::SampleHardwareStatus() {
@@ -605,7 +645,7 @@ void DeviceStatusCollector::GetNetworkInterfaces(
}
// Don't write any network state if we aren't in a kiosk session.
- if (!IsAutoLaunchedKioskSession())
+ if (!GetAutoLaunchedKioskSessionInfo())
return;
// Walk the various networks and store their state in the status report.
@@ -701,9 +741,8 @@ bool DeviceStatusCollector::GetDeviceStatus(
if (report_network_interfaces_)
GetNetworkInterfaces(status);
- if (report_users_) {
+ if (report_users_)
GetUsers(status);
- }
if (report_hardware_status_)
GetHardwareStatus(status);
@@ -719,7 +758,42 @@ bool DeviceStatusCollector::GetDeviceStatus(
bool DeviceStatusCollector::GetDeviceSessionStatus(
em::SessionStatusReportRequest* status) {
- return false;
+ // Only generate session status reports if session status reporting is
+ // enabled, and we are in an auto-launched kiosk session.
bartfab (slow) 2015/02/16 13:30:33 Nit: You split the conditional into two. The comme
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ if (!report_session_status_)
+ return false;
+
+ scoped_ptr<DeviceLocalAccount> account = GetAutoLaunchedKioskSessionInfo();
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ if (!account)
+ return false;
+
+ // Get the account ID associated with this user.
+ status->set_device_local_account_id(account->account_id);
+ em::AppStatus* app_status = status->add_installed_apps();
+ app_status->set_app_id(account->kiosk_app_id);
+
+ // Look up the app and get the version.
+ const std::string app_version = GetAppVersion(account->kiosk_app_id);
+ if (app_version.empty()) {
+ DLOG(ERROR) << "Unable to get version for extension: "
+ << account->kiosk_app_id;
+ } else {
+ app_status->set_extension_version(app_version);
+ }
+ return true;
+}
+
+std::string DeviceStatusCollector::GetAppVersion(
+ const std::string& kiosk_app_id) {
+ Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ user_manager::UserManager::Get()->GetActiveUser());
+ extensions::ExtensionRegistry* registry =
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ extensions::ExtensionRegistry::Get(profile);
+ const extensions::Extension* extension = registry->GetExtensionById(
bartfab (slow) 2015/02/16 13:30:33 Nit: const.
Andrew T Wilson (Slow) 2015/02/17 10:57:25 Done.
+ kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING);
+ if (!extension)
+ return std::string();
+ return extension->VersionString();
}
void DeviceStatusCollector::OnSubmittedSuccessfully() {

Powered by Google App Engine
This is Rietveld 408576698