Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // TODO(evanm): this is currently necessitated by generate_profile, which | 44 // TODO(evanm): this is currently necessitated by generate_profile, which |
| 45 // runs without a browser process. generate_profile should really create | 45 // runs without a browser process. generate_profile should really create |
| 46 // a browser process, at which point this check can then be nuked. | 46 // a browser process, at which point this check can then be nuked. |
| 47 if (!g_browser_process) | 47 if (!g_browser_process) |
| 48 return; | 48 return; |
| 49 | 49 |
| 50 // Register for the notifications we care about. | 50 // Register for the notifications we care about. |
| 51 // We only want notifications for the associated profile. | 51 // We only want notifications for the associated profile. |
| 52 content::Source<Profile> source(profile_); | 52 content::Source<Profile> source(profile_); |
| 53 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source); | 53 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source); |
| 54 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, | 54 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 55 source); | 55 source); |
| 56 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); | 56 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); |
| 57 registrar_.Add(this, | 57 registrar_.Add(this, |
| 58 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, | 58 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, |
| 59 source); | 59 source); |
| 60 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, source); | 60 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, source); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void InMemoryHistoryBackend::Observe( | 63 void InMemoryHistoryBackend::Observe( |
| 64 int type, | 64 int type, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 75 URLsModifiedDetails modified_details; | 75 URLsModifiedDetails modified_details; |
| 76 modified_details.changed_urls.push_back(visited_details->row); | 76 modified_details.changed_urls.push_back(visited_details->row); |
| 77 OnTypedURLsModified(modified_details); | 77 OnTypedURLsModified(modified_details); |
| 78 } | 78 } |
| 79 break; | 79 break; |
| 80 } | 80 } |
| 81 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: | 81 case chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED: |
| 82 OnKeywordSearchTermUpdated( | 82 OnKeywordSearchTermUpdated( |
| 83 *content::Details<history::KeywordSearchTermDetails>(details).ptr()); | 83 *content::Details<history::KeywordSearchTermDetails>(details).ptr()); |
| 84 break; | 84 break; |
| 85 case chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED: | 85 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: |
| 86 OnTypedURLsModified( | 86 OnTypedURLsModified( |
| 87 *content::Details<history::URLsModifiedDetails>(details).ptr()); | 87 *content::Details<history::URLsModifiedDetails>(details).ptr()); |
| 88 break; | 88 break; |
| 89 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: | 89 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: |
| 90 OnURLsDeleted( | 90 OnURLsDeleted( |
| 91 *content::Details<history::URLsDeletedDetails>(details).ptr()); | 91 *content::Details<history::URLsDeletedDetails>(details).ptr()); |
| 92 break; | 92 break; |
| 93 case chrome::NOTIFICATION_TEMPLATE_URL_REMOVED: | 93 case chrome::NOTIFICATION_TEMPLATE_URL_REMOVED: |
| 94 db_->DeleteAllSearchTermsForKeyword( | 94 db_->DeleteAllSearchTermsForKeyword( |
| 95 *(content::Details<TemplateURLID>(details).ptr())); | 95 *(content::Details<TemplateURLID>(details).ptr())); |
| 96 break; | 96 break; |
| 97 default: | 97 default: |
| 98 // For simplicity, the unit tests send us all notifications, even when | 98 // For simplicity, the unit tests send us all notifications, even when |
| 99 // we haven't registered for them, so don't assert here. | 99 // we haven't registered for them, so don't assert here. |
| 100 break; | 100 break; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void InMemoryHistoryBackend::OnTypedURLsModified( | 104 void InMemoryHistoryBackend::OnTypedURLsModified( |
| 105 const URLsModifiedDetails& details) { | 105 const URLsModifiedDetails& details) { |
| 106 DCHECK(db_.get()); | 106 DCHECK(db_.get()); |
| 107 | 107 |
| 108 // Add or update the URLs. | 108 // Add or update the URLs. |
| 109 // | 109 // |
| 110 // TODO(brettw) currently the rows in the in-memory database don't match the | 110 // TODO(brettw) currently the rows in the in-memory database don't match the |
| 111 // IDs in the main database. This sucks. Instead of Add and Remove, we should | 111 // IDs in the main database. This sucks. Instead of Add and Remove, we should |
| 112 // have Sync(), which would take the ID if it's given and add it. | 112 // have Sync(), which would take the ID if it's given and add it. |
| 113 URLRows::const_iterator i; | 113 URLRows::const_iterator i; |
| 114 for (i = details.changed_urls.begin(); | 114 for (i = details.changed_urls.begin(); |
| 115 i != details.changed_urls.end(); i++) { | 115 i != details.changed_urls.end(); i++) { |
|
sky
2012/04/10 16:29:01
++i
mrossetti
2012/04/11 19:38:55
Done.
| |
| 116 URLID id = db_->GetRowForURL(i->url(), NULL); | 116 if (i->typed_count() > 0) { |
| 117 if (id) | 117 URLID id = db_->GetRowForURL(i->url(), NULL); |
| 118 db_->UpdateURLRow(id, *i); | 118 if (id) |
| 119 else | 119 db_->UpdateURLRow(id, *i); |
| 120 id = db_->AddURL(*i); | 120 else |
| 121 db_->AddURL(*i); | |
| 122 } | |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) { | 126 void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) { |
| 125 DCHECK(db_.get()); | 127 DCHECK(db_.get()); |
| 126 | 128 |
| 127 if (details.all_history) { | 129 if (details.all_history) { |
| 128 // When all history is deleted, the individual URLs won't be listed. Just | 130 // When all history is deleted, the individual URLs won't be listed. Just |
| 129 // create a new database to quickly clear everything out. | 131 // create a new database to quickly clear everything out. |
| 130 db_.reset(new InMemoryDatabase); | 132 db_.reset(new InMemoryDatabase); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 169 |
| 168 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) { | 170 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) { |
| 169 URLID id = db_->GetRowForURL(url, NULL); | 171 URLID id = db_->GetRowForURL(url, NULL); |
| 170 if (!id) | 172 if (!id) |
| 171 return false; | 173 return false; |
| 172 | 174 |
| 173 return db_->GetKeywordSearchTermRow(id, NULL); | 175 return db_->GetKeywordSearchTermRow(id, NULL); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace history | 178 } // namespace history |
| OLD | NEW |