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

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

Issue 10217010: Completed the code path from AndroidProviderService to HistoryBackend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Init Created 8 years, 8 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) 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/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/history/visit_filter.h" 29 #include "chrome/browser/history/visit_filter.h"
30 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/download_persistent_store_info.h" 33 #include "content/public/browser/download_persistent_store_info.h"
34 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
35 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
36 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
37 #include "net/base/registry_controlled_domain.h" 37 #include "net/base/registry_controlled_domain.h"
38 38
39 #if defined(OS_ANDROID)
40 #include "chrome/browser/history/android/android_provider_backend.h"
41 #endif
42
39 using base::Time; 43 using base::Time;
40 using base::TimeDelta; 44 using base::TimeDelta;
41 using base::TimeTicks; 45 using base::TimeTicks;
42 46
43 /* The HistoryBackend consists of a number of components: 47 /* The HistoryBackend consists of a number of components:
44 48
45 HistoryDatabase (stores past 3 months of history) 49 HistoryDatabase (stores past 3 months of history)
46 URLDatabase (stores a list of URLs) 50 URLDatabase (stores a list of URLs)
47 DownloadDatabase (stores a list of downloads) 51 DownloadDatabase (stores a list of downloads)
48 VisitDatabase (stores a list of visits for the URLs) 52 VisitDatabase (stores a list of visits for the URLs)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 recent_redirects_(kMaxRedirectCount), 214 recent_redirects_(kMaxRedirectCount),
211 backend_destroy_message_loop_(NULL), 215 backend_destroy_message_loop_(NULL),
212 segment_queried_(false), 216 segment_queried_(false),
213 bookmark_service_(bookmark_service) { 217 bookmark_service_(bookmark_service) {
214 } 218 }
215 219
216 HistoryBackend::~HistoryBackend() { 220 HistoryBackend::~HistoryBackend() {
217 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 221 DCHECK(!scheduled_commit_) << "Deleting without cleanup";
218 ReleaseDBTasks(); 222 ReleaseDBTasks();
219 223
224 #if defined(OS_ANDROID)
225 // Release AndroidProviderBackend before other objects.
226 android_provider_backend_.reset();
227 #endif
228
220 // First close the databases before optionally running the "destroy" task. 229 // First close the databases before optionally running the "destroy" task.
221 if (db_.get()) { 230 if (db_.get()) {
222 // Commit the long-running transaction. 231 // Commit the long-running transaction.
223 db_->CommitTransaction(); 232 db_->CommitTransaction();
224 db_.reset(); 233 db_.reset();
225 } 234 }
226 if (thumbnail_db_.get()) { 235 if (thumbnail_db_.get()) {
227 thumbnail_db_->CommitTransaction(); 236 thumbnail_db_->CommitTransaction();
228 thumbnail_db_.reset(); 237 thumbnail_db_.reset();
229 } 238 }
230 if (archived_db_.get()) { 239 if (archived_db_.get()) {
231 archived_db_->CommitTransaction(); 240 archived_db_->CommitTransaction();
232 archived_db_.reset(); 241 archived_db_.reset();
233 } 242 }
234 if (text_database_.get()) { 243 if (text_database_.get()) {
235 text_database_->CommitTransaction(); 244 text_database_->CommitTransaction();
236 text_database_.reset(); 245 text_database_.reset();
237 } 246 }
238 247
239 if (!backend_destroy_task_.is_null()) { 248 if (!backend_destroy_task_.is_null()) {
240 // Notify an interested party (typically a unit test) that we're done. 249 // Notify an interested party (typically a unit test) that we're done.
241 DCHECK(backend_destroy_message_loop_); 250 DCHECK(backend_destroy_message_loop_);
242 backend_destroy_message_loop_->PostTask(FROM_HERE, backend_destroy_task_); 251 backend_destroy_message_loop_->PostTask(FROM_HERE, backend_destroy_task_);
243 } 252 }
253
254 #if defined(OS_ANDROID)
255 file_util::Delete(GetAndroidCacheFileName(), false);
256 #endif
244 } 257 }
245 258
246 void HistoryBackend::Init(const std::string& languages, bool force_fail) { 259 void HistoryBackend::Init(const std::string& languages, bool force_fail) {
247 if (!force_fail) 260 if (!force_fail)
248 InitImpl(languages); 261 InitImpl(languages);
249 delegate_->DBLoaded(id_); 262 delegate_->DBLoaded(id_);
250 } 263 }
251 264
252 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop, 265 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop,
253 const base::Closure& task) { 266 const base::Closure& task) {
(...skipping 22 matching lines...) Expand all
276 } 289 }
277 290
278 FilePath HistoryBackend::GetFaviconsFileName() const { 291 FilePath HistoryBackend::GetFaviconsFileName() const {
279 return history_dir_.Append(chrome::kFaviconsFilename); 292 return history_dir_.Append(chrome::kFaviconsFilename);
280 } 293 }
281 294
282 FilePath HistoryBackend::GetArchivedFileName() const { 295 FilePath HistoryBackend::GetArchivedFileName() const {
283 return history_dir_.Append(chrome::kArchivedHistoryFilename); 296 return history_dir_.Append(chrome::kArchivedHistoryFilename);
284 } 297 }
285 298
299 #if defined(OS_ANDROID)
300 FilePath HistoryBackend::GetAndroidCacheFileName() const {
301 return history_dir_.Append(chrome::kAndroidCacheFilename);
302 }
303 #endif
304
286 SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) { 305 SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) {
287 // Set is used to detect referrer loops. Should not happen, but can 306 // Set is used to detect referrer loops. Should not happen, but can
288 // if the database is corrupt. 307 // if the database is corrupt.
289 std::set<VisitID> visit_set; 308 std::set<VisitID> visit_set;
290 VisitID visit_id = from_visit; 309 VisitID visit_id = from_visit;
291 while (visit_id) { 310 while (visit_id) {
292 VisitRow row; 311 VisitRow row;
293 if (!db_->GetRowForVisit(visit_id, &row)) 312 if (!db_->GetRowForVisit(visit_id, &row))
294 return 0; 313 return 0;
295 if (row.segment_id) 314 if (row.segment_id)
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 archived_db_->BeginTransaction(); 714 archived_db_->BeginTransaction();
696 if (text_database_.get()) 715 if (text_database_.get())
697 text_database_->BeginTransaction(); 716 text_database_->BeginTransaction();
698 717
699 // Get the first item in our database. 718 // Get the first item in our database.
700 db_->GetStartDate(&first_recorded_time_); 719 db_->GetStartDate(&first_recorded_time_);
701 720
702 // Start expiring old stuff. 721 // Start expiring old stuff.
703 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); 722 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold));
704 723
724 #if defined(OS_ANDROID)
725 if (thumbnail_db_.get()) {
726 android_provider_backend_.reset(new AndroidProviderBackend(
727 GetAndroidCacheFileName(), db_.get(), thumbnail_db_.get(),
728 bookmark_service_, delegate_.get()));
729 }
730 #endif
731
705 HISTOGRAM_TIMES("History.InitTime", 732 HISTOGRAM_TIMES("History.InitTime",
706 TimeTicks::Now() - beginning_time); 733 TimeTicks::Now() - beginning_time);
707 } 734 }
708 735
709 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( 736 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
710 const GURL& url, 737 const GURL& url,
711 Time time, 738 Time time,
712 VisitID referring_visit, 739 VisitID referring_visit,
713 content::PageTransition transition, 740 content::PageTransition transition,
714 VisitSource visit_source) { 741 VisitSource visit_source) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 if (request->canceled()) 1163 if (request->canceled())
1137 return; 1164 return;
1138 1165
1139 if (db_.get()) { 1166 if (db_.get()) {
1140 db_->GetMostRecentKeywordSearchTerms(keyword_id, prefix, max_count, 1167 db_->GetMostRecentKeywordSearchTerms(keyword_id, prefix, max_count,
1141 &(request->value)); 1168 &(request->value));
1142 } 1169 }
1143 request->ForwardResult(request->handle(), &request->value); 1170 request->ForwardResult(request->handle(), &request->value);
1144 } 1171 }
1145 1172
1173 #if defined(OS_ANDROID)
sky 2012/04/25 15:57:25 Move all of this into the file history_backend_and
michaelbai 2012/04/26 05:32:48 Done.
1174
1175 // History and Bookmarks -------------------------------------------------------
1176
1177 void HistoryBackend::InsertHistoryAndBookmark(
1178 scoped_refptr<InsertRequest> request,
1179 const HistoryAndBookmarkRow& row) {
1180 if (request->canceled())
1181 return;
1182
1183 AndroidURLID id = 0;
1184 if (android_provider_backend_.get())
1185 id = android_provider_backend_->InsertHistoryAndBookmark(row);
1186
1187 request->ForwardResult(request->handle(), id != 0, id);
1188 }
1189
1190 void HistoryBackend::QueryHistoryAndBookmarks(
1191 scoped_refptr<QueryRequest> request,
1192 const std::vector<HistoryAndBookmarkRow::ColumnID>& projections,
1193 const std::string& selection,
1194 const std::vector<string16>& selection_args,
1195 const std::string& sort_order) {
1196 if (request->canceled())
1197 return;
1198
1199 AndroidStatement* statement = NULL;
1200 if (android_provider_backend_.get()) {
1201 statement = android_provider_backend_->QueryHistoryAndBookmarks(
1202 projections, selection, selection_args, sort_order);
1203 }
1204 request->ForwardResult(request->handle(), statement, statement);
1205 }
1206
1207 void HistoryBackend::UpdateHistoryAndBookmarks(
1208 scoped_refptr<UpdateRequest> request,
1209 const HistoryAndBookmarkRow& row,
1210 const std::string& selection,
1211 const std::vector<string16>& selection_args) {
1212 if (request->canceled())
1213 return;
1214
1215 int count = 0;
1216 bool result = false;
1217 if (android_provider_backend_.get()) {
1218 result = android_provider_backend_->UpdateHistoryAndBookmarks(row,
1219 selection, selection_args, &count);
1220 }
1221
1222 request->ForwardResult(request->handle(), result, count);
1223 }
1224
1225 void HistoryBackend::DeleteHistoryAndBookmarks(
1226 scoped_refptr<DeleteRequest> request,
1227 const std::string& selection,
1228 const std::vector<string16>& selection_args) {
1229 if (request->canceled())
1230 return;
1231
1232 int count = 0;
1233 bool result = false;
1234 if (android_provider_backend_.get())
1235 result = android_provider_backend_->DeleteHistoryAndBookmarks(selection,
1236 selection_args, &count);
1237
1238 request->ForwardResult(request->handle(), result, count);
1239 }
1240
1241 void HistoryBackend::DeleteHistory(
1242 scoped_refptr<DeleteRequest> request,
1243 const std::string& selection,
1244 const std::vector<string16>& selection_args) {
1245 if (request->canceled())
1246 return;
1247
1248 int count = 0;
1249 bool result = false;
1250 if (android_provider_backend_.get()) {
1251 result = android_provider_backend_->DeleteHistory(selection, selection_args,
1252 &count);
1253 }
1254 request->ForwardResult(request->handle(), result, count);
1255 }
1256
1257 // Statement -------------------------------------------------------------------
1258
1259 void HistoryBackend::MoveStatement(
1260 scoped_refptr<MoveStatementRequest> request,
1261 history::AndroidStatement* statement,
1262 int current_pos,
1263 int destination) {
1264 DCHECK_LE(-1, current_pos);
1265 DCHECK_LE(-1, destination);
1266
1267 int cur = current_pos;
1268 if (current_pos > destination) {
1269 statement->statement()->ResetWithoutClearingBoundVariables();
1270 cur = -1;
1271 }
1272 for (; cur < destination; ++cur) {
1273 if (!statement->statement()->Step())
1274 break;
1275 }
1276
1277 request->ForwardResult(request->handle(), cur);
1278 }
1279
1280 void HistoryBackend::CloseStatement(AndroidStatement* statement) {
1281 delete statement;
1282 }
1283
1284 // Search Term -----------------------------------------------------------------
1285
1286 void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request,
1287 const SearchRow& row) {
1288 if (request->canceled())
1289 return;
1290
1291 SearchTermID id = 0;
1292 if (android_provider_backend_.get())
1293 id = android_provider_backend_->InsertSearchTerm(row);
1294
1295 request->ForwardResult(request->handle(), id != 0, id);
1296 }
1297
1298 void HistoryBackend::UpdateSearchTerms(
1299 scoped_refptr<UpdateRequest> request,
1300 const SearchRow& row,
1301 const std::string& selection,
1302 const std::vector<string16> selection_args) {
1303 if (request->canceled())
1304 return;
1305
1306 int count = 0;
1307 bool result = false;
1308 if (android_provider_backend_.get()) {
1309 result = android_provider_backend_->UpdateSearchTerms(row, selection,
1310 selection_args, &count);
1311 }
1312 request->ForwardResult(request->handle(), result, count);
1313 }
1314
1315 void HistoryBackend::DeleteSearchTerms(
1316 scoped_refptr<DeleteRequest> request,
1317 const std::string& selection,
1318 const std::vector<string16> selection_args) {
1319 if (request->canceled())
1320 return;
1321
1322 int count = 0;
1323 bool result = false;
1324 if (android_provider_backend_.get()) {
1325 result = android_provider_backend_->DeleteSearchTerms(selection,
1326 selection_args, &count);
1327 }
1328
1329 request->ForwardResult(request->handle(), result, count);
1330 }
1331
1332 void HistoryBackend::QuerySearchTerms(
1333 scoped_refptr<QueryRequest> request,
1334 const std::vector<SearchRow::ColumnID>& projections,
1335 const std::string& selection,
1336 const std::vector<string16>& selection_args,
1337 const std::string& sort_order) {
1338 if (request->canceled())
1339 return;
1340
1341 AndroidStatement* statement = NULL;
1342 if (android_provider_backend_.get())
1343 statement = android_provider_backend_->QuerySearchTerms(projections,
1344 selection, selection_args, sort_order);
1345
1346 request->ForwardResult(request->handle(), statement, statement);
1347 }
1348
1349 #endif // defined(OS_ANDROID)
1350
1146 // Downloads ------------------------------------------------------------------- 1351 // Downloads -------------------------------------------------------------------
1147 1352
1148 void HistoryBackend::GetNextDownloadId( 1353 void HistoryBackend::GetNextDownloadId(
1149 scoped_refptr<DownloadNextIdRequest> request) { 1354 scoped_refptr<DownloadNextIdRequest> request) {
1150 if (request->canceled()) return; 1355 if (request->canceled()) return;
1151 if (db_.get()) { 1356 if (db_.get()) {
1152 request->value = db_->next_download_id(); 1357 request->value = db_->next_download_id();
1153 } else { 1358 } else {
1154 request->value = 0; 1359 request->value = 0;
1155 } 1360 }
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 return false; 2676 return false;
2472 2677
2473 favicon->expired = (Time::Now() - last_updated) > 2678 favicon->expired = (Time::Now() - last_updated) >
2474 TimeDelta::FromDays(kFaviconRefetchDays); 2679 TimeDelta::FromDays(kFaviconRefetchDays);
2475 favicon->known_icon = true; 2680 favicon->known_icon = true;
2476 favicon->image_data = data; 2681 favicon->image_data = data;
2477 return true; 2682 return true;
2478 } 2683 }
2479 2684
2480 } // namespace history 2685 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698