• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_
6 #define CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/policy/cloud_policy_identity_strategy.h"
13 
14 class TokenService;
15 
16 namespace policy {
17 
18 // DM token provider that stores the token in CrOS signed settings.
19 class DevicePolicyIdentityStrategy : public CloudPolicyIdentityStrategy {
20  public:
21   DevicePolicyIdentityStrategy();
22   virtual ~DevicePolicyIdentityStrategy();
23 
24   // Sets (GAIA) auth credentials of the owner of the device during device
25   // enrollment. This automatically triggers fetching a DMToken that can
26   // be used for future authentication with DMServer.
27   void SetAuthCredentials(const std::string& username,
28                           const std::string& auth_token);
29 
30   // Sets the device's credentials when they have been read from disk after
31   // a reboot.
32   void SetDeviceManagementCredentials(const std::string& owner_email,
33                                       const std::string& device_id,
34                                       const std::string& device_token);
35 
36   // Initiates a policy fetch after a successful device registration. This
37   // function should be called only after the device token has been fetched
38   // either through the DMServer or loaded from the cache.
39   void FetchPolicy();
40 
41   // CloudPolicyIdentityStrategy implementation:
42   virtual std::string GetDeviceToken() OVERRIDE;
43   virtual std::string GetDeviceID() OVERRIDE;
44   virtual std::string GetMachineID() OVERRIDE;
45   virtual std::string GetMachineModel() OVERRIDE;
46   virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType() OVERRIDE;
47   virtual std::string GetPolicyType() OVERRIDE;
48   virtual bool GetCredentials(std::string* username,
49                               std::string* auth_token) OVERRIDE;
50   virtual void OnDeviceTokenAvailable(const std::string& token) OVERRIDE;
51 
52  private:
53   // The e-mail and auth token of the device owner. Set by |SetCredentials()|.
54   std::string username_;
55   std::string auth_token_;
56 
57   // The machine identifier and model.
58   std::string machine_id_;
59   std::string machine_model_;
60 
61   // The device identifier to be sent with requests. (This is actually more like
62   // a session identifier since it is re-generated for each registration
63   // request.)
64   std::string device_id_;
65 
66   // Current token. Empty if not available.
67   std::string device_token_;
68 
69   DISALLOW_COPY_AND_ASSIGN(DevicePolicyIdentityStrategy);
70 };
71 
72 }  // namespace policy
73 
74 #endif  // CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_
75