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/barrier_closure.h" |
7 #include "base/callback.h" | 8 #include "base/callback.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 12 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 15 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chromeos/chromeos_switches.h" | 18 #include "chromeos/chromeos_switches.h" |
18 #include "components/user_manager/user.h" | 19 #include "components/user_manager/user.h" |
19 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/browser/web_contents.h" |
| 24 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 25 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
21 | 26 |
22 namespace chromeos { | 27 namespace chromeos { |
23 | 28 |
24 namespace { | 29 namespace { |
25 | 30 |
26 // As defined in /chromeos/dbus/cryptohome_client.cc. | 31 // As defined in /chromeos/dbus/cryptohome_client.cc. |
27 static const char kUserIdHashSuffix[] = "-hash"; | 32 static const char kUserIdHashSuffix[] = "-hash"; |
28 | 33 |
29 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { | 34 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { |
30 // Do not add profile dir prefix for legacy profile dir and test | 35 // Do not add profile dir prefix for legacy profile dir and test |
(...skipping 10 matching lines...) Expand all Loading... |
41 public: | 46 public: |
42 explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {} | 47 explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {} |
43 bool operator()(const user_manager::User* user) const { | 48 bool operator()(const user_manager::User* user) const { |
44 return user->username_hash() == username_hash; | 49 return user->username_hash() == username_hash; |
45 } | 50 } |
46 | 51 |
47 private: | 52 private: |
48 const std::string& username_hash; | 53 const std::string& username_hash; |
49 }; | 54 }; |
50 | 55 |
| 56 bool GetWebViewPartition(std::set<content::StoragePartition*>* partition_set, |
| 57 content::WebContents* web_contents) { |
| 58 extensions::WebViewGuest* view_guest = |
| 59 extensions::WebViewGuest::FromWebContents(web_contents); |
| 60 if (view_guest) { |
| 61 content::StoragePartition* partition = |
| 62 content::BrowserContext::GetStoragePartition( |
| 63 web_contents->GetBrowserContext(), web_contents->GetSiteInstance()); |
| 64 partition_set->insert(partition); |
| 65 } |
| 66 return false; |
| 67 } |
| 68 |
| 69 void ClearContentsData(content::WebContents* web_contents, |
| 70 const base::Closure& on_clear_callback) { |
| 71 content::BrowserContext* context = web_contents->GetBrowserContext(); |
| 72 extensions::GuestViewManager* manager = |
| 73 extensions::GuestViewManager::FromBrowserContext(context); |
| 74 std::set<content::StoragePartition*> partition_set; |
| 75 manager->ForEachGuest(web_contents, |
| 76 base::Bind(&GetWebViewPartition, &partition_set)); |
| 77 base::Closure barrier_closure = |
| 78 base::BarrierClosure(partition_set.size(), on_clear_callback); |
| 79 for (const auto& partition : partition_set) { |
| 80 partition->ClearData( |
| 81 content::StoragePartition::REMOVE_DATA_MASK_ALL, |
| 82 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, GURL(), |
| 83 content::StoragePartition::OriginMatcherFunction(), base::Time(), |
| 84 base::Time::Now(), barrier_closure); |
| 85 } |
| 86 } |
| 87 |
51 } // anonymous namespace | 88 } // anonymous namespace |
52 | 89 |
53 // static | 90 // static |
54 bool ProfileHelper::enable_profile_to_user_testing = false; | 91 bool ProfileHelper::enable_profile_to_user_testing = false; |
55 bool ProfileHelper::always_return_primary_user_for_testing = false; | 92 bool ProfileHelper::always_return_primary_user_for_testing = false; |
56 | 93 |
57 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
58 // ProfileHelper, public | 95 // ProfileHelper, public |
59 | 96 |
60 ProfileHelper::ProfileHelper() | 97 ProfileHelper::ProfileHelper() |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 227 } |
191 | 228 |
192 base::FilePath ProfileHelper::GetActiveUserProfileDir() { | 229 base::FilePath ProfileHelper::GetActiveUserProfileDir() { |
193 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); | 230 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); |
194 } | 231 } |
195 | 232 |
196 void ProfileHelper::Initialize() { | 233 void ProfileHelper::Initialize() { |
197 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 234 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
198 } | 235 } |
199 | 236 |
200 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { | 237 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback, |
201 on_clear_callbacks_.push_back(on_clear_callback); | 238 content::WebContents* webview_contents) { |
| 239 on_clear_callbacks_.push_back( |
| 240 webview_contents |
| 241 ? base::Bind(&ClearContentsData, webview_contents, on_clear_callback) |
| 242 : on_clear_callback); |
202 if (signin_profile_clear_requested_) | 243 if (signin_profile_clear_requested_) |
203 return; | 244 return; |
204 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 245 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
205 // Check if signin profile was loaded. | 246 // Check if signin profile was loaded. |
206 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { | 247 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { |
207 OnBrowsingDataRemoverDone(); | 248 OnBrowsingDataRemoverDone(); |
208 return; | 249 return; |
209 } | 250 } |
210 signin_profile_clear_requested_ = true; | 251 signin_profile_clear_requested_ = true; |
211 BrowsingDataRemover* remover = | 252 BrowsingDataRemover* remover = |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 void ProfileHelper::OnSessionRestoreStateChanged( | 384 void ProfileHelper::OnSessionRestoreStateChanged( |
344 Profile* user_profile, | 385 Profile* user_profile, |
345 OAuth2LoginManager::SessionRestoreState state) { | 386 OAuth2LoginManager::SessionRestoreState state) { |
346 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE || | 387 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE || |
347 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || | 388 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || |
348 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) { | 389 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) { |
349 chromeos::OAuth2LoginManager* login_manager = | 390 chromeos::OAuth2LoginManager* login_manager = |
350 chromeos::OAuth2LoginManagerFactory::GetInstance()-> | 391 chromeos::OAuth2LoginManagerFactory::GetInstance()-> |
351 GetForProfile(user_profile); | 392 GetForProfile(user_profile); |
352 login_manager->RemoveObserver(this); | 393 login_manager->RemoveObserver(this); |
353 ClearSigninProfile(base::Closure()); | 394 ClearSigninProfile(base::Closure(), nullptr); |
354 } | 395 } |
355 } | 396 } |
356 | 397 |
357 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
358 // ProfileHelper, UserManager::UserSessionStateObserver implementation: | 399 // ProfileHelper, UserManager::UserSessionStateObserver implementation: |
359 | 400 |
360 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { | 401 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { |
361 active_user_id_hash_ = hash; | 402 active_user_id_hash_ = hash; |
362 } | 403 } |
363 | 404 |
(...skipping 19 matching lines...) Expand all Loading... |
383 user_to_profile_for_testing_[user] = profile; | 424 user_to_profile_for_testing_[user] = profile; |
384 } | 425 } |
385 | 426 |
386 // static | 427 // static |
387 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( | 428 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( |
388 const std::string& user_id) { | 429 const std::string& user_id) { |
389 return user_id + kUserIdHashSuffix; | 430 return user_id + kUserIdHashSuffix; |
390 } | 431 } |
391 | 432 |
392 } // namespace chromeos | 433 } // namespace chromeos |
OLD | NEW |