Chromium Code Reviews| 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <list> | |
| 6 | 7 |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" | 16 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
| 18 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | |
| 15 #include "chrome/browser/lifetime/keep_alive_types.h" | 19 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 16 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 20 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 17 #include "chrome/browser/password_manager/password_store_factory.h" | 21 #include "chrome/browser/password_manager/password_store_factory.h" |
| 18 #include "chrome/browser/profiles/profile_attributes_entry.h" | 22 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 19 #include "chrome/browser/profiles/profile_attributes_storage.h" | 23 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/profiles/profile_window.h" | 25 #include "chrome/browser/profiles/profile_window.h" |
| 22 #include "chrome/browser/profiles/profiles_state.h" | 26 #include "chrome/browser/profiles/profiles_state.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 27 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U); | 65 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U); |
| 62 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 66 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 63 if (status == Profile::CREATE_STATUS_INITIALIZED) | 67 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 64 base::MessageLoop::current()->QuitWhenIdle(); | 68 base::MessageLoop::current()->QuitWhenIdle(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 // An observer that returns back to test code after one or more profiles was | 71 // An observer that returns back to test code after one or more profiles was |
| 68 // deleted. It also create ScopedKeepAlive object to prevent browser shutdown | 72 // deleted. It also create ScopedKeepAlive object to prevent browser shutdown |
| 69 // started in case browser has become windowless. | 73 // started in case browser has become windowless. |
| 70 class MultipleProfileDeletionObserver | 74 class MultipleProfileDeletionObserver |
| 71 : public BrowsingDataRemoverImpl::CompletionInhibitor, | 75 : public ProfileAttributesStorage::Observer { |
| 72 public ProfileAttributesStorage::Observer { | |
| 73 public: | 76 public: |
| 74 explicit MultipleProfileDeletionObserver(size_t expected_count) | 77 explicit MultipleProfileDeletionObserver(size_t expected_count) |
| 75 : expected_count_(expected_count), | 78 : expected_count_(expected_count), |
| 76 profiles_created_count_(0), | 79 profiles_created_count_(0), |
| 77 profiles_data_removed_count_(0) { | 80 profiles_data_removed_count_(0) { |
| 78 EXPECT_GT(expected_count_, 0u); | 81 EXPECT_GT(expected_count_, 0u); |
| 79 g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 82 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 80 AddObserver(this); | 83 profile_manager->GetProfileAttributesStorage().AddObserver(this); |
| 81 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(this); | 84 |
| 85 for (Profile* profile : profile_manager->GetLoadedProfiles()) { | |
|
msramek
2017/04/10 13:20:08
I rewrote this test to use BrowsingDataRemoverComp
| |
| 86 inhibitors_.emplace_back( | |
| 87 BrowsingDataRemoverFactory::GetForBrowserContext(profile), | |
| 88 base::Bind(&MultipleProfileDeletionObserver:: | |
|
Bernhard Bauer
2017/04/10 23:29:37
Hm, this callback is always identical, right? Coul
msramek
2017/04/11 13:13:03
Done.
Yes, that's a good idea. I partially revert
| |
| 89 HandleBrowsingDataRemoverWouldComplete, | |
| 90 base::Unretained(this))); | |
| 91 } | |
| 82 } | 92 } |
| 93 | |
| 83 ~MultipleProfileDeletionObserver() override { | 94 ~MultipleProfileDeletionObserver() override { |
| 84 g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 95 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 85 RemoveObserver(this); | 96 RemoveObserver(this); |
| 86 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(nullptr); | 97 inhibitors_.clear(); |
| 87 } | 98 } |
| 99 | |
| 88 void Wait() { | 100 void Wait() { |
| 89 keep_alive_ = base::MakeUnique<ScopedKeepAlive>( | 101 keep_alive_ = base::MakeUnique<ScopedKeepAlive>( |
| 90 KeepAliveOrigin::PROFILE_HELPER, KeepAliveRestartOption::DISABLED); | 102 KeepAliveOrigin::PROFILE_HELPER, KeepAliveRestartOption::DISABLED); |
| 91 loop_.Run(); | 103 loop_.Run(); |
| 92 } | 104 } |
| 93 | 105 |
| 94 private: | 106 private: |
| 107 // TODO(https://crbug.com/704601): remove this code when bug is fixed. | |
| 108 class CompletionInhibitor : public BrowsingDataRemoverCompletionInhibitor { | |
| 109 public: | |
| 110 CompletionInhibitor(BrowsingDataRemover* remover, | |
| 111 const base::Closure& callback) | |
| 112 : BrowsingDataRemoverCompletionInhibitor(remover), | |
| 113 callback_(callback) {} | |
| 114 ~CompletionInhibitor() override {} | |
| 115 | |
| 116 // BrowsingDataRemoverCompletionInhibitor: | |
| 117 void OnBrowsingDataRemoverWouldComplete( | |
| 118 const base::Closure& continue_to_completion) override { | |
| 119 BrowsingDataRemoverCompletionInhibitor:: | |
| 120 OnBrowsingDataRemoverWouldComplete(continue_to_completion); | |
| 121 callback_.Run(); | |
| 122 } | |
| 123 | |
| 124 private: | |
| 125 base::Closure callback_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(CompletionInhibitor); | |
| 128 }; | |
| 129 | |
| 130 void HandleBrowsingDataRemoverWouldComplete() { | |
| 131 profiles_data_removed_count_++; | |
| 132 MaybeQuit(); | |
| 133 } | |
| 134 | |
| 95 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override { | 135 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override { |
| 96 profiles_created_count_++; | 136 profiles_created_count_++; |
| 97 MaybeQuit(); | 137 MaybeQuit(); |
| 98 } | 138 } |
| 99 | 139 |
| 100 // TODO(https://crbug.com/704601): remove this code when bug is fixed. | |
| 101 void OnBrowsingDataRemoverWouldComplete( | |
| 102 BrowsingDataRemoverImpl* remover, | |
| 103 const base::Closure& continue_to_completion) override { | |
| 104 continue_to_completion.Run(); | |
| 105 profiles_data_removed_count_++; | |
| 106 MaybeQuit(); | |
| 107 } | |
| 108 | |
| 109 void MaybeQuit() { | 140 void MaybeQuit() { |
| 110 DLOG(INFO) << profiles_created_count_ | 141 DLOG(INFO) << profiles_created_count_ |
| 111 << " profiles removed, and " | 142 << " profiles removed, and " |
| 112 << profiles_data_removed_count_ | 143 << profiles_data_removed_count_ |
| 113 << " profile data removed of expected " | 144 << " profile data removed of expected " |
| 114 << expected_count_; | 145 << expected_count_; |
| 115 if (profiles_created_count_ < expected_count_ || | 146 if (profiles_created_count_ < expected_count_ || |
| 116 profiles_data_removed_count_ < expected_count_) | 147 profiles_data_removed_count_ < expected_count_) |
| 117 return; | 148 return; |
| 118 | 149 |
| 119 EXPECT_EQ(expected_count_, profiles_created_count_); | 150 EXPECT_EQ(expected_count_, profiles_created_count_); |
| 120 EXPECT_EQ(expected_count_, profiles_data_removed_count_); | 151 EXPECT_EQ(expected_count_, profiles_data_removed_count_); |
| 121 | 152 |
| 122 keep_alive_.reset(); | 153 keep_alive_.reset(); |
| 123 loop_.Quit(); | 154 loop_.Quit(); |
| 124 } | 155 } |
| 125 | 156 |
| 157 std::list<CompletionInhibitor> inhibitors_; | |
| 158 | |
| 126 base::RunLoop loop_; | 159 base::RunLoop loop_; |
| 127 std::unique_ptr<ScopedKeepAlive> keep_alive_; | 160 std::unique_ptr<ScopedKeepAlive> keep_alive_; |
| 128 size_t expected_count_; | 161 size_t expected_count_; |
| 129 size_t profiles_created_count_; | 162 size_t profiles_created_count_; |
| 130 size_t profiles_data_removed_count_; | 163 size_t profiles_data_removed_count_; |
| 131 | 164 |
| 132 DISALLOW_COPY_AND_ASSIGN(MultipleProfileDeletionObserver); | 165 DISALLOW_COPY_AND_ASSIGN(MultipleProfileDeletionObserver); |
| 133 }; | 166 }; |
| 134 | 167 |
| 135 void EphemeralProfileCreationComplete(Profile* profile, | 168 void EphemeralProfileCreationComplete(Profile* profile, |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 | 671 |
| 639 EXPECT_FALSE(profile->HasOffTheRecordProfile()); | 672 EXPECT_FALSE(profile->HasOffTheRecordProfile()); |
| 640 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); | 673 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); |
| 641 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); | 674 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); |
| 642 // After destroying the incognito profile incognito preferences should be | 675 // After destroying the incognito profile incognito preferences should be |
| 643 // cleared so the default save path should be taken from the main profile. | 676 // cleared so the default save path should be taken from the main profile. |
| 644 EXPECT_FALSE(profile->GetOffTheRecordPrefs() | 677 EXPECT_FALSE(profile->GetOffTheRecordPrefs() |
| 645 ->GetFilePath(prefs::kSaveFileDefaultDirectory) | 678 ->GetFilePath(prefs::kSaveFileDefaultDirectory) |
| 646 .empty()); | 679 .empty()); |
| 647 } | 680 } |
| OLD | NEW |