| 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/in_memory_history_backend.h" | 5 #include "chrome/browser/history/in_memory_history_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // TODO(evanm): this is currently necessitated by generate_profile, which | 53 // TODO(evanm): this is currently necessitated by generate_profile, which |
| 54 // runs without a browser process. generate_profile should really create | 54 // runs without a browser process. generate_profile should really create |
| 55 // a browser process, at which point this check can then be nuked. | 55 // a browser process, at which point this check can then be nuked. |
| 56 if (!g_browser_process) | 56 if (!g_browser_process) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 // Register for the notifications we care about. | 59 // Register for the notifications we care about. |
| 60 // We only want notifications for the associated profile. | 60 // We only want notifications for the associated profile. |
| 61 content::Source<Profile> source(profile_); | 61 content::Source<Profile> source(profile_); |
| 62 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); | 62 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
| 63 registrar_.Add( | |
| 64 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source); | |
| 65 } | 63 } |
| 66 | 64 |
| 67 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( | 65 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( |
| 68 KeywordID keyword_id) { | 66 KeywordID keyword_id) { |
| 69 // For simplicity, this will not remove the corresponding URLRows, but | 67 // For simplicity, this will not remove the corresponding URLRows, but |
| 70 // this is okay, as the main database does not do so either. | 68 // this is okay, as the main database does not do so either. |
| 71 db_->DeleteAllSearchTermsForKeyword(keyword_id); | 69 db_->DeleteAllSearchTermsForKeyword(keyword_id); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, | 72 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated( | 87 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated( |
| 90 HistoryService* history_service, | 88 HistoryService* history_service, |
| 91 const URLRow& row, | 89 const URLRow& row, |
| 92 KeywordID keyword_id, | 90 KeywordID keyword_id, |
| 93 const base::string16& term) { | 91 const base::string16& term) { |
| 94 DCHECK(row.id()); | 92 DCHECK(row.id()); |
| 95 db_->InsertOrUpdateURLRowByID(row); | 93 db_->InsertOrUpdateURLRowByID(row); |
| 96 db_->SetKeywordSearchTermsForURL(row.id(), keyword_id, term); | 94 db_->SetKeywordSearchTermsForURL(row.id(), keyword_id, term); |
| 97 } | 95 } |
| 98 | 96 |
| 97 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( |
| 98 HistoryService* history_service, |
| 99 URLID url_id) { |
| 100 // For simplicity, this will not remove the corresponding URLRow, but this is |
| 101 // okay, as the main database does not do so either. |
| 102 db_->DeleteKeywordSearchTermForURL(url_id); |
| 103 } |
| 104 |
| 99 void InMemoryHistoryBackend::Observe( | 105 void InMemoryHistoryBackend::Observe( |
| 100 int type, | 106 int type, |
| 101 const content::NotificationSource& source, | 107 const content::NotificationSource& source, |
| 102 const content::NotificationDetails& details) { | 108 const content::NotificationDetails& details) { |
| 103 switch (type) { | 109 switch (type) { |
| 104 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED: | |
| 105 OnKeywordSearchTermDeleted( | |
| 106 *content::Details<KeywordSearchDeletedDetails>(details).ptr()); | |
| 107 break; | |
| 108 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | 110 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
| 109 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr()); | 111 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr()); |
| 110 break; | 112 break; |
| 111 default: | 113 default: |
| 112 // For simplicity, the unit tests send us all notifications, even when | 114 // For simplicity, the unit tests send us all notifications, even when |
| 113 // we haven't registered for them, so don't assert here. | 115 // we haven't registered for them, so don't assert here. |
| 114 break; | 116 break; |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 138 | 140 |
| 139 // Delete all matching URLs in our database. | 141 // Delete all matching URLs in our database. |
| 140 for (URLRows::const_iterator row = details.rows.begin(); | 142 for (URLRows::const_iterator row = details.rows.begin(); |
| 141 row != details.rows.end(); ++row) { | 143 row != details.rows.end(); ++row) { |
| 142 // This will also delete the corresponding keyword search term. | 144 // This will also delete the corresponding keyword search term. |
| 143 // Ignore errors, as we typically only cache a subset of URLRows. | 145 // Ignore errors, as we typically only cache a subset of URLRows. |
| 144 db_->DeleteURLRow(row->id()); | 146 db_->DeleteURLRow(row->id()); |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 | 149 |
| 148 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( | |
| 149 const KeywordSearchDeletedDetails& details) { | |
| 150 // For simplicity, this will not remove the corresponding URLRow, but this is | |
| 151 // okay, as the main database does not do so either. | |
| 152 db_->DeleteKeywordSearchTermForURL(details.url_row_id); | |
| 153 } | |
| 154 | |
| 155 } // namespace history | 150 } // namespace history |
| OLD | NEW |