device_local_account.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_H_
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_H_
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <vector>
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace chromeos {
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CrosSettings;
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace policy {
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// This must match DeviceLocalAccountInfoProto.AccountType in
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// chrome_device_policy.proto.
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct DeviceLocalAccount {
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  enum Type {
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // A login-less, policy-configured browsing session.
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    TYPE_PUBLIC_SESSION,
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // An account that serves as a container for a single full-screen app.
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    TYPE_KIOSK_APP,
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    // Sentinel, must be last.
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    TYPE_COUNT
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  };
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DeviceLocalAccount(Type type,
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                     const std::string& account_id,
31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                     const std::string& kiosk_app_id);
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ~DeviceLocalAccount();
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  Type type;
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // A device-local account has two identifiers:
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // * The |account_id| is chosen by the entity that defines the device-local
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //   account. The only constraints are that the |account_id| be unique and,
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //   for legacy reasons, it contain an @ symbol.
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // * The |user_id| is a synthesized identifier that is guaranteed to be
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //   unique, contain an @ symbol, not collide with the |user_id| of any other
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //   user on the device (such as regular users or supervised users) and be
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  //   identifiable as belonging to a device-local account by.
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // The |account_id| is primarily used by policy code: If device policy defines
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // a device-local account with a certain |account_id|, the user policy for
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // that account has to be fetched by referencing the same |account_id|.
468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // The |user_id| is passed to the chromeos::UserManager where it becomes part
478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // of the global user list on the device. The |account_id| would not be safe
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // to use here as it is a free-form identifier that could conflict with
498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // another |user_id| on the device and cannot be easily identified as
508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // belonging to a device-local account.
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string account_id;
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string user_id;
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string kiosk_app_id;
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)std::string GenerateDeviceLocalAccountUserId(const std::string& account_id,
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                             DeviceLocalAccount::Type type);
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Determines whether |user_id| belongs to a device-local account and if so,
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// returns the type of device-local account in |type| unless |type| is NULL.
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool IsDeviceLocalAccountUser(const std::string& user_id,
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                              DeviceLocalAccount::Type* type);
6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Stores a list of device-local accounts in |cros_settings|. The accounts are
6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// stored as a list of dictionaries with each dictionary containing the
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// information about one |DeviceLocalAccount|.
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void SetDeviceLocalAccounts(
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    chromeos::CrosSettings* cros_settings,
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const std::vector<DeviceLocalAccount>& accounts);
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Retrieves a list of device-local accounts from |cros_settings|.
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)std::vector<DeviceLocalAccount> GetDeviceLocalAccounts(
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    chromeos::CrosSettings* cros_settings);
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace policy
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_H_
78