| 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/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 // variables. We need to ensure that the profile is destroyed, and that | 496 // variables. We need to ensure that the profile is destroyed, and that |
| 497 // the message loop is cleared out, before destroying the threads and loop. | 497 // the message loop is cleared out, before destroying the threads and loop. |
| 498 // Otherwise we leak memory. | 498 // Otherwise we leak memory. |
| 499 profile_.reset(); | 499 profile_.reset(); |
| 500 message_loop_.RunAllPending(); | 500 message_loop_.RunAllPending(); |
| 501 } | 501 } |
| 502 | 502 |
| 503 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 503 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 504 int remove_mask, | 504 int remove_mask, |
| 505 bool include_protected_origins) { | 505 bool include_protected_origins) { |
| 506 BrowsingDataRemover* remover = new BrowsingDataRemover( | 506 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( |
| 507 profile_.get(), period, | 507 profile_.get(), period); |
| 508 // Pick a time that's a bit into the future, since there could be | |
| 509 // pending writes. | |
| 510 base::Time::Now() + base::TimeDelta::FromSeconds(10)); | |
| 511 remover->OverrideQuotaManagerForTesting(GetMockManager()); | 508 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 512 | 509 |
| 513 AwaitCompletionHelper await_completion; | 510 AwaitCompletionHelper await_completion; |
| 514 remover->AddObserver(&await_completion); | 511 remover->AddObserver(&await_completion); |
| 515 | 512 |
| 516 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 513 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 517 | 514 |
| 518 // BrowsingDataRemover deletes itself when it completes. | 515 // BrowsingDataRemover deletes itself when it completes. |
| 519 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; | 516 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; |
| 520 if (include_protected_origins) | 517 if (include_protected_origins) |
| 521 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; | 518 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; |
| 522 remover->Remove(remove_mask, origin_set_mask); | 519 remover->Remove(remove_mask, origin_set_mask); |
| 523 await_completion.BlockUntilNotified(); | 520 await_completion.BlockUntilNotified(); |
| 524 } | 521 } |
| 525 | 522 |
| 526 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, | 523 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 527 int remove_mask, | 524 int remove_mask, |
| 528 const GURL& remove_origin) { | 525 const GURL& remove_origin) { |
| 529 BrowsingDataRemover* remover = new BrowsingDataRemover( | 526 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( |
| 530 profile_.get(), period, | 527 profile_.get(), period); |
| 531 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | |
| 532 remover->OverrideQuotaManagerForTesting(GetMockManager()); | 528 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 533 | 529 |
| 534 AwaitCompletionHelper await_completion; | 530 AwaitCompletionHelper await_completion; |
| 535 remover->AddObserver(&await_completion); | 531 remover->AddObserver(&await_completion); |
| 536 | 532 |
| 537 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 533 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 538 | 534 |
| 539 // BrowsingDataRemover deletes itself when it completes. | 535 // BrowsingDataRemover deletes itself when it completes. |
| 540 remover->RemoveImpl(remove_mask, remove_origin, | 536 remover->RemoveImpl(remove_mask, remove_origin, |
| 541 BrowsingDataHelper::UNPROTECTED_WEB); | 537 BrowsingDataHelper::UNPROTECTED_WEB); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, | 1183 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 1188 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); | 1184 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); |
| 1189 | 1185 |
| 1190 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 1186 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1191 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 1187 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 1192 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); | 1188 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 1193 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); | 1189 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1194 } | 1190 } |
| 1195 | 1191 |
| 1196 // Verify that clearing autofill form data works. | 1192 // Verify that clearing autofill form data works. |
| 1197 TEST_F(BrowsingDataRemoverTest, AutofillRemoval) { | 1193 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) { |
| 1198 GetProfile()->CreateWebDataService(); | 1194 GetProfile()->CreateWebDataService(); |
| 1199 RemoveAutofillTester tester(GetProfile()); | 1195 RemoveAutofillTester tester(GetProfile()); |
| 1200 | 1196 |
| 1201 ASSERT_FALSE(tester.HasProfile()); | 1197 ASSERT_FALSE(tester.HasProfile()); |
| 1202 tester.AddProfile(); | 1198 tester.AddProfile(); |
| 1203 ASSERT_TRUE(tester.HasProfile()); | 1199 ASSERT_TRUE(tester.HasProfile()); |
| 1204 | 1200 |
| 1205 BlockUntilBrowsingDataRemoved( | 1201 BlockUntilBrowsingDataRemoved( |
| 1206 BrowsingDataRemover::LAST_HOUR, | 1202 BrowsingDataRemover::LAST_HOUR, |
| 1207 BrowsingDataRemover::REMOVE_FORM_DATA, false); | 1203 BrowsingDataRemover::REMOVE_FORM_DATA, false); |
| 1208 | 1204 |
| 1209 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); | 1205 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); |
| 1210 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 1206 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 1211 ASSERT_FALSE(tester.HasProfile()); | 1207 ASSERT_FALSE(tester.HasProfile()); |
| 1212 } | 1208 } |
| 1209 |
| 1210 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) { |
| 1211 GetProfile()->CreateWebDataService(); |
| 1212 RemoveAutofillTester tester(GetProfile()); |
| 1213 |
| 1214 ASSERT_FALSE(tester.HasProfile()); |
| 1215 tester.AddProfile(); |
| 1216 ASSERT_TRUE(tester.HasProfile()); |
| 1217 |
| 1218 BlockUntilBrowsingDataRemoved( |
| 1219 BrowsingDataRemover::EVERYTHING, |
| 1220 BrowsingDataRemover::REMOVE_FORM_DATA, false); |
| 1221 |
| 1222 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); |
| 1223 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 1224 ASSERT_FALSE(tester.HasProfile()); |
| 1225 } |
| OLD | NEW |