OLD | NEW |
| (Empty) |
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_USER_POLICY_SIGNIN_SERVICE_H_ | |
6 #define CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/profiles/profile_keyed_service.h" | |
11 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 | |
15 class OAuth2AccessTokenFetcher; | |
16 class Profile; | |
17 | |
18 namespace base { | |
19 class Time; | |
20 } | |
21 | |
22 namespace policy { | |
23 | |
24 class UserCloudPolicyManager; | |
25 | |
26 // The UserPolicySigninService tracks when user signin/signout actions occur and | |
27 // initializes/shuts down the UserCloudPolicyManager as required. This class is | |
28 // not used on ChromeOS because UserCloudPolicyManager initialization is handled | |
29 // via LoginUtils, since it must happen before profile creation. | |
30 class UserPolicySigninService | |
31 : public ProfileKeyedService, | |
32 public OAuth2AccessTokenConsumer, | |
33 public content::NotificationObserver { | |
34 public: | |
35 // Creates a UserPolicySigninService associated with the passed |profile|. | |
36 UserPolicySigninService(Profile* profile, UserCloudPolicyManager* manager); | |
37 virtual ~UserPolicySigninService(); | |
38 | |
39 // content::NotificationObserver implementation. | |
40 virtual void Observe(int type, | |
41 const content::NotificationSource& source, | |
42 const content::NotificationDetails& details) OVERRIDE; | |
43 | |
44 // OAuth2AccessTokenConsumer implementation. | |
45 virtual void OnGetTokenSuccess(const std::string& access_token, | |
46 const base::Time& expiration_time) OVERRIDE; | |
47 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | |
48 | |
49 private: | |
50 // Initializes the UserCloudPolicyManager to reflect the currently-signed-in | |
51 // user. | |
52 void ConfigureUserCloudPolicyManager(); | |
53 | |
54 // Fetches an OAuth token to allow the cloud policy service to register with | |
55 // the cloud policy server. | |
56 void RegisterCloudPolicyService(); | |
57 | |
58 // Weak pointer to the profile this service is associated with. | |
59 Profile* profile_; | |
60 | |
61 content::NotificationRegistrar registrar_; | |
62 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | |
63 | |
64 // Weak pointer to the UserCloudPolicyManager (allows dependency injection | |
65 // for tests). | |
66 UserCloudPolicyManager* manager_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); | |
69 }; | |
70 | |
71 } // namespace policy | |
72 | |
73 #endif // CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | |
OLD | NEW |