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

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

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