Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / login / enrollment / enterprise_enrollment_helper_impl.h
blob6a195ffcaaac3279304549be7c4c7340d3fb4281
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENTERPRISE_ENROLLMENT_HELPER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENTERPRISE_ENROLLMENT_HELPER_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper.h"
16 #include "chrome/browser/chromeos/policy/enrollment_config.h"
17 #include "components/policy/core/common/cloud/enterprise_metrics.h"
18 #include "google_apis/gaia/google_service_auth_error.h"
20 class Profile;
22 namespace policy {
23 class PolicyOAuth2TokenFetcher;
26 namespace chromeos {
28 class EnterpriseEnrollmentHelperImpl : public EnterpriseEnrollmentHelper {
29 public:
30 EnterpriseEnrollmentHelperImpl(
31 EnrollmentStatusConsumer* status_consumer,
32 const policy::EnrollmentConfig& enrollment_config,
33 const std::string& enrolling_user_domain);
34 ~EnterpriseEnrollmentHelperImpl() override;
36 // Overridden from EnterpriseEnrollmentHelper:
37 void EnrollUsingAuthCode(const std::string& auth_code,
38 bool fetch_additional_token) override;
39 void EnrollUsingToken(const std::string& token) override;
40 void ClearAuth(const base::Closure& callback) override;
41 void GetDeviceAttributeUpdatePermission() override;
42 void UpdateDeviceAttributes(const std::string& asset_id,
43 const std::string& location) override;
45 private:
46 void DoEnrollUsingToken(const std::string& token);
48 // Handles completion of the OAuth2 token fetch attempt.
49 void OnTokenFetched(bool is_additional_token,
50 const std::string& token,
51 const GoogleServiceAuthError& error);
53 // Handles completion of the enrollment attempt.
54 void OnEnrollmentFinished(policy::EnrollmentStatus status);
56 // Handles completion of the device attribute update permission request.
57 void OnDeviceAttributeUpdatePermission(bool granted);
59 // Handles completion of the device attribute update attempt.
60 void OnDeviceAttributeUploadCompleted(bool success);
62 void ReportAuthStatus(const GoogleServiceAuthError& error);
63 void ReportEnrollmentStatus(policy::EnrollmentStatus status);
65 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
66 // histogram, depending on |enrollment_mode_|.
67 void UMA(policy::MetricEnrollment sample);
69 // Called by ProfileHelper when a signin profile clearance has finished.
70 // |callback| is a callback, that was passed to ClearAuth() before.
71 void OnSigninProfileCleared(const base::Closure& callback);
73 const policy::EnrollmentConfig enrollment_config_;
74 const std::string enrolling_user_domain_;
75 bool fetch_additional_token_;
77 bool started_;
78 std::string additional_token_;
79 bool finished_;
80 bool success_;
81 bool auth_data_cleared_;
82 std::string oauth_token_;
84 scoped_ptr<policy::PolicyOAuth2TokenFetcher> oauth_fetcher_;
86 base::WeakPtrFactory<EnterpriseEnrollmentHelperImpl> weak_ptr_factory_;
88 DISALLOW_COPY_AND_ASSIGN(EnterpriseEnrollmentHelperImpl);
91 } // namespace chromeos
93 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENTERPRISE_ENROLLMENT_HELPER_IMPL_H_