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

Side by Side Diff: components/history/core/browser/download_database.cc

Issue 1875033005: [Downloads/History] Add tab-url and tab-referrer-url to DownloadRow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guid-fix
Patch Set: More comments Created 4 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
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 "components/history/core/browser/download_database.h" 5 #include "components/history/core/browser/download_database.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 "(\"%08X-%s-4%s-%01X%s-%s\"," 243 "(\"%08X-%s-4%s-%01X%s-%s\","
244 " id," 244 " id,"
245 " hex(randomblob(2))," 245 " hex(randomblob(2)),"
246 " substr(hex(randomblob(2)),2)," 246 " substr(hex(randomblob(2)),2),"
247 " (8 | (random() & 3))," 247 " (8 | (random() & 3)),"
248 " substr(hex(randomblob(2)),2)," 248 " substr(hex(randomblob(2)),2),"
249 " hex(randomblob(6)))"; 249 " hex(randomblob(6)))";
250 return GetDB().Execute(kMigrateGuidsQuery); 250 return GetDB().Execute(kMigrateGuidsQuery);
251 } 251 }
252 252
253 bool DownloadDatabase::MigrateDownloadTabUrl() {
254 return EnsureColumnExists("tab_url", "VARCHAR NOT NULL DEFAULT ''") &&
255 EnsureColumnExists("tab_referrer_url", "VARCHAR NOT NULL DEFAULT ''");
256 }
257
253 bool DownloadDatabase::InitDownloadTable() { 258 bool DownloadDatabase::InitDownloadTable() {
254 const char kSchema[] = 259 const char kSchema[] =
255 "CREATE TABLE downloads (" 260 "CREATE TABLE downloads ("
256 "id INTEGER PRIMARY KEY," // Primary key. 261 "id INTEGER PRIMARY KEY," // Primary key.
257 "guid VARCHAR NOT NULL," // GUID. 262 "guid VARCHAR NOT NULL," // GUID.
258 "current_path LONGVARCHAR NOT NULL," // Current disk location 263 "current_path LONGVARCHAR NOT NULL," // Current disk location
259 "target_path LONGVARCHAR NOT NULL," // Final disk location 264 "target_path LONGVARCHAR NOT NULL," // Final disk location
260 "start_time INTEGER NOT NULL," // When the download was started. 265 "start_time INTEGER NOT NULL," // When the download was started.
261 "received_bytes INTEGER NOT NULL," // Total size downloaded. 266 "received_bytes INTEGER NOT NULL," // Total size downloaded.
262 "total_bytes INTEGER NOT NULL," // Total size of the download. 267 "total_bytes INTEGER NOT NULL," // Total size of the download.
263 "state INTEGER NOT NULL," // 1=complete, 4=interrupted 268 "state INTEGER NOT NULL," // 1=complete, 4=interrupted
264 "danger_type INTEGER NOT NULL," // Danger type, validated. 269 "danger_type INTEGER NOT NULL," // Danger type, validated.
265 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason 270 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason
266 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents. 271 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents.
267 "end_time INTEGER NOT NULL," // When the download completed. 272 "end_time INTEGER NOT NULL," // When the download completed.
268 "opened INTEGER NOT NULL," // 1 if it has ever been opened 273 "opened INTEGER NOT NULL," // 1 if it has ever been opened
269 // else 0 274 // else 0
270 "referrer VARCHAR NOT NULL," // HTTP Referrer 275 "referrer VARCHAR NOT NULL," // HTTP Referrer
276 "tab_url VARCHAR NOT NULL," // Tab URL for initiator.
277 "tab_referrer_url VARCHAR NOT NULL," // Tag referrer URL for initiator.
271 "http_method VARCHAR NOT NULL," // HTTP method. 278 "http_method VARCHAR NOT NULL," // HTTP method.
272 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the 279 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the
273 // download 280 // download
274 "by_ext_name VARCHAR NOT NULL," // name of extension 281 "by_ext_name VARCHAR NOT NULL," // name of extension
275 "etag VARCHAR NOT NULL," // ETag 282 "etag VARCHAR NOT NULL," // ETag
276 "last_modified VARCHAR NOT NULL," // Last-Modified header 283 "last_modified VARCHAR NOT NULL," // Last-Modified header
277 "mime_type VARCHAR(255) NOT NULL," // MIME type. 284 "mime_type VARCHAR(255) NOT NULL," // MIME type.
278 "original_mime_type VARCHAR(255) NOT NULL)"; // Original MIME type. 285 "original_mime_type VARCHAR(255) NOT NULL)"; // Original MIME type.
279 286
280 const char kUrlChainSchema[] = 287 const char kUrlChainSchema[] =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 results->clear(); 337 results->clear();
331 std::set<uint32_t> ids; 338 std::set<uint32_t> ids;
332 339
333 std::map<uint32_t, DownloadRow*> info_map; 340 std::map<uint32_t, DownloadRow*> info_map;
334 341
335 sql::Statement statement_main(GetDB().GetCachedStatement( 342 sql::Statement statement_main(GetDB().GetCachedStatement(
336 SQL_FROM_HERE, 343 SQL_FROM_HERE,
337 "SELECT id, guid, current_path, target_path, mime_type, " 344 "SELECT id, guid, current_path, target_path, mime_type, "
338 "original_mime_type, start_time, received_bytes, total_bytes, state, " 345 "original_mime_type, start_time, received_bytes, total_bytes, state, "
339 "danger_type, interrupt_reason, hash, end_time, opened, referrer, " 346 "danger_type, interrupt_reason, hash, end_time, opened, referrer, "
340 "http_method, by_ext_id, by_ext_name, etag, last_modified " 347 "tab_url, tab_referrer_url, http_method, by_ext_id, by_ext_name, etag, "
341 "FROM downloads ORDER BY start_time")); 348 "last_modified FROM downloads ORDER BY start_time"));
342 349
343 while (statement_main.Step()) { 350 while (statement_main.Step()) {
344 scoped_ptr<DownloadRow> info(new DownloadRow()); 351 scoped_ptr<DownloadRow> info(new DownloadRow());
345 int column = 0; 352 int column = 0;
346 353
347 // SQLITE does not have unsigned integers, so explicitly handle negative 354 // SQLITE does not have unsigned integers, so explicitly handle negative
348 // |id|s instead of casting them to very large uint32s, which would break 355 // |id|s instead of casting them to very large uint32s, which would break
349 // the max(id) logic in GetNextDownloadId(). 356 // the max(id) logic in GetNextDownloadId().
350 int64_t signed_id = statement_main.ColumnInt64(column++); 357 int64_t signed_id = statement_main.ColumnInt64(column++);
351 info->id = IntToDownloadId(signed_id); 358 info->id = IntToDownloadId(signed_id);
(...skipping 12 matching lines...) Expand all
364 UMA_HISTOGRAM_COUNTS("Download.DatabaseInvalidState", state); 371 UMA_HISTOGRAM_COUNTS("Download.DatabaseInvalidState", state);
365 info->danger_type = 372 info->danger_type =
366 IntToDownloadDangerType(statement_main.ColumnInt(column++)); 373 IntToDownloadDangerType(statement_main.ColumnInt(column++));
367 info->interrupt_reason = 374 info->interrupt_reason =
368 IntToDownloadInterruptReason(statement_main.ColumnInt(column++)); 375 IntToDownloadInterruptReason(statement_main.ColumnInt(column++));
369 statement_main.ColumnBlobAsString(column++, &info->hash); 376 statement_main.ColumnBlobAsString(column++, &info->hash);
370 info->end_time = 377 info->end_time =
371 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); 378 base::Time::FromInternalValue(statement_main.ColumnInt64(column++));
372 info->opened = statement_main.ColumnInt(column++) != 0; 379 info->opened = statement_main.ColumnInt(column++) != 0;
373 info->referrer_url = GURL(statement_main.ColumnString(column++)); 380 info->referrer_url = GURL(statement_main.ColumnString(column++));
381 info->tab_url = GURL(statement_main.ColumnString(column++));
382 info->tab_referrer_url = GURL(statement_main.ColumnString(column++));
374 info->http_method = statement_main.ColumnString(column++); 383 info->http_method = statement_main.ColumnString(column++);
375 info->by_ext_id = statement_main.ColumnString(column++); 384 info->by_ext_id = statement_main.ColumnString(column++);
376 info->by_ext_name = statement_main.ColumnString(column++); 385 info->by_ext_name = statement_main.ColumnString(column++);
377 info->etag = statement_main.ColumnString(column++); 386 info->etag = statement_main.ColumnString(column++);
378 info->last_modified = statement_main.ColumnString(column++); 387 info->last_modified = statement_main.ColumnString(column++);
379 388
380 // If the record is corrupted, note that and drop it. 389 // If the record is corrupted, note that and drop it.
381 // http://crbug.com/251269 390 // http://crbug.com/251269
382 DroppedReason dropped_reason = DROPPED_REASON_MAX; 391 DroppedReason dropped_reason = DROPPED_REASON_MAX;
383 if (signed_id <= static_cast<int64_t>(kInvalidDownloadId)) { 392 if (signed_id <= static_cast<int64_t>(kInvalidDownloadId)) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 545
537 if (info.danger_type == DownloadDangerType::INVALID) 546 if (info.danger_type == DownloadDangerType::INVALID)
538 return false; 547 return false;
539 548
540 { 549 {
541 sql::Statement statement_insert(GetDB().GetCachedStatement( 550 sql::Statement statement_insert(GetDB().GetCachedStatement(
542 SQL_FROM_HERE, 551 SQL_FROM_HERE,
543 "INSERT INTO downloads " 552 "INSERT INTO downloads "
544 "(id, guid, current_path, target_path, mime_type, original_mime_type, " 553 "(id, guid, current_path, target_path, mime_type, original_mime_type, "
545 " start_time, received_bytes, total_bytes, state, danger_type, " 554 " start_time, received_bytes, total_bytes, state, danger_type, "
546 " interrupt_reason, hash, end_time, opened, referrer, http_method, " 555 " interrupt_reason, hash, end_time, opened, referrer, tab_url, "
547 " by_ext_id, by_ext_name, etag, last_modified) " 556 " tab_referrer_url, http_method, by_ext_id, by_ext_name, etag, "
557 " last_modified) "
548 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 558 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
549 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 559 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
550 " ?)")); 560 " ?, ?, ?)"));
551 561
552 int column = 0; 562 int column = 0;
553 statement_insert.BindInt(column++, DownloadIdToInt(info.id)); 563 statement_insert.BindInt(column++, DownloadIdToInt(info.id));
554 statement_insert.BindString(column++, info.guid); 564 statement_insert.BindString(column++, info.guid);
555 BindFilePath(statement_insert, info.current_path, column++); 565 BindFilePath(statement_insert, info.current_path, column++);
556 BindFilePath(statement_insert, info.target_path, column++); 566 BindFilePath(statement_insert, info.target_path, column++);
557 statement_insert.BindString(column++, info.mime_type); 567 statement_insert.BindString(column++, info.mime_type);
558 statement_insert.BindString(column++, info.original_mime_type); 568 statement_insert.BindString(column++, info.original_mime_type);
559 statement_insert.BindInt64(column++, info.start_time.ToInternalValue()); 569 statement_insert.BindInt64(column++, info.start_time.ToInternalValue());
560 statement_insert.BindInt64(column++, info.received_bytes); 570 statement_insert.BindInt64(column++, info.received_bytes);
561 statement_insert.BindInt64(column++, info.total_bytes); 571 statement_insert.BindInt64(column++, info.total_bytes);
562 statement_insert.BindInt(column++, DownloadStateToInt(info.state)); 572 statement_insert.BindInt(column++, DownloadStateToInt(info.state));
563 statement_insert.BindInt(column++, 573 statement_insert.BindInt(column++,
564 DownloadDangerTypeToInt(info.danger_type)); 574 DownloadDangerTypeToInt(info.danger_type));
565 statement_insert.BindInt( 575 statement_insert.BindInt(
566 column++, DownloadInterruptReasonToInt(info.interrupt_reason)); 576 column++, DownloadInterruptReasonToInt(info.interrupt_reason));
567 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size()); 577 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size());
568 statement_insert.BindInt64(column++, info.end_time.ToInternalValue()); 578 statement_insert.BindInt64(column++, info.end_time.ToInternalValue());
569 statement_insert.BindInt(column++, info.opened ? 1 : 0); 579 statement_insert.BindInt(column++, info.opened ? 1 : 0);
570 statement_insert.BindString(column++, info.referrer_url.spec()); 580 statement_insert.BindString(column++, info.referrer_url.spec());
581 statement_insert.BindString(column++, info.tab_url.spec());
582 statement_insert.BindString(column++, info.tab_referrer_url.spec());
571 statement_insert.BindString(column++, info.http_method); 583 statement_insert.BindString(column++, info.http_method);
572 statement_insert.BindString(column++, info.by_ext_id); 584 statement_insert.BindString(column++, info.by_ext_id);
573 statement_insert.BindString(column++, info.by_ext_name); 585 statement_insert.BindString(column++, info.by_ext_name);
574 statement_insert.BindString(column++, info.etag); 586 statement_insert.BindString(column++, info.etag);
575 statement_insert.BindString(column++, info.last_modified); 587 statement_insert.BindString(column++, info.last_modified);
576 if (!statement_insert.Run()) { 588 if (!statement_insert.Run()) {
577 // GetErrorCode() returns a bitmask where the lower byte is a more general 589 // GetErrorCode() returns a bitmask where the lower byte is a more general
578 // code and the upper byte is a more specific code. In order to save 590 // code and the upper byte is a more specific code. In order to save
579 // memory, take the general code, of which there are fewer than 50. See 591 // memory, take the general code, of which there are fewer than 50. See
580 // also sql/connection.cc 592 // also sql/connection.cc
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 size_t DownloadDatabase::CountDownloads() { 660 size_t DownloadDatabase::CountDownloads() {
649 EnsureInProgressEntriesCleanedUp(); 661 EnsureInProgressEntriesCleanedUp();
650 662
651 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 663 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
652 "SELECT count(*) from downloads")); 664 "SELECT count(*) from downloads"));
653 statement.Step(); 665 statement.Step();
654 return statement.ColumnInt(0); 666 return statement.ColumnInt(0);
655 } 667 }
656 668
657 } // namespace history 669 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698