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

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

Issue 1924473003: [Downloads] Use the initiating StoragePartition for resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ordering of site_instance_url/SiteInstanceURL fields, and add history test for WebViewTest. Created 4 years, 7 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() { 253 bool DownloadDatabase::MigrateDownloadTabUrl() {
254 return EnsureColumnExists("tab_url", "VARCHAR NOT NULL DEFAULT ''") && 254 return EnsureColumnExists("tab_url", "VARCHAR NOT NULL DEFAULT ''") &&
255 EnsureColumnExists("tab_referrer_url", "VARCHAR NOT NULL DEFAULT ''"); 255 EnsureColumnExists("tab_referrer_url", "VARCHAR NOT NULL DEFAULT ''");
256 } 256 }
257 257
258 bool DownloadDatabase::MigrateDownloadSiteInstanceUrl() {
259 return EnsureColumnExists("site_instance_url", "VARCHAR NOT NULL DEFAULT ''");
260 }
261
258 bool DownloadDatabase::InitDownloadTable() { 262 bool DownloadDatabase::InitDownloadTable() {
259 const char kSchema[] = 263 const char kSchema[] =
260 "CREATE TABLE downloads (" 264 "CREATE TABLE downloads ("
261 "id INTEGER PRIMARY KEY," // Primary key. 265 "id INTEGER PRIMARY KEY," // Primary key.
262 "guid VARCHAR NOT NULL," // GUID. 266 "guid VARCHAR NOT NULL," // GUID.
263 "current_path LONGVARCHAR NOT NULL," // Current disk location 267 "current_path LONGVARCHAR NOT NULL," // Current disk location
264 "target_path LONGVARCHAR NOT NULL," // Final disk location 268 "target_path LONGVARCHAR NOT NULL," // Final disk location
265 "start_time INTEGER NOT NULL," // When the download was started. 269 "start_time INTEGER NOT NULL," // When the download was started.
266 "received_bytes INTEGER NOT NULL," // Total size downloaded. 270 "received_bytes INTEGER NOT NULL," // Total size downloaded.
267 "total_bytes INTEGER NOT NULL," // Total size of the download. 271 "total_bytes INTEGER NOT NULL," // Total size of the download.
268 "state INTEGER NOT NULL," // 1=complete, 4=interrupted 272 "state INTEGER NOT NULL," // 1=complete, 4=interrupted
269 "danger_type INTEGER NOT NULL," // Danger type, validated. 273 "danger_type INTEGER NOT NULL," // Danger type, validated.
270 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason 274 "interrupt_reason INTEGER NOT NULL," // DownloadInterruptReason
271 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents. 275 "hash BLOB NOT NULL," // Raw SHA-256 hash of contents.
272 "end_time INTEGER NOT NULL," // When the download completed. 276 "end_time INTEGER NOT NULL," // When the download completed.
273 "opened INTEGER NOT NULL," // 1 if it has ever been opened 277 "opened INTEGER NOT NULL," // 1 if it has ever been opened
274 // else 0 278 // else 0
275 "referrer VARCHAR NOT NULL," // HTTP Referrer 279 "referrer VARCHAR NOT NULL," // HTTP Referrer
276 "tab_url VARCHAR NOT NULL," // Tab URL for initiator. 280 "site_instance_url VARCHAR NOT NULL," // Site URL for initiating site
Charlie Reis 2016/05/05 21:43:22 site_url (see comment in download_item.h)
asanka 2016/05/07 00:24:45 Done. Here and elsewhere.
277 "tab_referrer_url VARCHAR NOT NULL," // Tag referrer URL for initiator. 281 // instance.
278 "http_method VARCHAR NOT NULL," // HTTP method. 282 "tab_url VARCHAR NOT NULL," // Tab URL for initiator.
279 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the 283 "tab_referrer_url VARCHAR NOT NULL," // Tag referrer URL for initiator.
280 // download 284 "http_method VARCHAR NOT NULL," // HTTP method.
281 "by_ext_name VARCHAR NOT NULL," // name of extension 285 "by_ext_id VARCHAR NOT NULL," // ID of extension that started the
282 "etag VARCHAR NOT NULL," // ETag 286 // download
283 "last_modified VARCHAR NOT NULL," // Last-Modified header 287 "by_ext_name VARCHAR NOT NULL," // name of extension
284 "mime_type VARCHAR(255) NOT NULL," // MIME type. 288 "etag VARCHAR NOT NULL," // ETag
289 "last_modified VARCHAR NOT NULL," // Last-Modified header
290 "mime_type VARCHAR(255) NOT NULL," // MIME type.
285 "original_mime_type VARCHAR(255) NOT NULL)"; // Original MIME type. 291 "original_mime_type VARCHAR(255) NOT NULL)"; // Original MIME type.
286 292
287 const char kUrlChainSchema[] = 293 const char kUrlChainSchema[] =
288 "CREATE TABLE downloads_url_chains (" 294 "CREATE TABLE downloads_url_chains ("
289 "id INTEGER NOT NULL," // downloads.id. 295 "id INTEGER NOT NULL," // downloads.id.
290 "chain_index INTEGER NOT NULL," // Index of url in chain 296 "chain_index INTEGER NOT NULL," // Index of url in chain
291 // 0 is initial target, 297 // 0 is initial target,
292 // MAX is target after redirects. 298 // MAX is target after redirects.
293 "url LONGVARCHAR NOT NULL, " // URL. 299 "url LONGVARCHAR NOT NULL, " // URL.
294 "PRIMARY KEY (id, chain_index) )"; 300 "PRIMARY KEY (id, chain_index) )";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 results->clear(); 343 results->clear();
338 std::set<uint32_t> ids; 344 std::set<uint32_t> ids;
339 345
340 std::map<uint32_t, DownloadRow*> info_map; 346 std::map<uint32_t, DownloadRow*> info_map;
341 347
342 sql::Statement statement_main(GetDB().GetCachedStatement( 348 sql::Statement statement_main(GetDB().GetCachedStatement(
343 SQL_FROM_HERE, 349 SQL_FROM_HERE,
344 "SELECT id, guid, current_path, target_path, mime_type, " 350 "SELECT id, guid, current_path, target_path, mime_type, "
345 "original_mime_type, start_time, received_bytes, total_bytes, state, " 351 "original_mime_type, start_time, received_bytes, total_bytes, state, "
346 "danger_type, interrupt_reason, hash, end_time, opened, referrer, " 352 "danger_type, interrupt_reason, hash, end_time, opened, referrer, "
347 "tab_url, tab_referrer_url, http_method, by_ext_id, by_ext_name, etag, " 353 "site_instance_url, tab_url, tab_referrer_url, http_method, by_ext_id, "
348 "last_modified FROM downloads ORDER BY start_time")); 354 "by_ext_name, etag, last_modified FROM downloads ORDER BY start_time"));
349 355
350 while (statement_main.Step()) { 356 while (statement_main.Step()) {
351 std::unique_ptr<DownloadRow> info(new DownloadRow()); 357 std::unique_ptr<DownloadRow> info(new DownloadRow());
352 int column = 0; 358 int column = 0;
353 359
354 // SQLITE does not have unsigned integers, so explicitly handle negative 360 // SQLITE does not have unsigned integers, so explicitly handle negative
355 // |id|s instead of casting them to very large uint32s, which would break 361 // |id|s instead of casting them to very large uint32s, which would break
356 // the max(id) logic in GetNextDownloadId(). 362 // the max(id) logic in GetNextDownloadId().
357 int64_t signed_id = statement_main.ColumnInt64(column++); 363 int64_t signed_id = statement_main.ColumnInt64(column++);
358 info->id = IntToDownloadId(signed_id); 364 info->id = IntToDownloadId(signed_id);
(...skipping 12 matching lines...) Expand all
371 UMA_HISTOGRAM_COUNTS("Download.DatabaseInvalidState", state); 377 UMA_HISTOGRAM_COUNTS("Download.DatabaseInvalidState", state);
372 info->danger_type = 378 info->danger_type =
373 IntToDownloadDangerType(statement_main.ColumnInt(column++)); 379 IntToDownloadDangerType(statement_main.ColumnInt(column++));
374 info->interrupt_reason = 380 info->interrupt_reason =
375 IntToDownloadInterruptReason(statement_main.ColumnInt(column++)); 381 IntToDownloadInterruptReason(statement_main.ColumnInt(column++));
376 statement_main.ColumnBlobAsString(column++, &info->hash); 382 statement_main.ColumnBlobAsString(column++, &info->hash);
377 info->end_time = 383 info->end_time =
378 base::Time::FromInternalValue(statement_main.ColumnInt64(column++)); 384 base::Time::FromInternalValue(statement_main.ColumnInt64(column++));
379 info->opened = statement_main.ColumnInt(column++) != 0; 385 info->opened = statement_main.ColumnInt(column++) != 0;
380 info->referrer_url = GURL(statement_main.ColumnString(column++)); 386 info->referrer_url = GURL(statement_main.ColumnString(column++));
387 info->site_instance_url = GURL(statement_main.ColumnString(column++));
381 info->tab_url = GURL(statement_main.ColumnString(column++)); 388 info->tab_url = GURL(statement_main.ColumnString(column++));
382 info->tab_referrer_url = GURL(statement_main.ColumnString(column++)); 389 info->tab_referrer_url = GURL(statement_main.ColumnString(column++));
383 info->http_method = statement_main.ColumnString(column++); 390 info->http_method = statement_main.ColumnString(column++);
384 info->by_ext_id = statement_main.ColumnString(column++); 391 info->by_ext_id = statement_main.ColumnString(column++);
385 info->by_ext_name = statement_main.ColumnString(column++); 392 info->by_ext_name = statement_main.ColumnString(column++);
386 info->etag = statement_main.ColumnString(column++); 393 info->etag = statement_main.ColumnString(column++);
387 info->last_modified = statement_main.ColumnString(column++); 394 info->last_modified = statement_main.ColumnString(column++);
388 395
389 // If the record is corrupted, note that and drop it. 396 // If the record is corrupted, note that and drop it.
390 // http://crbug.com/251269 397 // http://crbug.com/251269
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 552
546 if (info.danger_type == DownloadDangerType::INVALID) 553 if (info.danger_type == DownloadDangerType::INVALID)
547 return false; 554 return false;
548 555
549 { 556 {
550 sql::Statement statement_insert(GetDB().GetCachedStatement( 557 sql::Statement statement_insert(GetDB().GetCachedStatement(
551 SQL_FROM_HERE, 558 SQL_FROM_HERE,
552 "INSERT INTO downloads " 559 "INSERT INTO downloads "
553 "(id, guid, current_path, target_path, mime_type, original_mime_type, " 560 "(id, guid, current_path, target_path, mime_type, original_mime_type, "
554 " start_time, received_bytes, total_bytes, state, danger_type, " 561 " start_time, received_bytes, total_bytes, state, danger_type, "
555 " interrupt_reason, hash, end_time, opened, referrer, tab_url, " 562 " interrupt_reason, hash, end_time, opened, referrer, "
556 " tab_referrer_url, http_method, by_ext_id, by_ext_name, etag, " 563 " site_instance_url, tab_url, tab_referrer_url, http_method, "
557 " last_modified) " 564 " by_ext_id, by_ext_name, etag, last_modified) "
558 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 565 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
559 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 566 " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
560 " ?, ?, ?)")); 567 " ?, ?, ?, ?)"));
561 568
562 int column = 0; 569 int column = 0;
563 statement_insert.BindInt(column++, DownloadIdToInt(info.id)); 570 statement_insert.BindInt(column++, DownloadIdToInt(info.id));
564 statement_insert.BindString(column++, info.guid); 571 statement_insert.BindString(column++, info.guid);
565 BindFilePath(statement_insert, info.current_path, column++); 572 BindFilePath(statement_insert, info.current_path, column++);
566 BindFilePath(statement_insert, info.target_path, column++); 573 BindFilePath(statement_insert, info.target_path, column++);
567 statement_insert.BindString(column++, info.mime_type); 574 statement_insert.BindString(column++, info.mime_type);
568 statement_insert.BindString(column++, info.original_mime_type); 575 statement_insert.BindString(column++, info.original_mime_type);
569 statement_insert.BindInt64(column++, info.start_time.ToInternalValue()); 576 statement_insert.BindInt64(column++, info.start_time.ToInternalValue());
570 statement_insert.BindInt64(column++, info.received_bytes); 577 statement_insert.BindInt64(column++, info.received_bytes);
571 statement_insert.BindInt64(column++, info.total_bytes); 578 statement_insert.BindInt64(column++, info.total_bytes);
572 statement_insert.BindInt(column++, DownloadStateToInt(info.state)); 579 statement_insert.BindInt(column++, DownloadStateToInt(info.state));
573 statement_insert.BindInt(column++, 580 statement_insert.BindInt(column++,
574 DownloadDangerTypeToInt(info.danger_type)); 581 DownloadDangerTypeToInt(info.danger_type));
575 statement_insert.BindInt( 582 statement_insert.BindInt(
576 column++, DownloadInterruptReasonToInt(info.interrupt_reason)); 583 column++, DownloadInterruptReasonToInt(info.interrupt_reason));
577 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size()); 584 statement_insert.BindBlob(column++, info.hash.data(), info.hash.size());
578 statement_insert.BindInt64(column++, info.end_time.ToInternalValue()); 585 statement_insert.BindInt64(column++, info.end_time.ToInternalValue());
579 statement_insert.BindInt(column++, info.opened ? 1 : 0); 586 statement_insert.BindInt(column++, info.opened ? 1 : 0);
580 statement_insert.BindString(column++, info.referrer_url.spec()); 587 statement_insert.BindString(column++, info.referrer_url.spec());
588 statement_insert.BindString(column++, info.site_instance_url.spec());
581 statement_insert.BindString(column++, info.tab_url.spec()); 589 statement_insert.BindString(column++, info.tab_url.spec());
582 statement_insert.BindString(column++, info.tab_referrer_url.spec()); 590 statement_insert.BindString(column++, info.tab_referrer_url.spec());
583 statement_insert.BindString(column++, info.http_method); 591 statement_insert.BindString(column++, info.http_method);
584 statement_insert.BindString(column++, info.by_ext_id); 592 statement_insert.BindString(column++, info.by_ext_id);
585 statement_insert.BindString(column++, info.by_ext_name); 593 statement_insert.BindString(column++, info.by_ext_name);
586 statement_insert.BindString(column++, info.etag); 594 statement_insert.BindString(column++, info.etag);
587 statement_insert.BindString(column++, info.last_modified); 595 statement_insert.BindString(column++, info.last_modified);
588 if (!statement_insert.Run()) { 596 if (!statement_insert.Run()) {
589 // GetErrorCode() returns a bitmask where the lower byte is a more general 597 // GetErrorCode() returns a bitmask where the lower byte is a more general
590 // code and the upper byte is a more specific code. In order to save 598 // code and the upper byte is a more specific code. In order to save
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 size_t DownloadDatabase::CountDownloads() { 668 size_t DownloadDatabase::CountDownloads() {
661 EnsureInProgressEntriesCleanedUp(); 669 EnsureInProgressEntriesCleanedUp();
662 670
663 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 671 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
664 "SELECT count(*) from downloads")); 672 "SELECT count(*) from downloads"));
665 statement.Step(); 673 statement.Step();
666 return statement.ColumnInt(0); 674 return statement.ColumnInt(0);
667 } 675 }
668 676
669 } // namespace history 677 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698