OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // The signin manager encapsulates some functionality tracking | 5 // The signin manager encapsulates some functionality tracking |
6 // which user is signed in. See SigninManagerBase for full description of | 6 // which user is signed in. See SigninManagerBase for full description of |
7 // responsibilities. The class defined in this file provides functionality | 7 // responsibilities. The class defined in this file provides functionality |
8 // required by all platforms except Chrome OS. | 8 // required by all platforms except Chrome OS. |
9 // | 9 // |
10 // When a user is signed in, a ClientLogin request is run on their behalf. | 10 // When a user is signed in, a ClientLogin request is run on their behalf. |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include <set> | 24 #include <set> |
25 #include <string> | 25 #include <string> |
26 | 26 |
27 #include "base/compiler_specific.h" | 27 #include "base/compiler_specific.h" |
28 #include "base/gtest_prod_util.h" | 28 #include "base/gtest_prod_util.h" |
29 #include "base/logging.h" | 29 #include "base/logging.h" |
30 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
31 #include "base/observer_list.h" | 31 #include "base/observer_list.h" |
32 #include "base/prefs/pref_change_registrar.h" | 32 #include "base/prefs/pref_change_registrar.h" |
33 #include "base/prefs/pref_member.h" | 33 #include "base/prefs/pref_member.h" |
34 #include "chrome/browser/profiles/profile.h" | |
35 #include "components/keyed_service/core/keyed_service.h" | 34 #include "components/keyed_service/core/keyed_service.h" |
36 #include "components/signin/core/browser/signin_internals_util.h" | 35 #include "components/signin/core/browser/signin_internals_util.h" |
37 #include "components/signin/core/browser/signin_manager_base.h" | 36 #include "components/signin/core/browser/signin_manager_base.h" |
38 #include "google_apis/gaia/google_service_auth_error.h" | 37 #include "google_apis/gaia/google_service_auth_error.h" |
39 #include "google_apis/gaia/merge_session_helper.h" | 38 #include "google_apis/gaia/merge_session_helper.h" |
40 #include "net/cookies/canonical_cookie.h" | 39 #include "net/cookies/canonical_cookie.h" |
41 | 40 |
42 class PrefService; | 41 class PrefService; |
| 42 class ProfileOAuth2TokenService; |
43 class SigninAccountIdHelper; | 43 class SigninAccountIdHelper; |
44 class SigninClient; | 44 class SigninClient; |
45 | 45 |
46 class SigninManager : public SigninManagerBase { | 46 class SigninManager : public SigninManagerBase { |
47 public: | 47 public: |
48 // The callback invoked once the OAuth token has been fetched during signin, | 48 // The callback invoked once the OAuth token has been fetched during signin, |
49 // but before the profile transitions to the "signed-in" state. This allows | 49 // but before the profile transitions to the "signed-in" state. This allows |
50 // callers to load policy and prompt the user appropriately before completing | 50 // callers to load policy and prompt the user appropriately before completing |
51 // signin. The callback is passed the just-fetched OAuth login refresh token. | 51 // signin. The callback is passed the just-fetched OAuth login refresh token. |
52 typedef base::Callback<void(const std::string&)> OAuthTokenFetchedCallback; | 52 typedef base::Callback<void(const std::string&)> OAuthTokenFetchedCallback; |
53 | 53 |
54 // Returns true if |url| is a web signin URL and should be hosted in an | 54 // Returns true if |url| is a web signin URL and should be hosted in an |
55 // isolated, privileged signin process. | 55 // isolated, privileged signin process. |
56 static bool IsWebBasedSigninFlowURL(const GURL& url); | 56 static bool IsWebBasedSigninFlowURL(const GURL& url); |
57 | 57 |
58 // This is used to distinguish URLs belonging to the special web signin flow | 58 // This is used to distinguish URLs belonging to the special web signin flow |
59 // running in the special signin process from other URLs on the same domain. | 59 // running in the special signin process from other URLs on the same domain. |
60 // We do not grant WebUI privilieges / bindings to this process or to URLs of | 60 // We do not grant WebUI privilieges / bindings to this process or to URLs of |
61 // this scheme; enforcement of privileges is handled separately by | 61 // this scheme; enforcement of privileges is handled separately by |
62 // OneClickSigninHelper. | 62 // OneClickSigninHelper. |
63 static const char kChromeSigninEffectiveSite[]; | 63 static const char kChromeSigninEffectiveSite[]; |
64 | 64 |
65 explicit SigninManager(SigninClient* client); | 65 SigninManager(SigninClient* client, ProfileOAuth2TokenService* token_service); |
66 virtual ~SigninManager(); | 66 virtual ~SigninManager(); |
67 | 67 |
68 // Returns true if the username is allowed based on the policy string. | 68 // Returns true if the username is allowed based on the policy string. |
69 static bool IsUsernameAllowedByPolicy(const std::string& username, | 69 static bool IsUsernameAllowedByPolicy(const std::string& username, |
70 const std::string& policy); | 70 const std::string& policy); |
71 | 71 |
72 // Attempt to sign in this user with a refresh token. | 72 // Attempt to sign in this user with a refresh token. |
73 // If non-null, the passed |oauth_fetched_callback| callback is invoked once | 73 // If non-null, the passed |oauth_fetched_callback| callback is invoked once |
74 // signin has been completed. | 74 // signin has been completed. |
75 // The callback should invoke SignOut() or CompletePendingSignin() to either | 75 // The callback should invoke SignOut() or CompletePendingSignin() to either |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 virtual bool IsSigninAllowed() const OVERRIDE; | 108 virtual bool IsSigninAllowed() const OVERRIDE; |
109 | 109 |
110 // Returns true if the passed username is allowed by policy. Virtual for | 110 // Returns true if the passed username is allowed by policy. Virtual for |
111 // mocking in tests. | 111 // mocking in tests. |
112 virtual bool IsAllowedUsername(const std::string& username) const; | 112 virtual bool IsAllowedUsername(const std::string& username) const; |
113 | 113 |
114 // If an authentication is in progress, return the username being | 114 // If an authentication is in progress, return the username being |
115 // authenticated. Returns an empty string if no auth is in progress. | 115 // authenticated. Returns an empty string if no auth is in progress. |
116 const std::string& GetUsernameForAuthInProgress() const; | 116 const std::string& GetUsernameForAuthInProgress() const; |
117 | 117 |
118 // Set the profile preference to turn off one-click sign-in so that it won't | 118 // Set the preference to turn off one-click sign-in so that it won't ever |
119 // ever show it again in this profile (even if the user tries a new account). | 119 // show it again for the user associated with |prefs| (even if the user tries |
120 static void DisableOneClickSignIn(Profile* profile); | 120 // a new account). |
| 121 static void DisableOneClickSignIn(PrefService* prefs); |
121 | 122 |
122 // Tells the SigninManager whether to prohibit signout for this profile. | 123 // Tells the SigninManager whether to prohibit signout for this profile. |
123 // If |prohibit_signout| is true, then signout will be prohibited. | 124 // If |prohibit_signout| is true, then signout will be prohibited. |
124 void ProhibitSignout(bool prohibit_signout); | 125 void ProhibitSignout(bool prohibit_signout); |
125 | 126 |
126 // If true, signout is prohibited for this profile (calls to SignOut() are | 127 // If true, signout is prohibited for this profile (calls to SignOut() are |
127 // ignored). | 128 // ignored). |
128 bool IsSignoutProhibited() const; | 129 bool IsSignoutProhibited() const; |
129 | 130 |
130 // Add or remove observers for the merge session notification. | 131 // Add or remove observers for the merge session notification. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // Temporarily saves the oauth2 refresh token. It will be passed to the | 196 // Temporarily saves the oauth2 refresh token. It will be passed to the |
196 // token service so that it does not need to mint new ones. | 197 // token service so that it does not need to mint new ones. |
197 std::string temp_refresh_token_; | 198 std::string temp_refresh_token_; |
198 | 199 |
199 base::WeakPtrFactory<SigninManager> weak_pointer_factory_; | 200 base::WeakPtrFactory<SigninManager> weak_pointer_factory_; |
200 | 201 |
201 // The SigninClient object associated with this object. Must outlive this | 202 // The SigninClient object associated with this object. Must outlive this |
202 // object. | 203 // object. |
203 SigninClient* client_; | 204 SigninClient* client_; |
204 | 205 |
| 206 // The ProfileOAuth2TokenService instance associated with this object. Must |
| 207 // outlive this object. |
| 208 ProfileOAuth2TokenService* token_service_; |
| 209 |
205 // Helper object to listen for changes to signin preferences stored in non- | 210 // Helper object to listen for changes to signin preferences stored in non- |
206 // profile-specific local prefs (like kGoogleServicesUsernamePattern). | 211 // profile-specific local prefs (like kGoogleServicesUsernamePattern). |
207 PrefChangeRegistrar local_state_pref_registrar_; | 212 PrefChangeRegistrar local_state_pref_registrar_; |
208 | 213 |
209 // Helper object to listen for changes to the signin allowed preference. | 214 // Helper object to listen for changes to the signin allowed preference. |
210 BooleanPrefMember signin_allowed_; | 215 BooleanPrefMember signin_allowed_; |
211 | 216 |
212 // Helper to merge signed in account into the content area. | 217 // Helper to merge signed in account into the content area. |
213 scoped_ptr<MergeSessionHelper> merge_session_helper_; | 218 scoped_ptr<MergeSessionHelper> merge_session_helper_; |
214 | 219 |
215 DISALLOW_COPY_AND_ASSIGN(SigninManager); | 220 DISALLOW_COPY_AND_ASSIGN(SigninManager); |
216 }; | 221 }; |
217 | 222 |
218 #endif // !defined(OS_CHROMEOS) | 223 #endif // !defined(OS_CHROMEOS) |
219 | 224 |
220 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ | 225 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ |
OLD | NEW |