Commit 7cb1f9cb authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_DESTROYED from IndependentOTRProfileManager

Bug: 268984
Change-Id: Id59283a4bde7a87a88345672b10d9db9bf9b9c17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869829Reviewed-by: default avatarBrandon Tolsch <btolsch@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708037}
parent 704e8e0c
...@@ -43,17 +43,15 @@ IndependentOTRProfileManager* IndependentOTRProfileManager::GetInstance() { ...@@ -43,17 +43,15 @@ IndependentOTRProfileManager* IndependentOTRProfileManager::GetInstance() {
std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration> std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration>
IndependentOTRProfileManager::CreateFromOriginalProfile( IndependentOTRProfileManager::CreateFromOriginalProfile(
Profile* profile, Profile* original_profile,
ProfileDestroyedCallback callback) { ProfileDestroyedCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(profile); DCHECK(original_profile);
DCHECK(!profile->IsOffTheRecord()); DCHECK(!original_profile->IsOffTheRecord());
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
if (!HasDependentProfiles(profile)) { if (!HasDependentProfiles(original_profile))
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, observed_original_profiles_.Add(original_profile);
content::Source<Profile>(profile)); auto* otr_profile = original_profile->CreateOffTheRecordProfile();
}
auto* otr_profile = profile->CreateOffTheRecordProfile();
auto entry = refcounts_map_.emplace(otr_profile, 1); auto entry = refcounts_map_.emplace(otr_profile, 1);
auto callback_entry = auto callback_entry =
callbacks_map_.emplace(otr_profile, std::move(callback)); callbacks_map_.emplace(otr_profile, std::move(callback));
...@@ -97,10 +95,8 @@ void IndependentOTRProfileManager::OnBrowserRemoved(Browser* browser) { ...@@ -97,10 +95,8 @@ void IndependentOTRProfileManager::OnBrowserRemoved(Browser* browser) {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, entry->first); base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, entry->first);
auto* original_profile = entry->first->GetOriginalProfile(); auto* original_profile = entry->first->GetOriginalProfile();
refcounts_map_.erase(entry); refcounts_map_.erase(entry);
if (!HasDependentProfiles(original_profile)) { if (!HasDependentProfiles(original_profile))
registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, observed_original_profiles_.Remove(original_profile);
content::Source<Profile>(original_profile));
}
} }
} }
...@@ -138,28 +134,22 @@ void IndependentOTRProfileManager::UnregisterProfile(Profile* profile) { ...@@ -138,28 +134,22 @@ void IndependentOTRProfileManager::UnregisterProfile(Profile* profile) {
auto* original_profile = profile->GetOriginalProfile(); auto* original_profile = profile->GetOriginalProfile();
ProfileDestroyer::DestroyProfileWhenAppropriate(entry->first); ProfileDestroyer::DestroyProfileWhenAppropriate(entry->first);
refcounts_map_.erase(entry); refcounts_map_.erase(entry);
if (!HasDependentProfiles(original_profile)) { if (!HasDependentProfiles(original_profile))
registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, observed_original_profiles_.Remove(original_profile);
content::Source<Profile>(original_profile));
}
} }
} }
void IndependentOTRProfileManager::Observe( void IndependentOTRProfileManager::OnProfileWillBeDestroyed(Profile* profile) {
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
for (auto it = callbacks_map_.begin(); it != callbacks_map_.end();) { for (auto it = callbacks_map_.begin(); it != callbacks_map_.end();) {
if (source != content::Source<Profile>(it->first->GetOriginalProfile())) { if (profile != it->first->GetOriginalProfile()) {
++it; ++it;
continue; continue;
} }
// If the registration is destroyed from within this callback, we don't want // If the registration is destroyed from within this callback, we don't want
// to double-erase. If it isn't, we still need to erase the callback entry. // to double-erase. If it isn't, we still need to erase the callback entry.
auto* profile = it->first; auto* otr_profile = it->first;
auto callback = std::move(it->second); auto callback = std::move(it->second);
it = callbacks_map_.erase(it); it = callbacks_map_.erase(it);
std::move(callback).Run(profile); std::move(callback).Run(otr_profile);
} }
} }
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile; class Profile;
...@@ -42,9 +43,8 @@ class Profile; ...@@ -42,9 +43,8 @@ class Profile;
// original profile is being destroyed. // original profile is being destroyed.
// //
// All methods must be called on the UI thread. // All methods must be called on the UI thread.
class IndependentOTRProfileManager final class IndependentOTRProfileManager final : public BrowserListObserver,
: public BrowserListObserver, public ProfileObserver {
public content::NotificationObserver {
public: public:
class OTRProfileRegistration { class OTRProfileRegistration {
public: public:
...@@ -84,21 +84,19 @@ class IndependentOTRProfileManager final ...@@ -84,21 +84,19 @@ class IndependentOTRProfileManager final
bool HasDependentProfiles(Profile* profile) const; bool HasDependentProfiles(Profile* profile) const;
void UnregisterProfile(Profile* profile); void UnregisterProfile(Profile* profile);
// chrome::BrowserListObserver overrides. // chrome::BrowserListObserver:
void OnBrowserAdded(Browser* browser) final; void OnBrowserAdded(Browser* browser) final;
void OnBrowserRemoved(Browser* browser) final; void OnBrowserRemoved(Browser* browser) final;
// content::NotificationObserver overrides. // ProfileObserver:
void Observe(int type, void OnProfileWillBeDestroyed(Profile* profile) final;
const content::NotificationSource& source,
const content::NotificationDetails& details) final;
// Counts the number of Browser instances referencing an independent OTR // Counts the number of Browser instances referencing an independent OTR
// profile plus 1 for the OTRProfileRegistration object that created it. // profile plus 1 for the OTRProfileRegistration object that created it.
base::flat_map<Profile*, int32_t> refcounts_map_; base::flat_map<Profile*, int32_t> refcounts_map_;
base::flat_map<Profile*, ProfileDestroyedCallback> callbacks_map_; base::flat_map<Profile*, ProfileDestroyedCallback> callbacks_map_;
content::NotificationRegistrar registrar_; ScopedObserver<Profile, ProfileObserver> observed_original_profiles_{this};
DISALLOW_COPY_AND_ASSIGN(IndependentOTRProfileManager); DISALLOW_COPY_AND_ASSIGN(IndependentOTRProfileManager);
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/media/router/presentation/independent_otr_profile_manager.h" #include "chrome/browser/media/router/presentation/independent_otr_profile_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/browser_list_observer.h"
...@@ -21,53 +23,33 @@ ...@@ -21,53 +23,33 @@
#include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
namespace content {
class NotificationDetails;
} // namespace content
namespace { namespace {
class ProfileDestructionWatcher final : public content::NotificationObserver { class ProfileDestructionWatcher : public ProfileObserver {
public: public:
using DestructionCallback = base::OnceClosure;
ProfileDestructionWatcher() = default; ProfileDestructionWatcher() = default;
~ProfileDestructionWatcher() override = default; ~ProfileDestructionWatcher() override = default;
// Watches for the destruction of |profile| and sets |destroyed| to true when void Watch(Profile* profile) { observed_profiles_.Add(profile); }
// that happens. |profile| can be any Profile object, but most tests below
// use it to watch for the cleanup of an OTR profile.
void Watch(Profile* profile, bool* destroyed) {
ASSERT_FALSE(*destroyed);
profile_ = profile;
destroyed_ = destroyed;
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_));
}
// content::NotificationObserver overrides. // ProfileObserver:
void Observe(int type, void OnProfileWillBeDestroyed(Profile* profile) override {
const content::NotificationSource& source, destroyed_ = true;
const content::NotificationDetails& details) override { observed_profiles_.Remove(profile);
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
DCHECK(content::Source<Profile>(profile_) == source);
*destroyed_ = true;
registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, source);
} }
bool destroyed() const { return destroyed_; }
private: private:
Profile* profile_; bool destroyed_ = false;
bool* destroyed_; ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ProfileDestructionWatcher);
}; };
// Waits for |browser| to be removed from BrowserList and then calls |callback|. // Waits for |browser| to be removed from BrowserList and then calls |callback|.
...@@ -140,7 +122,6 @@ class IndependentOTRProfileManagerTest : public InProcessBrowserTest { ...@@ -140,7 +122,6 @@ class IndependentOTRProfileManagerTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, CreateAndDestroy) { IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, CreateAndDestroy) {
ProfileDestructionWatcher watcher; ProfileDestructionWatcher watcher;
bool destroyed = false;
{ {
auto profile_registration = manager_->CreateFromOriginalProfile( auto profile_registration = manager_->CreateFromOriginalProfile(
browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed)); browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed));
...@@ -150,11 +131,11 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, CreateAndDestroy) { ...@@ -150,11 +131,11 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, CreateAndDestroy) {
EXPECT_NE(browser()->profile()->GetOffTheRecordProfile(), otr_profile); EXPECT_NE(browser()->profile()->GetOffTheRecordProfile(), otr_profile);
EXPECT_TRUE(otr_profile->IsOffTheRecord()); EXPECT_TRUE(otr_profile->IsOffTheRecord());
watcher.Watch(otr_profile, &destroyed); watcher.Watch(otr_profile);
} }
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed); EXPECT_TRUE(watcher.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
...@@ -181,21 +162,19 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -181,21 +162,19 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser1)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser1));
ASSERT_TRUE(base::Contains(*BrowserList::GetInstance(), otr_browser2)); ASSERT_TRUE(base::Contains(*BrowserList::GetInstance(), otr_browser2));
bool destroyed = false; watcher.Watch(otr_profile);
watcher.Watch(otr_profile, &destroyed);
base::RunLoop run_loop2; base::RunLoop run_loop2;
BrowserRemovedWaiter removed_waiter2(otr_browser2, BrowserRemovedWaiter removed_waiter2(otr_browser2,
run_loop2.QuitWhenIdleClosure()); run_loop2.QuitWhenIdleClosure());
otr_browser2->window()->Close(); otr_browser2->window()->Close();
run_loop2.Run(); run_loop2.Run();
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser2)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser2));
EXPECT_TRUE(destroyed); EXPECT_TRUE(watcher.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
DeleteImmediatelyWhenBrowsersAlreadyClosed) { DeleteImmediatelyWhenBrowsersAlreadyClosed) {
ProfileDestructionWatcher watcher; ProfileDestructionWatcher watcher;
bool destroyed = false;
{ {
auto profile_registration = manager_->CreateFromOriginalProfile( auto profile_registration = manager_->CreateFromOriginalProfile(
browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed)); browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed));
...@@ -218,19 +197,17 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -218,19 +197,17 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser1)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser1));
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser2)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser2));
watcher.Watch(otr_profile, &destroyed); watcher.Watch(otr_profile);
} }
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed); EXPECT_TRUE(watcher.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
CreateTwoFromSameProfile) { CreateTwoFromSameProfile) {
ProfileDestructionWatcher watcher1; ProfileDestructionWatcher watcher1;
ProfileDestructionWatcher watcher2; ProfileDestructionWatcher watcher2;
bool destroyed1 = false;
bool destroyed2 = false;
{ {
auto profile_registration1 = manager_->CreateFromOriginalProfile( auto profile_registration1 = manager_->CreateFromOriginalProfile(
browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed)); browser()->profile(), base::BindOnce(&OriginalProfileNeverDestroyed));
...@@ -242,13 +219,13 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -242,13 +219,13 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
ASSERT_NE(otr_profile1, otr_profile2); ASSERT_NE(otr_profile1, otr_profile2);
watcher1.Watch(otr_profile1, &destroyed1); watcher1.Watch(otr_profile1);
watcher2.Watch(otr_profile2, &destroyed2); watcher2.Watch(otr_profile2);
} }
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed1); EXPECT_TRUE(watcher1.destroyed());
EXPECT_TRUE(destroyed2); EXPECT_TRUE(watcher2.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
...@@ -270,8 +247,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -270,8 +247,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
ASSERT_NE(original_profile.get(), otr_profile); ASSERT_NE(original_profile.get(), otr_profile);
EXPECT_NE(original_profile->GetOffTheRecordProfile(), otr_profile); EXPECT_NE(original_profile->GetOffTheRecordProfile(), otr_profile);
bool destroyed = false; watcher.Watch(otr_profile);
watcher.Watch(otr_profile, &destroyed);
// Run tasks to ensure that Mojo connections are created before the profile is // Run tasks to ensure that Mojo connections are created before the profile is
// destroyed. // destroyed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -279,7 +255,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -279,7 +255,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
// |original_profile| being destroyed should trigger the dependent OTR // |original_profile| being destroyed should trigger the dependent OTR
// profile to be destroyed. // profile to be destroyed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed); EXPECT_TRUE(watcher.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
...@@ -302,10 +278,8 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -302,10 +278,8 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
auto profile_owner2 = RegistrationOwner(manager_, original_profile.get()); auto profile_owner2 = RegistrationOwner(manager_, original_profile.get());
auto* otr_profile2 = profile_owner2.profile(); auto* otr_profile2 = profile_owner2.profile();
bool destroyed1 = false; watcher1.Watch(otr_profile1);
bool destroyed2 = false; watcher2.Watch(otr_profile2);
watcher1.Watch(otr_profile1, &destroyed1);
watcher2.Watch(otr_profile2, &destroyed2);
// Run tasks to ensure that Mojo connections are created before the profile is // Run tasks to ensure that Mojo connections are created before the profile is
// destroyed. // destroyed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -313,16 +287,14 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -313,16 +287,14 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
// |original_profile| being destroyed should trigger the dependent OTR // |original_profile| being destroyed should trigger the dependent OTR
// profiles to be destroyed. // profiles to be destroyed.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed1); EXPECT_TRUE(watcher1.destroyed());
EXPECT_TRUE(destroyed2); EXPECT_TRUE(watcher2.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
BrowserClosingDoesntRemoveProfileObserver) { BrowserClosingDoesntRemoveProfileObserver) {
ProfileDestructionWatcher watcher1; ProfileDestructionWatcher watcher1;
ProfileDestructionWatcher watcher2; ProfileDestructionWatcher watcher2;
bool destroyed1 = false;
bool destroyed2 = false;
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
base::ScopedTempDir temp_dir; base::ScopedTempDir temp_dir;
...@@ -341,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -341,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
auto* otr_profile2 = profile_owner2.profile(); auto* otr_profile2 = profile_owner2.profile();
otr_browser = CreateBrowser(otr_profile2); otr_browser = CreateBrowser(otr_profile2);
watcher2.Watch(otr_profile2, &destroyed2); watcher2.Watch(otr_profile2);
} }
base::RunLoop run_loop; base::RunLoop run_loop;
BrowserRemovedWaiter removed_waiter(otr_browser, BrowserRemovedWaiter removed_waiter(otr_browser,
...@@ -349,12 +321,12 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -349,12 +321,12 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
otr_browser->window()->Close(); otr_browser->window()->Close();
run_loop.Run(); run_loop.Run();
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser));
EXPECT_TRUE(destroyed2); EXPECT_TRUE(watcher2.destroyed());
watcher1.Watch(otr_profile1, &destroyed1); watcher1.Watch(otr_profile1);
original_profile.reset(); original_profile.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(destroyed1); EXPECT_TRUE(watcher1.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
...@@ -369,15 +341,14 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, ...@@ -369,15 +341,14 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest,
otr_browser = CreateBrowser(otr_profile); otr_browser = CreateBrowser(otr_profile);
} }
bool destroyed = false; watcher.Watch(otr_profile);
watcher.Watch(otr_profile, &destroyed);
base::RunLoop run_loop; base::RunLoop run_loop;
BrowserRemovedWaiter removed_waiter(otr_browser, BrowserRemovedWaiter removed_waiter(otr_browser,
run_loop.QuitWhenIdleClosure()); run_loop.QuitWhenIdleClosure());
otr_browser->window()->Close(); otr_browser->window()->Close();
run_loop.Run(); run_loop.Run();
ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser)); ASSERT_FALSE(base::Contains(*BrowserList::GetInstance(), otr_browser));
EXPECT_TRUE(destroyed); EXPECT_TRUE(watcher.destroyed());
} }
IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, Notifications) { IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, Notifications) {
...@@ -398,12 +369,4 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, Notifications) { ...@@ -398,12 +369,4 @@ IN_PROC_BROWSER_TEST_F(IndependentOTRProfileManagerTest, Notifications) {
EXPECT_FALSE(profile->HasOffTheRecordProfile()); EXPECT_FALSE(profile->HasOffTheRecordProfile());
EXPECT_TRUE(otr_profile->IsOffTheRecord()); EXPECT_TRUE(otr_profile->IsOffTheRecord());
EXPECT_TRUE(otr_profile->IsIndependentOffTheRecordProfile()); EXPECT_TRUE(otr_profile->IsIndependentOffTheRecordProfile());
// Destroy the OTR profile.
content::WindowedNotificationObserver profile_destroyed_observer(
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(otr_profile));
profile_registration.reset();
profile_destroyed_observer.Wait();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment