Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/history/in_memory_history_backend.cc

Issue 8275004: Revert 105300 - HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/url_database.h" 17 #include "chrome/browser/history/url_database.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h"
19 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
20 #include "content/common/notification_source.h" 22 #include "content/common/notification_source.h"
21 23
22 namespace history { 24 namespace history {
23 25
24 InMemoryHistoryBackend::InMemoryHistoryBackend() 26 InMemoryHistoryBackend::InMemoryHistoryBackend()
25 : profile_(NULL) { 27 : profile_(NULL) {
26 } 28 }
27 29
28 InMemoryHistoryBackend::~InMemoryHistoryBackend() {} 30 InMemoryHistoryBackend::~InMemoryHistoryBackend() {
31 if (index_.get())
32 index_->ShutDown();
33 }
29 34
30 bool InMemoryHistoryBackend::Init(const FilePath& history_filename, 35 bool InMemoryHistoryBackend::Init(const FilePath& history_filename,
31 const FilePath& history_dir, 36 const FilePath& history_dir,
32 URLDatabase* db, 37 URLDatabase* db,
33 const std::string& languages) { 38 const std::string& languages) {
34 db_.reset(new InMemoryDatabase); 39 db_.reset(new InMemoryDatabase);
35 return db_->InitFromDisk(history_filename); 40 bool success = db_->InitFromDisk(history_filename);
41 if (!CommandLine::ForCurrentProcess()->HasSwitch(
42 switches::kDisableHistoryQuickProvider)) {
43 index_.reset(new InMemoryURLIndex(history_dir));
44 index_->Init(db, languages);
45 }
46 return success;
36 } 47 }
37 48
38 void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) { 49 void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) {
39 if (!db_.get()) { 50 if (!db_.get()) {
40 NOTREACHED(); 51 NOTREACHED();
41 return; 52 return;
42 } 53 }
43 54
44 profile_ = profile; 55 profile_ = profile;
45 56
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // IDs in the main database. This sucks. Instead of Add and Remove, we should 122 // 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. 123 // have Sync(), which would take the ID if it's given and add it.
113 std::vector<history::URLRow>::const_iterator i; 124 std::vector<history::URLRow>::const_iterator i;
114 for (i = details.changed_urls.begin(); 125 for (i = details.changed_urls.begin();
115 i != details.changed_urls.end(); i++) { 126 i != details.changed_urls.end(); i++) {
116 URLID id = db_->GetRowForURL(i->url(), NULL); 127 URLID id = db_->GetRowForURL(i->url(), NULL);
117 if (id) 128 if (id)
118 db_->UpdateURLRow(id, *i); 129 db_->UpdateURLRow(id, *i);
119 else 130 else
120 id = db_->AddURL(*i); 131 id = db_->AddURL(*i);
132 if (index_.get())
133 index_->UpdateURL(id, *i);
121 } 134 }
122 } 135 }
123 136
124 void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) { 137 void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) {
138 DCHECK(db_.get());
139
125 if (details.all_history) { 140 if (details.all_history) {
126 // When all history is deleted, the individual URLs won't be listed. Just 141 // When all history is deleted, the individual URLs won't be listed. Just
127 // create a new database to quickly clear everything out. 142 // create a new database to quickly clear everything out.
128 db_.reset(new InMemoryDatabase); 143 db_.reset(new InMemoryDatabase);
129 if (!db_->InitFromScratch()) 144 if (!db_->InitFromScratch())
130 db_.reset(); 145 db_.reset();
146 if (index_.get())
147 index_->ReloadFromHistory(db_.get(), true);
131 return; 148 return;
132 } 149 }
133 150
134 // Delete all matching URLs in our database. 151 // Delete all matching URLs in our database.
135 for (std::vector<URLRow>::const_iterator row = details.rows.begin(); 152 for (std::set<GURL>::const_iterator i = details.urls.begin();
136 row != details.rows.end(); ++row) { 153 i != details.urls.end(); ++i) {
137 // We typically won't have most of them since we only have a subset of 154 URLID id = db_->GetRowForURL(*i, NULL);
138 // history, so ignore errors. 155 if (id) {
139 db_->DeleteURLRow(row->id()); 156 // We typically won't have most of them since we only have a subset of
157 // history, so ignore errors.
158 db_->DeleteURLRow(id);
159 if (index_.get())
160 index_->DeleteURL(id);
161 }
140 } 162 }
141 } 163 }
142 164
143 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated( 165 void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
144 const KeywordSearchTermDetails& details) { 166 const KeywordSearchTermDetails& details) {
145 // The url won't exist for new search terms (as the user hasn't typed it), so 167 // The url won't exist for new search terms (as the user hasn't typed it), so
146 // we force it to be added. If we end up adding a URL it won't be 168 // we force it to be added. If we end up adding a URL it won't be
147 // autocompleted as the typed count is 0. 169 // autocompleted as the typed count is 0.
148 URLRow url_row; 170 URLRow url_row;
149 URLID url_id; 171 URLID url_id;
(...skipping 15 matching lines...) Expand all
165 187
166 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) { 188 bool InMemoryHistoryBackend::HasKeyword(const GURL& url) {
167 URLID id = db_->GetRowForURL(url, NULL); 189 URLID id = db_->GetRowForURL(url, NULL);
168 if (!id) 190 if (!id)
169 return false; 191 return false;
170 192
171 return db_->GetKeywordSearchTermRow(id, NULL); 193 return db_->GetKeywordSearchTermRow(id, NULL);
172 } 194 }
173 195
174 } // namespace history 196 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_history_backend.h ('k') | chrome/browser/history/in_memory_url_index.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698