• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_STATUS_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_STATUS_CHROMEOS_H_
7 
8 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
9 #include "components/policy/core/common/cloud/cloud_policy_store.h"
10 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
11 
12 namespace policy {
13 
14 // Describes the result of an enrollment operation, including the relevant error
15 // codes received from the involved components.
16 class EnrollmentStatus {
17  public:
18   // Enrollment status codes.
19   enum Status {
20     STATUS_SUCCESS,                     // Enrollment succeeded.
21     STATUS_NO_STATE_KEYS,               // Server-backed state keys unavailable.
22     STATUS_REGISTRATION_FAILED,         // DM registration failed.
23     STATUS_REGISTRATION_BAD_MODE,       // Bad device mode.
24     STATUS_ROBOT_AUTH_FETCH_FAILED,     // API OAuth2 auth code failure.
25     STATUS_ROBOT_REFRESH_FETCH_FAILED,  // API OAuth2 refresh token failure.
26     STATUS_ROBOT_REFRESH_STORE_FAILED,  // Failed to store API OAuth2 token.
27     STATUS_POLICY_FETCH_FAILED,         // DM policy fetch failed.
28     STATUS_VALIDATION_FAILED,           // Policy validation failed.
29     STATUS_LOCK_ERROR,                  // Cryptohome failed to lock the device.
30     STATUS_LOCK_TIMEOUT,                // Timeout while waiting for the lock.
31     STATUS_LOCK_WRONG_USER,             // Locked to different domain.
32     STATUS_STORE_ERROR,                 // Failed to store the policy.
33     STATUS_STORE_TOKEN_AND_ID_FAILED,   // Failed to store DM token and device
34                                         // ID.
35   };
36 
37   // Helpers for constructing errors for relevant cases.
38   static EnrollmentStatus ForStatus(Status status);
39   static EnrollmentStatus ForRegistrationError(
40       DeviceManagementStatus client_status);
41   static EnrollmentStatus ForFetchError(DeviceManagementStatus client_status);
42   static EnrollmentStatus ForRobotAuthFetchError(
43       DeviceManagementStatus client_status);
44   static EnrollmentStatus ForRobotRefreshFetchError(int http_status);
45   static EnrollmentStatus ForValidationError(
46       CloudPolicyValidatorBase::Status validation_status);
47   static EnrollmentStatus ForStoreError(
48       CloudPolicyStore::Status store_error,
49       CloudPolicyValidatorBase::Status validation_status);
50 
status()51   Status status() const { return status_; }
client_status()52   DeviceManagementStatus client_status() const { return client_status_; }
http_status()53   int http_status() const { return http_status_; }
store_status()54   CloudPolicyStore::Status store_status() const { return store_status_; }
validation_status()55   CloudPolicyValidatorBase::Status validation_status() const {
56     return validation_status_;
57   }
58 
59  private:
60   EnrollmentStatus(Status status,
61                    DeviceManagementStatus client_status,
62                    int http_status,
63                    CloudPolicyStore::Status store_status,
64                    CloudPolicyValidatorBase::Status validation_status);
65 
66   Status status_;
67   DeviceManagementStatus client_status_;
68   int http_status_;
69   CloudPolicyStore::Status store_status_;
70   CloudPolicyValidatorBase::Status validation_status_;
71 };
72 
73 }  // namespace policy
74 
75 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_STATUS_CHROMEOS_H_
76