Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / user_policy_signin_service_mobile.h
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.
4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_
7
8 #include <string>
9 #include <vector>
10
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"
17
18 class ProfileOAuth2TokenService;
19 class Profile;
20
21 namespace net {
22 class URLRequestContextGetter;
23 }
24
25 namespace policy {
26
27 class CloudPolicyClientRegistrationHelper;
28
29 // A specialization of the UserPolicySigninServiceBase for the mobile platforms
30 // (currently Android and iOS).
31 class UserPolicySigninService : public UserPolicySigninServiceBase {
32  public:
33   // Creates a UserPolicySigninService associated with the passed |profile|.
34   UserPolicySigninService(
35       Profile* profile,
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   virtual ~UserPolicySigninService();
43
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   // |callback| is invoked once we have registered this device to fetch policy,
48   // or once it is determined that |username| is not a managed account.
49   void RegisterForPolicy(const std::string& username,
50                          const PolicyRegistrationCallback& callback);
51
52 #if !defined(OS_ANDROID)
53   // Registers a CloudPolicyClient for fetching policy for |username|.
54   // This requires a valid OAuth access token for the scopes returned by the
55   // |GetScopes| static function. |callback| is invoked once we have
56   // registered this device to fetch policy, or once it is determined that
57   // |username| is not a managed account.
58   void RegisterForPolicyWithAccessToken(
59       const std::string& username,
60       const std::string& access_token,
61       const PolicyRegistrationCallback& callback);
62
63   // Returns the list of OAuth access scopes required for policy fetching.
64   static std::vector<std::string> GetScopes();
65 #endif
66
67  private:
68   void RegisterForPolicyInternal(
69       const std::string& username,
70       const std::string& access_token,
71       const PolicyRegistrationCallback& callback);
72
73   void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
74                                       PolicyRegistrationCallback callback);
75
76   // KeyedService implementation:
77   virtual void Shutdown() OVERRIDE;
78
79   // CloudPolicyService::Observer implementation:
80   virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
81
82   // Overridden from UserPolicySigninServiceBase to cancel the pending delayed
83   // registration.
84   virtual void ShutdownUserCloudPolicyManager() OVERRIDE;
85
86   // Registers for cloud policy for an already signed-in user.
87   void RegisterCloudPolicyService();
88
89   // Cancels a pending cloud policy registration attempt.
90   void CancelPendingRegistration();
91
92   void OnRegistrationDone();
93
94   scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
95
96   // Weak pointer to the token service used to authenticate the
97   // CloudPolicyClient during registration.
98   ProfileOAuth2TokenService* oauth2_token_service_;
99
100   // The PrefService associated with the profile.
101   PrefService* profile_prefs_;
102
103   base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
104
105   DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
106 };
107
108 }  // namespace policy
109
110 #endif  // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_