Convert remoting_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / chrome / browser / policy / cloud / user_policy_signin_service_mobile.h
blob96592864853c4432e955fc51a4848a42206f63fa
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_MOBILE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_
8 #include <string>
9 #include <vector>
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"
18 class ProfileOAuth2TokenService;
19 class Profile;
21 namespace net {
22 class URLRequestContextGetter;
25 namespace policy {
27 class CloudPolicyClientRegistrationHelper;
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 ~UserPolicySigninService() override;
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);
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);
63 // Returns the list of OAuth access scopes required for policy fetching.
64 static std::vector<std::string> GetScopes();
65 #endif
67 private:
68 void RegisterForPolicyInternal(
69 const std::string& username,
70 const std::string& access_token,
71 const PolicyRegistrationCallback& callback);
73 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
74 PolicyRegistrationCallback callback);
76 // KeyedService implementation:
77 void Shutdown() override;
79 // CloudPolicyService::Observer implementation:
80 void OnInitializationCompleted(CloudPolicyService* service) override;
82 // Overridden from UserPolicySigninServiceBase to cancel the pending delayed
83 // registration.
84 void ShutdownUserCloudPolicyManager() override;
86 // Registers for cloud policy for an already signed-in user.
87 void RegisterCloudPolicyService();
89 // Cancels a pending cloud policy registration attempt.
90 void CancelPendingRegistration();
92 void OnRegistrationDone();
94 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
96 // Weak pointer to the token service used to authenticate the
97 // CloudPolicyClient during registration.
98 ProfileOAuth2TokenService* oauth2_token_service_;
100 // The PrefService associated with the profile.
101 PrefService* profile_prefs_;
103 base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
105 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
108 } // namespace policy
110 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_MOBILE_H_