| 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 "chrome/browser/profiles/profile_destroyer.h" | 5 #include "chrome/browser/profiles/profile_destroyer.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 9 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/policy/core/common/policy_service.h" |
| 13 #include "components/sync_preferences/pref_service_syncable.h" |
| 11 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
| 13 | 16 |
| 14 class TestingOffTheRecordDestructionProfile : public TestingProfile { | 17 class TestingOffTheRecordDestructionProfile : public TestingProfile { |
| 15 public: | 18 public: |
| 16 TestingOffTheRecordDestructionProfile() | 19 TestingOffTheRecordDestructionProfile() |
| 17 : TestingProfile( | 20 : TestingProfile( |
| 18 base::FilePath(), | 21 base::FilePath(), |
| 19 NULL, | 22 NULL, |
| 20 scoped_refptr<ExtensionSpecialStoragePolicy>() | 23 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 21 std::unique_ptr<sync_preferences::PrefServiceSyncable>(), | 24 scoped_refptr<ExtensionSpecialStoragePolicy>(), |
| 22 true, | 25 #endif |
| 23 TestingFactories()), | 26 std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 27 /*parent=*/NULL, |
| 28 /*guest_session=*/true, |
| 29 /*supervised_user_id=*/"", |
| 30 std::unique_ptr<policy::PolicyService>(), |
| 31 TestingFactories(), |
| 32 /*profile_name=*/""), |
| 24 destroyed_otr_profile_(false) { | 33 destroyed_otr_profile_(false) { |
| 25 set_incognito(true); | 34 ForceIncognito(true); |
| 26 } | 35 } |
| 27 void DestroyOffTheRecordProfile() override { | 36 void DestroyOffTheRecordProfile() override { |
| 28 destroyed_otr_profile_ = true; | 37 destroyed_otr_profile_ = true; |
| 29 } | 38 } |
| 30 bool destroyed_otr_profile_; | 39 bool destroyed_otr_profile_; |
| 31 | 40 |
| 32 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile); | 41 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile); |
| 33 }; | 42 }; |
| 34 | 43 |
| 35 class TestingOriginalDestructionProfile : public TestingProfile { | 44 class TestingOriginalDestructionProfile : public TestingProfile { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // I meant, ALL the render process hosts... :-) | 111 // I meant, ALL the render process hosts... :-) |
| 103 render_process_host2.release()->Cleanup(); | 112 render_process_host2.release()->Cleanup(); |
| 104 base::RunLoop().RunUntilIdle(); | 113 base::RunLoop().RunUntilIdle(); |
| 105 EXPECT_TRUE(off_the_record_profile_->destroyed_otr_profile_); | 114 EXPECT_TRUE(off_the_record_profile_->destroyed_otr_profile_); |
| 106 } | 115 } |
| 107 | 116 |
| 108 TEST_F(ProfileDestroyerTest, DelayOriginalProfileDestruction) { | 117 TEST_F(ProfileDestroyerTest, DelayOriginalProfileDestruction) { |
| 109 TestingOriginalDestructionProfile* original_profile = | 118 TestingOriginalDestructionProfile* original_profile = |
| 110 new TestingOriginalDestructionProfile; | 119 new TestingOriginalDestructionProfile; |
| 111 | 120 |
| 112 TestingOffTheRecordDestructionProfile* off_the_record_profile = | 121 std::unique_ptr<TestingOffTheRecordDestructionProfile> |
| 113 new TestingOffTheRecordDestructionProfile; | 122 off_the_record_profile(new TestingOffTheRecordDestructionProfile); |
| 123 |
| 114 | 124 |
| 115 original_profile->SetOffTheRecordProfile(off_the_record_profile); | 125 original_profile->SetOffTheRecordProfile(std::move(off_the_record_profile)); |
| 116 | 126 |
| 117 scoped_refptr<content::SiteInstance> instance1( | 127 scoped_refptr<content::SiteInstance> instance1(content::SiteInstance::Create( |
| 118 content::SiteInstance::Create(off_the_record_profile)); | 128 original_profile->GetOffTheRecordProfile())); |
| 119 std::unique_ptr<content::RenderProcessHost> render_process_host1; | 129 std::unique_ptr<content::RenderProcessHost> render_process_host1; |
| 120 render_process_host1.reset(instance1->GetProcess()); | 130 render_process_host1.reset(instance1->GetProcess()); |
| 121 ASSERT_TRUE(render_process_host1.get() != NULL); | 131 ASSERT_TRUE(render_process_host1.get() != NULL); |
| 122 | 132 |
| 123 // Trying to destroy the original profile should be delayed until associated | 133 // Trying to destroy the original profile should be delayed until associated |
| 124 // off the record profile is released by all render process hosts. | 134 // off the record profile is released by all render process hosts. |
| 125 ProfileDestroyer::DestroyProfileWhenAppropriate(original_profile); | 135 ProfileDestroyer::DestroyProfileWhenAppropriate(original_profile); |
| 126 EXPECT_NE(TestingOriginalDestructionProfile::kNull, | 136 EXPECT_NE(TestingOriginalDestructionProfile::kNull, |
| 127 TestingOriginalDestructionProfile::living_instance_); | 137 TestingOriginalDestructionProfile::living_instance_); |
| 128 EXPECT_FALSE(original_profile->destroyed_otr_profile_); | 138 EXPECT_FALSE(original_profile->destroyed_otr_profile_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 139 std::unique_ptr<content::RenderProcessHost> render_process_host2; | 149 std::unique_ptr<content::RenderProcessHost> render_process_host2; |
| 140 render_process_host2.reset(instance2->GetProcess()); | 150 render_process_host2.reset(instance2->GetProcess()); |
| 141 ASSERT_TRUE(render_process_host2.get() != NULL); | 151 ASSERT_TRUE(render_process_host2.get() != NULL); |
| 142 | 152 |
| 143 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); | 153 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); |
| 144 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); | 154 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); |
| 145 render_process_host2.release()->Cleanup(); | 155 render_process_host2.release()->Cleanup(); |
| 146 base::RunLoop().RunUntilIdle(); | 156 base::RunLoop().RunUntilIdle(); |
| 147 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); | 157 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); |
| 148 } | 158 } |
| OLD | NEW |