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.
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service.h"
20 class URLRequestContextGetter
;
25 class CloudPolicyClientRegistrationHelper
;
27 // A specialization of the UserPolicySigninServiceBase for the desktop
28 // platforms (Windows, Mac and Linux).
29 class UserPolicySigninService
: public UserPolicySigninServiceBase
,
30 public OAuth2TokenService::Observer
{
32 // Creates a UserPolicySigninService associated with the passed
33 // |policy_manager| and |signin_manager|.
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
* oauth2_token_service
);
42 virtual ~UserPolicySigninService();
44 // Registers a CloudPolicyClient for fetching policy for a user. The
45 // |oauth2_login_token| and |username| are explicitly passed because
46 // the user is not signed in yet (ProfileOAuth2TokenService does not have
47 // any tokens yet to prevent services from using it until after we've fetched
49 void RegisterForPolicy(const std::string
& username
,
50 const std::string
& oauth2_login_token
,
51 const PolicyRegistrationCallback
& callback
);
53 // OAuth2TokenService::Observer implementation:
54 virtual void OnRefreshTokenAvailable(const std::string
& account_id
) OVERRIDE
;
56 // CloudPolicyService::Observer implementation:
57 virtual void OnInitializationCompleted(CloudPolicyService
* service
) OVERRIDE
;
59 // BrowserContextKeyedService implementation:
60 virtual void Shutdown() OVERRIDE
;
63 // UserPolicySigninServiceBase implementation:
64 virtual void InitializeUserCloudPolicyManager(
65 const std::string
& username
,
66 scoped_ptr
<CloudPolicyClient
> client
) OVERRIDE
;
68 virtual void PrepareForUserCloudPolicyManagerShutdown() OVERRIDE
;
69 virtual void ShutdownUserCloudPolicyManager() OVERRIDE
;
72 // Fetches an OAuth token to allow the cloud policy service to register with
73 // the cloud policy server. |oauth_login_token| should contain an OAuth login
74 // refresh token that can be downscoped to get an access token for the
75 // device_management service.
76 void RegisterCloudPolicyService();
78 // Callback invoked when policy registration has finished.
79 void OnRegistrationComplete();
81 // Helper routine which prohibits user signout if the user is registered for
83 void ProhibitSignoutIfNeeded();
85 // Invoked when a policy registration request is complete.
86 void CallPolicyRegistrationCallback(scoped_ptr
<CloudPolicyClient
> client
,
87 PolicyRegistrationCallback callback
);
89 // Parent profile for this service.
92 scoped_ptr
<CloudPolicyClientRegistrationHelper
> registration_helper_
;
94 // Weak pointer to the token service we use to authenticate during
95 // CloudPolicyClient registration.
96 ProfileOAuth2TokenService
* oauth2_token_service_
;
98 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService
);
101 } // namespace policy
103 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_