- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / user_policy_signin_service.h
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_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_
7
8 #include <string>
9
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"
16
17 class Profile;
18
19 namespace net {
20 class URLRequestContextGetter;
21 }
22
23 namespace policy {
24
25 class CloudPolicyClientRegistrationHelper;
26
27 // A specialization of the UserPolicySigninServiceBase for the desktop
28 // platforms (Windows, Mac and Linux).
29 class UserPolicySigninService : public UserPolicySigninServiceBase,
30                                 public OAuth2TokenService::Observer {
31  public:
32   // Creates a UserPolicySigninService associated with the passed |profile|.
33   UserPolicySigninService(
34       Profile* profile,
35       PrefService* local_state,
36       scoped_refptr<net::URLRequestContextGetter> request_context,
37       DeviceManagementService* device_management_service,
38       ProfileOAuth2TokenService* oauth2_token_service);
39   virtual ~UserPolicySigninService();
40
41   // Registers a CloudPolicyClient for fetching policy for a user. The
42   // |oauth2_login_token| and |username| are explicitly passed because
43   // the user is not signed in yet (ProfileOAuth2TokenService does not have
44   // any tokens yet to prevent services from using it until after we've fetched
45   // policy).
46   void RegisterPolicyClient(const std::string& username,
47                             const std::string& oauth2_login_token,
48                             const PolicyRegistrationCallback& callback);
49
50   // OAuth2TokenService::Observer implementation:
51   virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
52
53   // CloudPolicyService::Observer implementation:
54   virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
55
56   // BrowserContextKeyedService implementation:
57   virtual void Shutdown() OVERRIDE;
58
59  protected:
60   // UserPolicySigninServiceBase implementation:
61   virtual void InitializeUserCloudPolicyManager(
62       scoped_ptr<CloudPolicyClient> client) OVERRIDE;
63
64   virtual void PrepareForUserCloudPolicyManagerShutdown() OVERRIDE;
65   virtual void ShutdownUserCloudPolicyManager() OVERRIDE;
66
67  private:
68   // Fetches an OAuth token to allow the cloud policy service to register with
69   // the cloud policy server. |oauth_login_token| should contain an OAuth login
70   // refresh token that can be downscoped to get an access token for the
71   // device_management service.
72   void RegisterCloudPolicyService();
73
74   // Callback invoked when policy registration has finished.
75   void OnRegistrationComplete();
76
77   // Helper routine which prohibits user signout if the user is registered for
78   // cloud policy.
79   void ProhibitSignoutIfNeeded();
80
81   // Invoked when a policy registration request is complete.
82   void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
83                                       PolicyRegistrationCallback callback);
84
85   scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
86
87   // Weak pointer to the token service we use to authenticate during
88   // CloudPolicyClient registration.
89   ProfileOAuth2TokenService* oauth2_token_service_;
90
91   DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
92 };
93
94 }  // namespace policy
95
96 #endif  // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_