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_IOS_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_IOS_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 "base/memory/weak_ptr.h"
15 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
17 class ProfileOAuth2TokenService;
21 class URLRequestContextGetter;
26 class CloudPolicyClientRegistrationHelper;
28 typedef void (^PolicyRegistrationBlockCallback)(const std::string& dm_token,
29 const std::string& client_id);
31 typedef void (^PolicyFetchBlockCallback)(bool succeeded);
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 {
38 // Creates a UserPolicySigninService associated with the passed |profile|.
39 UserPolicySigninService(
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();
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);
57 // Wrapper for FetchPolicyForSignedInUser that uses a block instead of
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);
67 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
68 PolicyRegistrationBlockCallback callback);
70 void CallPolicyFetchCallback(PolicyFetchBlockCallback callback,
73 // KeyedService implementation:
74 virtual void Shutdown() OVERRIDE;
76 // CloudPolicyService::Observer implementation:
77 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
79 // Cancels a pending cloud policy registration attempt.
80 void CancelPendingRegistration();
82 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
83 base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
85 // Weak pointer to the token service used to authenticate the
86 // CloudPolicyClient during registration.
87 ProfileOAuth2TokenService* oauth2_token_service_;
89 // The PrefService associated with the profile.
90 PrefService* profile_prefs_;
92 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
97 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_IOS_H_