OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/profiles/profile_helper.h" | 5 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 10 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
18 #include "components/user_manager/user.h" | 18 #include "components/user_manager/user.h" |
19 #include "components/user_manager/user_manager.h" | 19 #include "components/user_manager/user_manager.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/storage_partition.h" | |
22 #include "content/public/browser/web_contents.h" | |
23 #include "extensions/browser/guest_view/guest_view_manager.h" | |
24 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | |
21 | 25 |
22 namespace chromeos { | 26 namespace chromeos { |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 // As defined in /chromeos/dbus/cryptohome_client.cc. | 30 // As defined in /chromeos/dbus/cryptohome_client.cc. |
27 static const char kUserIdHashSuffix[] = "-hash"; | 31 static const char kUserIdHashSuffix[] = "-hash"; |
28 | 32 |
29 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { | 33 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { |
30 // Do not add profile dir prefix for legacy profile dir and test | 34 // Do not add profile dir prefix for legacy profile dir and test |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 } | 194 } |
191 | 195 |
192 base::FilePath ProfileHelper::GetActiveUserProfileDir() { | 196 base::FilePath ProfileHelper::GetActiveUserProfileDir() { |
193 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); | 197 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); |
194 } | 198 } |
195 | 199 |
196 void ProfileHelper::Initialize() { | 200 void ProfileHelper::Initialize() { |
197 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 201 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
198 } | 202 } |
199 | 203 |
200 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { | 204 static bool ClearWebViewData(const base::Closure& on_clear_callback, |
Roman Sorokin (ftl)
2015/03/19 13:15:40
Why these functions are static? Please move to ano
Ivan Podogov
2015/03/19 13:25:37
Done.
| |
201 on_clear_callbacks_.push_back(on_clear_callback); | 205 content::WebContents* web_contents) { |
206 extensions::WebViewGuest* view_guest = | |
207 extensions::WebViewGuest::FromWebContents(web_contents); | |
208 if (view_guest) { | |
209 view_guest->ClearData(base::Time(), | |
210 content::StoragePartition::REMOVE_DATA_MASK_ALL, | |
211 on_clear_callback); | |
212 return true; | |
Roman Sorokin (ftl)
2015/03/19 13:15:40
Why we don't return value returned by ClearData?
Ivan Podogov
2015/03/19 13:25:37
Done.
| |
213 } | |
214 return false; | |
215 } | |
216 | |
217 static void ClearContentsData(content::WebContents* web_contents, | |
218 const base::Closure& on_clear_callback) { | |
219 content::BrowserContext* context = web_contents->GetBrowserContext(); | |
220 extensions::GuestViewManager* manager = | |
221 extensions::GuestViewManager::FromBrowserContext(context); | |
222 if (!manager->ForEachGuest( | |
223 web_contents, base::Bind(&ClearWebViewData, on_clear_callback))) { | |
224 on_clear_callback.Run(); | |
225 } | |
226 } | |
227 | |
228 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback, | |
229 content::WebContents* webview_contents) { | |
230 on_clear_callbacks_.push_back( | |
231 webview_contents | |
232 ? base::Bind(&ClearContentsData, webview_contents, on_clear_callback) | |
233 : on_clear_callback); | |
202 if (signin_profile_clear_requested_) | 234 if (signin_profile_clear_requested_) |
203 return; | 235 return; |
204 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 236 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
205 // Check if signin profile was loaded. | 237 // Check if signin profile was loaded. |
206 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { | 238 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { |
207 OnBrowsingDataRemoverDone(); | 239 OnBrowsingDataRemoverDone(); |
208 return; | 240 return; |
209 } | 241 } |
210 signin_profile_clear_requested_ = true; | 242 signin_profile_clear_requested_ = true; |
211 BrowsingDataRemover* remover = | 243 BrowsingDataRemover* remover = |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 void ProfileHelper::OnSessionRestoreStateChanged( | 375 void ProfileHelper::OnSessionRestoreStateChanged( |
344 Profile* user_profile, | 376 Profile* user_profile, |
345 OAuth2LoginManager::SessionRestoreState state) { | 377 OAuth2LoginManager::SessionRestoreState state) { |
346 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE || | 378 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE || |
347 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || | 379 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || |
348 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) { | 380 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) { |
349 chromeos::OAuth2LoginManager* login_manager = | 381 chromeos::OAuth2LoginManager* login_manager = |
350 chromeos::OAuth2LoginManagerFactory::GetInstance()-> | 382 chromeos::OAuth2LoginManagerFactory::GetInstance()-> |
351 GetForProfile(user_profile); | 383 GetForProfile(user_profile); |
352 login_manager->RemoveObserver(this); | 384 login_manager->RemoveObserver(this); |
353 ClearSigninProfile(base::Closure()); | 385 ClearSigninProfile(base::Closure(), nullptr); |
354 } | 386 } |
355 } | 387 } |
356 | 388 |
357 //////////////////////////////////////////////////////////////////////////////// | 389 //////////////////////////////////////////////////////////////////////////////// |
358 // ProfileHelper, UserManager::UserSessionStateObserver implementation: | 390 // ProfileHelper, UserManager::UserSessionStateObserver implementation: |
359 | 391 |
360 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { | 392 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { |
361 active_user_id_hash_ = hash; | 393 active_user_id_hash_ = hash; |
362 } | 394 } |
363 | 395 |
(...skipping 19 matching lines...) Expand all Loading... | |
383 user_to_profile_for_testing_[user] = profile; | 415 user_to_profile_for_testing_[user] = profile; |
384 } | 416 } |
385 | 417 |
386 // static | 418 // static |
387 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( | 419 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( |
388 const std::string& user_id) { | 420 const std::string& user_id) { |
389 return user_id + kUserIdHashSuffix; | 421 return user_id + kUserIdHashSuffix; |
390 } | 422 } |
391 | 423 |
392 } // namespace chromeos | 424 } // namespace chromeos |
OLD | NEW |