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_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover.h"
17 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper.h"
18 #include "chrome/browser/chromeos/policy/enrollment_config.h"
19 #include "components/policy/core/common/cloud/enterprise_metrics.h"
20 #include "google_apis/gaia/google_service_auth_error.h"
25 class PolicyOAuth2TokenFetcher
;
30 class EnterpriseEnrollmentHelperImpl
: public EnterpriseEnrollmentHelper
,
31 public BrowsingDataRemover::Observer
{
33 EnterpriseEnrollmentHelperImpl(
34 EnrollmentStatusConsumer
* status_consumer
,
35 const policy::EnrollmentConfig
& enrollment_config
,
36 const std::string
& enrolling_user_domain
);
37 ~EnterpriseEnrollmentHelperImpl() override
;
39 // Overridden from EnterpriseEnrollmentHelper:
40 void EnrollUsingProfile(Profile
* profile
,
41 bool fetch_additional_token
) override
;
42 void EnrollUsingToken(const std::string
& token
) override
;
43 void ClearAuth(const base::Closure
& callback
) override
;
46 void DoEnrollUsingToken(const std::string
& token
);
48 // Handles completion of the OAuth2 token fetch attempt.
49 void OnTokenFetched(size_t fetcher_index
,
50 const std::string
& token
,
51 const GoogleServiceAuthError
& error
);
53 // Handles completion of the enrollment attempt.
54 void OnEnrollmentFinished(policy::EnrollmentStatus status
);
56 void ReportAuthStatus(const GoogleServiceAuthError
& error
);
57 void ReportEnrollmentStatus(policy::EnrollmentStatus status
);
59 // Logs an UMA event in the kMetricEnrollment or the kMetricEnrollmentRecovery
60 // histogram, depending on |enrollment_mode_|.
61 void UMA(policy::MetricEnrollment sample
);
63 // Overridden from BrowsingDataRemover::Observer:
64 void OnBrowsingDataRemoverDone() override
;
66 const policy::EnrollmentConfig enrollment_config_
;
67 const std::string enrolling_user_domain_
;
69 bool fetch_additional_token_
;
72 size_t oauth_fetchers_finished_
;
73 GoogleServiceAuthError last_auth_error_
;
74 std::string additional_token_
;
77 bool auth_data_cleared_
;
79 // The browsing data remover instance currently active, if any.
80 BrowsingDataRemover
* browsing_data_remover_
;
82 // The callbacks to invoke after browsing data has been cleared.
83 std::vector
<base::Closure
> auth_clear_callbacks_
;
85 ScopedVector
<policy::PolicyOAuth2TokenFetcher
> oauth_fetchers_
;
87 base::WeakPtrFactory
<EnterpriseEnrollmentHelperImpl
> weak_ptr_factory_
;
89 DISALLOW_COPY_AND_ASSIGN(EnterpriseEnrollmentHelperImpl
);
92 } // namespace chromeos
94 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_ENTERPRISE_ENROLLMENT_HELPER_IMPL_H_