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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
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_MODIFIED, source); | |
63 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); | 62 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
64 registrar_.Add( | 63 registrar_.Add( |
65 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, source); | 64 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, source); |
66 registrar_.Add( | 65 registrar_.Add( |
67 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source); | 66 this, chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED, source); |
68 } | 67 } |
69 | 68 |
70 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( | 69 void InMemoryHistoryBackend::DeleteAllSearchTermsForKeyword( |
71 KeywordID keyword_id) { | 70 KeywordID keyword_id) { |
72 // For simplicity, this will not remove the corresponding URLRows, but | 71 // For simplicity, this will not remove the corresponding URLRows, but |
73 // this is okay, as the main database does not do so either. | 72 // this is okay, as the main database does not do so either. |
74 db_->DeleteAllSearchTermsForKeyword(keyword_id); | 73 db_->DeleteAllSearchTermsForKeyword(keyword_id); |
75 } | 74 } |
76 | 75 |
77 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, | 76 void InMemoryHistoryBackend::OnURLVisited(HistoryService* history_service, |
78 ui::PageTransition transition, | 77 ui::PageTransition transition, |
79 const URLRow& row, | 78 const URLRow& row, |
80 const RedirectList& redirects, | 79 const RedirectList& redirects, |
81 base::Time visit_time) { | 80 base::Time visit_time) { |
82 OnURLVisitedOrModified(row); | 81 OnURLVisitedOrModified(row); |
83 } | 82 } |
84 | 83 |
| 84 void InMemoryHistoryBackend::OnURLsModified(HistoryService* history_service, |
| 85 const URLRows& changed_urls) { |
| 86 for (const auto& row : changed_urls) { |
| 87 OnURLVisitedOrModified(row); |
| 88 } |
| 89 } |
| 90 |
85 void InMemoryHistoryBackend::Observe( | 91 void InMemoryHistoryBackend::Observe( |
86 int type, | 92 int type, |
87 const content::NotificationSource& source, | 93 const content::NotificationSource& source, |
88 const content::NotificationDetails& details) { | 94 const content::NotificationDetails& details) { |
89 switch (type) { | 95 switch (type) { |
90 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: | 96 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: |
91 OnKeywordSearchTermUpdated( | 97 OnKeywordSearchTermUpdated( |
92 *content::Details<KeywordSearchUpdatedDetails>(details).ptr()); | 98 *content::Details<KeywordSearchUpdatedDetails>(details).ptr()); |
93 break; | 99 break; |
94 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED: | 100 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_DELETED: |
95 OnKeywordSearchTermDeleted( | 101 OnKeywordSearchTermDeleted( |
96 *content::Details<KeywordSearchDeletedDetails>(details).ptr()); | 102 *content::Details<KeywordSearchDeletedDetails>(details).ptr()); |
97 break; | 103 break; |
98 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: { | |
99 const URLsModifiedDetails* modified_details = | |
100 content::Details<URLsModifiedDetails>(details).ptr(); | |
101 URLRows::const_iterator it; | |
102 for (it = modified_details->changed_urls.begin(); | |
103 it != modified_details->changed_urls.end(); ++it) { | |
104 OnURLVisitedOrModified(*it); | |
105 } | |
106 break; | |
107 } | |
108 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | 104 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
109 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr()); | 105 OnURLsDeleted(*content::Details<URLsDeletedDetails>(details).ptr()); |
110 break; | 106 break; |
111 default: | 107 default: |
112 // For simplicity, the unit tests send us all notifications, even when | 108 // For simplicity, the unit tests send us all notifications, even when |
113 // we haven't registered for them, so don't assert here. | 109 // we haven't registered for them, so don't assert here. |
114 break; | 110 break; |
115 } | 111 } |
116 } | 112 } |
117 | 113 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 150 } |
155 | 151 |
156 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( | 152 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( |
157 const KeywordSearchDeletedDetails& details) { | 153 const KeywordSearchDeletedDetails& details) { |
158 // For simplicity, this will not remove the corresponding URLRow, but this is | 154 // For simplicity, this will not remove the corresponding URLRow, but this is |
159 // okay, as the main database does not do so either. | 155 // okay, as the main database does not do so either. |
160 db_->DeleteKeywordSearchTermForURL(details.url_row_id); | 156 db_->DeleteKeywordSearchTermForURL(details.url_row_id); |
161 } | 157 } |
162 | 158 |
163 } // namespace history | 159 } // namespace history |
OLD | NEW |