OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h" | 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 UserCloudPolicyManager* manager = policy_manager(); | 65 UserCloudPolicyManager* manager = policy_manager(); |
66 DCHECK(manager); | 66 DCHECK(manager); |
67 DCHECK(!manager->core()->client()); | 67 DCHECK(!manager->core()->client()); |
68 InitializeUserCloudPolicyManager(username, client.Pass()); | 68 InitializeUserCloudPolicyManager(username, client.Pass()); |
69 DCHECK(manager->IsClientRegistered()); | 69 DCHECK(manager->IsClientRegistered()); |
70 | 70 |
71 // Now initiate a policy fetch. | 71 // Now initiate a policy fetch. |
72 manager->core()->service()->RefreshPolicy(callback); | 72 manager->core()->service()->RefreshPolicy(callback); |
73 } | 73 } |
74 | 74 |
| 75 void UserPolicySigninServiceBase::GoogleSignedOut(const std::string& username) { |
| 76 ShutdownUserCloudPolicyManager(); |
| 77 } |
| 78 |
75 void UserPolicySigninServiceBase::Observe( | 79 void UserPolicySigninServiceBase::Observe( |
76 int type, | 80 int type, |
77 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
78 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
79 switch (type) { | 83 switch (type) { |
80 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | |
81 ShutdownUserCloudPolicyManager(); | |
82 break; | |
83 case chrome::NOTIFICATION_PROFILE_ADDED: | 84 case chrome::NOTIFICATION_PROFILE_ADDED: |
84 // A new profile has been loaded - if it's signed in, then initialize the | 85 // A new profile has been loaded - if it's signed in, then initialize the |
85 // UCPM, otherwise shut down the UCPM (which deletes any cached policy | 86 // UCPM, otherwise shut down the UCPM (which deletes any cached policy |
86 // data). This must be done here instead of at constructor time because | 87 // data). This must be done here instead of at constructor time because |
87 // the Profile is not fully initialized when this object is constructed | 88 // the Profile is not fully initialized when this object is constructed |
88 // (DoFinalInit() has not yet been called, so ProfileIOData and | 89 // (DoFinalInit() has not yet been called, so ProfileIOData and |
89 // SSLConfigServiceManager have not been created yet). | 90 // SSLConfigServiceManager have not been created yet). |
90 // TODO(atwilson): Switch to using a timer instead, to avoid contention | 91 // TODO(atwilson): Switch to using a timer instead, to avoid contention |
91 // with other services at startup (http://crbug.com/165468). | 92 // with other services at startup (http://crbug.com/165468). |
92 InitializeOnProfileReady(content::Source<Profile>(source).ptr()); | 93 InitializeOnProfileReady(content::Source<Profile>(source).ptr()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 base::Bind( | 126 base::Bind( |
126 &UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager, | 127 &UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager, |
127 weak_factory_.GetWeakPtr())); | 128 weak_factory_.GetWeakPtr())); |
128 } else { | 129 } else { |
129 DVLOG(1) << "Error fetching policy: " << client->status(); | 130 DVLOG(1) << "Error fetching policy: " << client->status(); |
130 } | 131 } |
131 } | 132 } |
132 } | 133 } |
133 | 134 |
134 void UserPolicySigninServiceBase::Shutdown() { | 135 void UserPolicySigninServiceBase::Shutdown() { |
| 136 if (signin_manager()) |
| 137 signin_manager()->RemoveObserver(this); |
135 PrepareForUserCloudPolicyManagerShutdown(); | 138 PrepareForUserCloudPolicyManagerShutdown(); |
136 } | 139 } |
137 | 140 |
138 void UserPolicySigninServiceBase::PrepareForUserCloudPolicyManagerShutdown() { | 141 void UserPolicySigninServiceBase::PrepareForUserCloudPolicyManagerShutdown() { |
139 UserCloudPolicyManager* manager = policy_manager(); | 142 UserCloudPolicyManager* manager = policy_manager(); |
140 if (manager && manager->core()->client()) | 143 if (manager && manager->core()->client()) |
141 manager->core()->client()->RemoveObserver(this); | 144 manager->core()->client()->RemoveObserver(this); |
142 if (manager && manager->core()->service()) | 145 if (manager && manager->core()->service()) |
143 manager->core()->service()->RemoveObserver(this); | 146 manager->core()->service()->RemoveObserver(this); |
144 } | 147 } |
(...skipping 28 matching lines...) Expand all Loading... |
173 } | 176 } |
174 | 177 |
175 void UserPolicySigninServiceBase::InitializeOnProfileReady(Profile* profile) { | 178 void UserPolicySigninServiceBase::InitializeOnProfileReady(Profile* profile) { |
176 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, | 179 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, |
177 // skip initialization. | 180 // skip initialization. |
178 if (!policy_manager() || !signin_manager()) { | 181 if (!policy_manager() || !signin_manager()) { |
179 DVLOG(1) << "Skipping initialization for tests due to missing components."; | 182 DVLOG(1) << "Skipping initialization for tests due to missing components."; |
180 return; | 183 return; |
181 } | 184 } |
182 | 185 |
183 // Shutdown the UserCloudPolicyManager when the user signs out. We do | 186 // Shutdown the UserCloudPolicyManager when the user signs out. We start |
184 // this here because we don't want to get SIGNED_OUT notifications until | 187 // observing the SigninManager here because we don't want to get signout |
185 // after the profile has started initializing (http://crbug.com/316229). | 188 // notifications until after the profile has started initializing |
186 registrar_.Add(this, | 189 // (http://crbug.com/316229). |
187 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 190 signin_manager()->AddObserver(this); |
188 content::Source<Profile>(profile)); | |
189 | 191 |
190 std::string username = signin_manager()->GetAuthenticatedUsername(); | 192 std::string username = signin_manager()->GetAuthenticatedUsername(); |
191 if (username.empty()) | 193 if (username.empty()) |
192 ShutdownUserCloudPolicyManager(); | 194 ShutdownUserCloudPolicyManager(); |
193 else | 195 else |
194 InitializeForSignedInUser(username, profile->GetRequestContext()); | 196 InitializeForSignedInUser(username, profile->GetRequestContext()); |
195 } | 197 } |
196 | 198 |
197 void UserPolicySigninServiceBase::InitializeForSignedInUser( | 199 void UserPolicySigninServiceBase::InitializeForSignedInUser( |
198 const std::string& username, | 200 const std::string& username, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 259 } |
258 | 260 |
259 scoped_refptr<net::URLRequestContextGetter> | 261 scoped_refptr<net::URLRequestContextGetter> |
260 UserPolicySigninServiceBase::CreateUserRequestContext( | 262 UserPolicySigninServiceBase::CreateUserRequestContext( |
261 scoped_refptr<net::URLRequestContextGetter> profile_request_context) { | 263 scoped_refptr<net::URLRequestContextGetter> profile_request_context) { |
262 return new UserPolicyRequestContext( | 264 return new UserPolicyRequestContext( |
263 profile_request_context, system_request_context(), GetUserAgent()); | 265 profile_request_context, system_request_context(), GetUserAgent()); |
264 } | 266 } |
265 | 267 |
266 } // namespace policy | 268 } // namespace policy |
OLD | NEW |