| 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/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 const URLRow* row2 = NULL, | 429 const URLRow* row2 = NULL, |
| 430 const URLRow* row3 = NULL) { | 430 const URLRow* row3 = NULL) { |
| 431 URLRows rows; | 431 URLRows rows; |
| 432 rows.push_back(*row1); | 432 rows.push_back(*row1); |
| 433 if (row2) rows.push_back(*row2); | 433 if (row2) rows.push_back(*row2); |
| 434 if (row3) rows.push_back(*row3); | 434 if (row3) rows.push_back(*row3); |
| 435 | 435 |
| 436 if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) { | 436 if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) { |
| 437 scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails()); | 437 scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails()); |
| 438 details->changed_urls.swap(rows); | 438 details->changed_urls.swap(rows); |
| 439 BroadcastNotifications(type, details.PassAs<HistoryDetails>()); | 439 BroadcastNotifications(type, details.Pass()); |
| 440 } else if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) { | 440 } else if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) { |
| 441 for (URLRows::const_iterator it = rows.begin(); it != rows.end(); ++it) { | 441 for (URLRows::const_iterator it = rows.begin(); it != rows.end(); ++it) { |
| 442 scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails()); | 442 scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails()); |
| 443 details->row = *it; | 443 details->row = *it; |
| 444 BroadcastNotifications(type, details.PassAs<HistoryDetails>()); | 444 BroadcastNotifications(type, details.Pass()); |
| 445 } | 445 } |
| 446 } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | 446 } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
| 447 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 447 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); |
| 448 details->rows = rows; | 448 details->rows = rows; |
| 449 BroadcastNotifications(type, details.PassAs<HistoryDetails>()); | 449 BroadcastNotifications(type, details.Pass()); |
| 450 } else { | 450 } else { |
| 451 NOTREACHED(); | 451 NOTREACHED(); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 | 454 |
| 455 protected: | 455 protected: |
| 456 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, | 456 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, |
| 457 const base::string16& prefix) { | 457 const base::string16& prefix) { |
| 458 std::vector<KeywordSearchTermVisit> matching_terms; | 458 std::vector<KeywordSearchTermVisit> matching_terms; |
| 459 mem_backend_->db()->GetMostRecentKeywordSearchTerms( | 459 mem_backend_->db()->GetMostRecentKeywordSearchTerms( |
| (...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 URLRow row1(CreateTestTypedURL()); | 3141 URLRow row1(CreateTestTypedURL()); |
| 3142 URLRow row2(CreateAnotherTestTypedURL()); | 3142 URLRow row2(CreateAnotherTestTypedURL()); |
| 3143 URLRow row3(CreateTestNonTypedURL()); | 3143 URLRow row3(CreateTestNonTypedURL()); |
| 3144 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 3144 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 3145 &row1, &row2, &row3); | 3145 &row1, &row2, &row3); |
| 3146 | 3146 |
| 3147 // Now notify the in-memory database that all history has been deleted. | 3147 // Now notify the in-memory database that all history has been deleted. |
| 3148 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 3148 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); |
| 3149 details->all_history = true; | 3149 details->all_history = true; |
| 3150 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 3150 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 3151 details.PassAs<HistoryDetails>()); | 3151 details.Pass()); |
| 3152 | 3152 |
| 3153 // Expect that everything goes away. | 3153 // Expect that everything goes away. |
| 3154 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); | 3154 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); |
| 3155 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); | 3155 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); |
| 3156 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); | 3156 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); |
| 3157 } | 3157 } |
| 3158 | 3158 |
| 3159 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( | 3159 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( |
| 3160 URLRow* row1, | 3160 URLRow* row1, |
| 3161 URLRow* row2, | 3161 URLRow* row2, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3263 // Verify that the second term is no longer returned as result, and also check | 3263 // Verify that the second term is no longer returned as result, and also check |
| 3264 // at the low level that it is gone for good. The term corresponding to the | 3264 // at the low level that it is gone for good. The term corresponding to the |
| 3265 // first URLRow should not be affected. | 3265 // first URLRow should not be affected. |
| 3266 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3266 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
| 3267 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3267 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
| 3268 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3268 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
| 3269 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3269 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
| 3270 } | 3270 } |
| 3271 | 3271 |
| 3272 } // namespace history | 3272 } // namespace history |
| OLD | NEW |