Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/profiles/profile_manager_browsertest.cc

Issue 2802013002: Move BrowsingDataRemoverImpl:: CompletionInhibitor to the public interface (Closed)
Patch Set: Finishing after shutdown is still OK. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" 15 #include "chrome/browser/browsing_data/browsing_data_remover.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
15 #include "chrome/browser/lifetime/keep_alive_types.h" 17 #include "chrome/browser/lifetime/keep_alive_types.h"
16 #include "chrome/browser/lifetime/scoped_keep_alive.h" 18 #include "chrome/browser/lifetime/scoped_keep_alive.h"
17 #include "chrome/browser/password_manager/password_store_factory.h" 19 #include "chrome/browser/password_manager/password_store_factory.h"
18 #include "chrome/browser/profiles/profile_attributes_entry.h" 20 #include "chrome/browser/profiles/profile_attributes_entry.h"
19 #include "chrome/browser/profiles/profile_attributes_storage.h" 21 #include "chrome/browser/profiles/profile_attributes_storage.h"
20 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/profiles/profile_window.h" 23 #include "chrome/browser/profiles/profile_window.h"
22 #include "chrome/browser/profiles/profiles_state.h" 24 #include "chrome/browser/profiles/profiles_state.h"
23 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U); 63 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U);
62 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 64 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U);
63 if (status == Profile::CREATE_STATUS_INITIALIZED) 65 if (status == Profile::CREATE_STATUS_INITIALIZED)
64 base::MessageLoop::current()->QuitWhenIdle(); 66 base::MessageLoop::current()->QuitWhenIdle();
65 } 67 }
66 68
67 // An observer that returns back to test code after one or more profiles was 69 // 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 70 // deleted. It also create ScopedKeepAlive object to prevent browser shutdown
69 // started in case browser has become windowless. 71 // started in case browser has become windowless.
70 class MultipleProfileDeletionObserver 72 class MultipleProfileDeletionObserver
71 : public BrowsingDataRemoverImpl::CompletionInhibitor, 73 : public ProfileAttributesStorage::Observer {
72 public ProfileAttributesStorage::Observer {
73 public: 74 public:
74 explicit MultipleProfileDeletionObserver(size_t expected_count) 75 explicit MultipleProfileDeletionObserver(size_t expected_count)
75 : expected_count_(expected_count), 76 : expected_count_(expected_count),
76 profiles_created_count_(0), 77 profiles_created_count_(0),
77 profiles_data_removed_count_(0) { 78 profiles_data_removed_count_(0) {
78 EXPECT_GT(expected_count_, 0u); 79 EXPECT_GT(expected_count_, 0u);
79 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 80 ProfileManager* profile_manager = g_browser_process->profile_manager();
80 AddObserver(this); 81 profile_manager->GetProfileAttributesStorage().AddObserver(this);
81 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(this); 82
83 base::Callback<void(const base::Closure&)> would_complete_callback =
84 base::Bind(&MultipleProfileDeletionObserver::
85 OnBrowsingDataRemoverWouldComplete,
86 base::Unretained(this));
87 for (Profile* profile : profile_manager->GetLoadedProfiles()) {
88 BrowsingDataRemoverFactory::GetForBrowserContext(profile)
89 ->SetWouldCompleteCallbackForTesting(would_complete_callback);
90 }
82 } 91 }
92
83 ~MultipleProfileDeletionObserver() override { 93 ~MultipleProfileDeletionObserver() override {
84 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 94 g_browser_process->profile_manager()->GetProfileAttributesStorage().
85 RemoveObserver(this); 95 RemoveObserver(this);
86 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(nullptr);
87 } 96 }
97
88 void Wait() { 98 void Wait() {
89 keep_alive_ = base::MakeUnique<ScopedKeepAlive>( 99 keep_alive_ = base::MakeUnique<ScopedKeepAlive>(
90 KeepAliveOrigin::PROFILE_HELPER, KeepAliveRestartOption::DISABLED); 100 KeepAliveOrigin::PROFILE_HELPER, KeepAliveRestartOption::DISABLED);
91 loop_.Run(); 101 loop_.Run();
92 } 102 }
93 103
94 private: 104 private:
95 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override { 105 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override {
96 profiles_created_count_++; 106 profiles_created_count_++;
97 MaybeQuit(); 107 MaybeQuit();
98 } 108 }
99 109
100 // TODO(https://crbug.com/704601): remove this code when bug is fixed. 110 // TODO(https://crbug.com/704601): remove this code when bug is fixed.
101 void OnBrowsingDataRemoverWouldComplete( 111 void OnBrowsingDataRemoverWouldComplete(
102 BrowsingDataRemoverImpl* remover, 112 const base::Closure& continue_to_completion) {
103 const base::Closure& continue_to_completion) override {
104 continue_to_completion.Run(); 113 continue_to_completion.Run();
105 profiles_data_removed_count_++; 114 profiles_data_removed_count_++;
106 MaybeQuit(); 115 MaybeQuit();
107 } 116 }
108 117
109 void MaybeQuit() { 118 void MaybeQuit() {
110 DLOG(INFO) << profiles_created_count_ 119 DLOG(INFO) << profiles_created_count_
111 << " profiles removed, and " 120 << " profiles removed, and "
112 << profiles_data_removed_count_ 121 << profiles_data_removed_count_
113 << " profile data removed of expected " 122 << " profile data removed of expected "
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 647
639 EXPECT_FALSE(profile->HasOffTheRecordProfile()); 648 EXPECT_FALSE(profile->HasOffTheRecordProfile());
640 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); 649 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile));
641 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); 650 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
642 // After destroying the incognito profile incognito preferences should be 651 // After destroying the incognito profile incognito preferences should be
643 // cleared so the default save path should be taken from the main profile. 652 // cleared so the default save path should be taken from the main profile.
644 EXPECT_FALSE(profile->GetOffTheRecordPrefs() 653 EXPECT_FALSE(profile->GetOffTheRecordPrefs()
645 ->GetFilePath(prefs::kSaveFileDefaultDirectory) 654 ->GetFilePath(prefs::kSaveFileDefaultDirectory)
646 .empty()); 655 .empty());
647 } 656 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698