summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/device_policy_identity_strategy.h
blob: 365ed0f06dfcecc41ffe13dd63b7c63ae9c07d48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_
#define CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_
#pragma once

#include <string>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud_policy_identity_strategy.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"

class TokenService;

namespace policy {

// DM token provider that stores the token in CrOS signed settings.
class DevicePolicyIdentityStrategy : public CloudPolicyIdentityStrategy,
                                     public NotificationObserver {
 public:
  DevicePolicyIdentityStrategy();
  virtual ~DevicePolicyIdentityStrategy();

  // Called by DevicePolicyIdentityStrategy::OwnershipChecker:
  virtual void OnOwnershipInformationAvailable(bool current_user_is_owner);

  // CloudPolicyIdentityStrategy implementation:
  virtual std::string GetDeviceToken();
  virtual std::string GetDeviceID();
  virtual std::string GetMachineID();
  virtual em::DeviceRegisterRequest_Type GetPolicyRegisterType();
  virtual std::string GetPolicyType();
  virtual bool GetCredentials(std::string* username,
                              std::string* auth_token);
  virtual void OnDeviceTokenAvailable(const std::string& token);

 private:
  class OwnershipChecker;

  // Recheck whether all parameters are available and if so, trigger a
  // credentials changed notification.
  void CheckAndTriggerFetch();

  // Updates the ownership information and then passes control to
  // |CheckAndTriggerFetch|.
  void CheckOwnershipAndTriggerFetch();

  // NotificationObserver method overrides:
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // The machine identifier.
  std::string machine_id_;

  // The device identifier to be sent with requests. (This is actually more like
  // a session identifier since it is re-generated for each registration
  // request.)
  std::string device_id_;

  // Current token. Empty if not available.
  std::string device_token_;

  // Whether the currently logged in user is the device's owner. This variable
  // is owned by the UI thread but updated from the FILE thread. Therefore
  // after an owner login it will take some time before it turns to true.
  bool current_user_is_owner_;

  // Registers the provider for notification of successful Gaia logins.
  NotificationRegistrar registrar_;

  scoped_refptr<OwnershipChecker> ownership_checker_;

  // Allows to construct weak ptrs.
  base::WeakPtrFactory<DevicePolicyIdentityStrategy> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(DevicePolicyIdentityStrategy);
};

}  // namespace policy

#endif  // CHROME_BROWSER_POLICY_DEVICE_POLICY_IDENTITY_STRATEGY_H_