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_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
18 class ProfileOAuth2TokenService
;
22 class URLRequestContextGetter
;
27 class CloudPolicyClientRegistrationHelper
;
29 // A specialization of the UserPolicySigninServiceBase for the mobile platforms
30 // (currently Android and iOS).
31 class UserPolicySigninService
: public UserPolicySigninServiceBase
{
33 // Creates a UserPolicySigninService associated with the passed |profile|.
34 UserPolicySigninService(
36 PrefService
* local_state
,
37 DeviceManagementService
* device_management_service
,
38 UserCloudPolicyManager
* policy_manager
,
39 SigninManager
* signin_manager
,
40 scoped_refptr
<net::URLRequestContextGetter
> system_request_context
,
41 ProfileOAuth2TokenService
* token_service
);
42 ~UserPolicySigninService() override
;
44 // Registers a CloudPolicyClient for fetching policy for |username|.
45 // This requests an OAuth2 token for the services involved, and contacts
46 // the policy service if the account has management enabled.
47 // |account_id| is the obfuscated identitifcation of |username| to get OAuth2
49 // |callback| is invoked once we have registered this device to fetch policy,
50 // or once it is determined that |username| is not a managed account.
51 void RegisterForPolicy(const std::string
& username
,
52 const std::string
& account_id
,
53 const PolicyRegistrationCallback
& callback
);
55 #if !defined(OS_ANDROID)
56 // Registers a CloudPolicyClient for fetching policy for |username|.
57 // This requires a valid OAuth access token for the scopes returned by the
58 // |GetScopes| static function. |callback| is invoked once we have
59 // registered this device to fetch policy, or once it is determined that
60 // |username| is not a managed account.
61 void RegisterForPolicyWithAccessToken(
62 const std::string
& username
,
63 const std::string
& access_token
,
64 const PolicyRegistrationCallback
& callback
);
66 // Returns the list of OAuth access scopes required for policy fetching.
67 static std::vector
<std::string
> GetScopes();
71 void RegisterForPolicyInternal(const std::string
& username
,
72 const std::string
& account_id
,
73 const std::string
& access_token
,
74 const PolicyRegistrationCallback
& callback
);
76 void CallPolicyRegistrationCallback(scoped_ptr
<CloudPolicyClient
> client
,
77 PolicyRegistrationCallback callback
);
79 // KeyedService implementation:
80 void Shutdown() override
;
82 // CloudPolicyService::Observer implementation:
83 void OnInitializationCompleted(CloudPolicyService
* service
) override
;
85 // Overridden from UserPolicySigninServiceBase to cancel the pending delayed
87 void ShutdownUserCloudPolicyManager() override
;
89 // Registers for cloud policy for an already signed-in user.
90 void RegisterCloudPolicyService();
92 // Cancels a pending cloud policy registration attempt.
93 void CancelPendingRegistration();
95 void OnRegistrationDone();
97 scoped_ptr
<CloudPolicyClientRegistrationHelper
> registration_helper_
;
99 // Weak pointer to the token service used to authenticate the
100 // CloudPolicyClient during registration.
101 ProfileOAuth2TokenService
* oauth2_token_service_
;
103 // The PrefService associated with the profile.
104 PrefService
* profile_prefs_
;
106 base::WeakPtrFactory
<UserPolicySigninService
> weak_factory_
;
108 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService
);
111 } // namespace policy
113 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_