Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / cloud / user_policy_signin_service_ios.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_IOS_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_IOS_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 "base/memory/weak_ptr.h"
15 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
16
17 class ProfileOAuth2TokenService;
18 class Profile;
19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
24 namespace policy {
25
26 class CloudPolicyClientRegistrationHelper;
27
28 typedef void (^PolicyRegistrationBlockCallback)(const std::string& dm_token,
29                                                 const std::string& client_id);
30
31 typedef void (^PolicyFetchBlockCallback)(bool succeeded);
32
33 // A specialization of the UserPolicySigninServiceBase for iOS.
34 // TODO(joaodasilva): share more code with UserPolicySigninServiceBase and
35 // the Android implementation. http://crbug.com/273055
36 class UserPolicySigninService : public UserPolicySigninServiceBase {
37  public:
38   // Creates a UserPolicySigninService associated with the passed |profile|.
39   UserPolicySigninService(
40       Profile* profile,
41       PrefService* local_state,
42       DeviceManagementService* device_management_service,
43       UserCloudPolicyManager* policy_manager,
44       SigninManager* signin_manager,
45       scoped_refptr<net::URLRequestContextGetter> system_request_context,
46       ProfileOAuth2TokenService* token_service);
47   virtual ~UserPolicySigninService();
48
49   // Registers a CloudPolicyClient for fetching policy for |username|.
50   // This requests an OAuth2 token for the services involved, and contacts
51   // the policy service if the account has management enabled.
52   // |callback| is invoked once we have registered this device to fetch policy,
53   // or once it is determined that |username| is not a managed account.
54   void RegisterForPolicy(const std::string& username,
55                          PolicyRegistrationBlockCallback callback);
56
57   // Wrapper for FetchPolicyForSignedInUser that uses a block instead of
58   // a base::Callback.
59   void FetchPolicy(
60       const std::string& username,
61       const std::string& dm_token,
62       const std::string& client_id,
63       scoped_refptr<net::URLRequestContextGetter> profile_request_context,
64       PolicyFetchBlockCallback callback);
65
66  private:
67   void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
68                                       PolicyRegistrationBlockCallback callback);
69
70   void CallPolicyFetchCallback(PolicyFetchBlockCallback callback,
71                                bool succeeded);
72
73   // KeyedService implementation:
74   virtual void Shutdown() OVERRIDE;
75
76   // CloudPolicyService::Observer implementation:
77   virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
78
79   // Cancels a pending cloud policy registration attempt.
80   void CancelPendingRegistration();
81
82   scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
83   base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
84
85   // Weak pointer to the token service used to authenticate the
86   // CloudPolicyClient during registration.
87   ProfileOAuth2TokenService* oauth2_token_service_;
88
89   // The PrefService associated with the profile.
90   PrefService* profile_prefs_;
91
92   DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
93 };
94
95 }  // namespace policy
96
97 #endif  // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_IOS_H_