| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/history/history_notifications.h" | 14 #include "chrome/browser/history/history_notifications.h" |
| 15 #include "chrome/browser/history/in_memory_database.h" | 15 #include "chrome/browser/history/in_memory_database.h" |
| 16 #include "chrome/browser/history/in_memory_url_index.h" | 16 #include "chrome/browser/history/in_memory_url_index.h" |
| 17 #include "chrome/browser/history/url_database.h" | 17 #include "chrome/browser/history/url_database.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "content/common/notification_details.h" | 21 #include "content/common/notification_details.h" |
| 21 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
| 22 | 23 |
| 23 namespace history { | 24 namespace history { |
| 24 | 25 |
| 25 InMemoryHistoryBackend::InMemoryHistoryBackend() | 26 InMemoryHistoryBackend::InMemoryHistoryBackend() |
| 26 : profile_(NULL) { | 27 : profile_(NULL) { |
| 27 } | 28 } |
| 28 | 29 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 55 | 56 |
| 56 // TODO(evanm): this is currently necessitated by generate_profile, which | 57 // TODO(evanm): this is currently necessitated by generate_profile, which |
| 57 // runs without a browser process. generate_profile should really create | 58 // runs without a browser process. generate_profile should really create |
| 58 // a browser process, at which point this check can then be nuked. | 59 // a browser process, at which point this check can then be nuked. |
| 59 if (!g_browser_process) | 60 if (!g_browser_process) |
| 60 return; | 61 return; |
| 61 | 62 |
| 62 // Register for the notifications we care about. | 63 // Register for the notifications we care about. |
| 63 // We only want notifications for the associated profile. | 64 // We only want notifications for the associated profile. |
| 64 Source<Profile> source(profile_); | 65 Source<Profile> source(profile_); |
| 65 registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source); | 66 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source); |
| 66 registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source); | 67 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, |
| 67 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source); | |
| 68 registrar_.Add(this, NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED, | |
| 69 source); | 68 source); |
| 70 registrar_.Add(this, NotificationType::TEMPLATE_URL_REMOVED, source); | 69 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
| 70 registrar_.Add(this, |
| 71 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, |
| 72 source); |
| 73 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, source); |
| 71 } | 74 } |
| 72 | 75 |
| 73 void InMemoryHistoryBackend::Observe(NotificationType type, | 76 void InMemoryHistoryBackend::Observe(int type, |
| 74 const NotificationSource& source, | 77 const NotificationSource& source, |
| 75 const NotificationDetails& details) { | 78 const NotificationDetails& details) { |
| 76 switch (type.value) { | 79 switch (type) { |
| 77 case NotificationType::HISTORY_URL_VISITED: { | 80 case chrome::NOTIFICATION_HISTORY_URL_VISITED: { |
| 78 Details<history::URLVisitedDetails> visited_details(details); | 81 Details<history::URLVisitedDetails> visited_details(details); |
| 79 PageTransition::Type primary_type = | 82 PageTransition::Type primary_type = |
| 80 PageTransition::StripQualifier(visited_details->transition); | 83 PageTransition::StripQualifier(visited_details->transition); |
| 81 if (visited_details->row.typed_count() > 0 || | 84 if (visited_details->row.typed_count() > 0 || |
| 82 primary_type == PageTransition::KEYWORD || | 85 primary_type == PageTransition::KEYWORD || |
| 83 HasKeyword(visited_details->row.url())) { | 86 HasKeyword(visited_details->row.url())) { |
| 84 URLsModifiedDetails modified_details; | 87 URLsModifiedDetails modified_details; |
| 85 modified_details.changed_urls.push_back(visited_details->row); | 88 modified_details.changed_urls.push_back(visited_details->row); |
| 86 OnTypedURLsModified(modified_details); | 89 OnTypedURLsModified(modified_details); |
| 87 } | 90 } |
| 88 break; | 91 break; |
| 89 } | 92 } |
| 90 case NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED: | 93 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: |
| 91 OnKeywordSearchTermUpdated( | 94 OnKeywordSearchTermUpdated( |
| 92 *Details<history::KeywordSearchTermDetails>(details).ptr()); | 95 *Details<history::KeywordSearchTermDetails>(details).ptr()); |
| 93 break; | 96 break; |
| 94 case NotificationType::HISTORY_TYPED_URLS_MODIFIED: | 97 case chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED: |
| 95 OnTypedURLsModified( | 98 OnTypedURLsModified( |
| 96 *Details<history::URLsModifiedDetails>(details).ptr()); | 99 *Details<history::URLsModifiedDetails>(details).ptr()); |
| 97 break; | 100 break; |
| 98 case NotificationType::HISTORY_URLS_DELETED: | 101 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
| 99 OnURLsDeleted(*Details<history::URLsDeletedDetails>(details).ptr()); | 102 OnURLsDeleted(*Details<history::URLsDeletedDetails>(details).ptr()); |
| 100 break; | 103 break; |
| 101 case NotificationType::TEMPLATE_URL_REMOVED: | 104 case chrome::NOTIFICATION_TEMPLATE_URL_REMOVED: |
| 102 db_->DeleteAllSearchTermsForKeyword( | 105 db_->DeleteAllSearchTermsForKeyword( |
| 103 *(Details<TemplateURLID>(details).ptr())); | 106 *(Details<TemplateURLID>(details).ptr())); |
| 104 break; | 107 break; |
| 105 default: | 108 default: |
| 106 // For simplicity, the unit tests send us all notifications, even when | 109 // For simplicity, the unit tests send us all notifications, even when |
| 107 // we haven't registered for them, so don't assert here. | 110 // we haven't registered for them, so don't assert here. |
| 108 break; | 111 break; |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 | 114 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) { | 188 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) { |
| 186 URLID id = db_->GetRowForURL(url, NULL); | 189 URLID id = db_->GetRowForURL(url, NULL); |
| 187 if (!id) | 190 if (!id) |
| 188 return false; | 191 return false; |
| 189 | 192 |
| 190 return db_->GetKeywordSearchTermRow(id, NULL); | 193 return db_->GetKeywordSearchTermRow(id, NULL); |
| 191 } | 194 } |
| 192 | 195 |
| 193 } // namespace history | 196 } // namespace history |
| OLD | NEW |