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

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

Issue 849323002: Componentize HistoryDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compilation Created 5 years, 11 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 base::FilePath ColumnFilePath(sql::Statement& statement, int col) { 58 base::FilePath ColumnFilePath(sql::Statement& statement, int col) {
59 return base::FilePath(statement.ColumnString16(col)); 59 return base::FilePath(statement.ColumnString16(col));
60 } 60 }
61 61
62 #endif 62 #endif
63 63
64 } // namespace 64 } // namespace
65 65
66 DownloadDatabase::DownloadDatabase( 66 DownloadDatabase::DownloadDatabase(
67 DownloadInterruptReason download_interrupt_no_reason, 67 DownloadInterruptReason download_interrupt_reason_none,
68 DownloadInterruptReason download_interrupt_crash) 68 DownloadInterruptReason download_interrupt_reason_crash)
69 : owning_thread_set_(false), 69 : owning_thread_set_(false),
70 owning_thread_(0), 70 owning_thread_(0),
71 in_progress_entry_cleanup_completed_(false), 71 in_progress_entry_cleanup_completed_(false),
72 download_interrupt_no_reason_(download_interrupt_no_reason), 72 download_interrupt_reason_none_(download_interrupt_reason_none),
73 download_interrupt_crash_(download_interrupt_crash) { 73 download_interrupt_reason_crash_(download_interrupt_reason_crash) {
74 } 74 }
75 75
76 DownloadDatabase::~DownloadDatabase() { 76 DownloadDatabase::~DownloadDatabase() {
77 } 77 }
78 78
79 bool DownloadDatabase::EnsureColumnExists(const std::string& name, 79 bool DownloadDatabase::EnsureColumnExists(const std::string& name,
80 const std::string& type) { 80 const std::string& type) {
81 std::string add_col = "ALTER TABLE downloads ADD COLUMN " + name + " " + type; 81 std::string add_col = "ALTER TABLE downloads ADD COLUMN " + name + " " + type;
82 return GetDB().DoesColumnExist("downloads", name.c_str()) || 82 return GetDB().DoesColumnExist("downloads", name.c_str()) ||
83 GetDB().Execute(add_col.c_str()); 83 GetDB().Execute(add_col.c_str());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 "SELECT id, full_path, full_path, " 143 "SELECT id, full_path, full_path, "
144 " CASE start_time WHEN 0 THEN 0 ELSE " 144 " CASE start_time WHEN 0 THEN 0 ELSE "
145 " (start_time + 11644473600) * 1000000 END, " 145 " (start_time + 11644473600) * 1000000 END, "
146 " received_bytes, total_bytes, " 146 " received_bytes, total_bytes, "
147 " state, ?, ?, " 147 " state, ?, ?, "
148 " CASE end_time WHEN 0 THEN 0 ELSE " 148 " CASE end_time WHEN 0 THEN 0 ELSE "
149 " (end_time + 11644473600) * 1000000 END, " 149 " (end_time + 11644473600) * 1000000 END, "
150 " opened " 150 " opened "
151 "FROM downloads_tmp")); 151 "FROM downloads_tmp"));
152 statement_populate.BindInt( 152 statement_populate.BindInt(
153 0, DownloadInterruptReasonToInt(download_interrupt_no_reason_)); 153 0, DownloadInterruptReasonToInt(download_interrupt_reason_none_));
154 statement_populate.BindInt( 154 statement_populate.BindInt(
155 1, DownloadDangerTypeToInt(DownloadDangerType::NOT_DANGEROUS)); 155 1, DownloadDangerTypeToInt(DownloadDangerType::NOT_DANGEROUS));
156 if (!statement_populate.Run()) 156 if (!statement_populate.Run())
157 return false; 157 return false;
158 158
159 // Create new chain table and populate it. 159 // Create new chain table and populate it.
160 if (!GetDB().Execute(kReasonPathDangerUrlChainSchema)) 160 if (!GetDB().Execute(kReasonPathDangerUrlChainSchema))
161 return false; 161 return false;
162 162
163 if (!GetDB().Execute("INSERT INTO downloads_url_chains " 163 if (!GetDB().Execute("INSERT INTO downloads_url_chains "
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return statement.Run(); 432 return statement.Run();
433 } 433 }
434 434
435 void DownloadDatabase::EnsureInProgressEntriesCleanedUp() { 435 void DownloadDatabase::EnsureInProgressEntriesCleanedUp() {
436 if (in_progress_entry_cleanup_completed_) 436 if (in_progress_entry_cleanup_completed_)
437 return; 437 return;
438 438
439 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 439 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
440 "UPDATE downloads SET state=?, interrupt_reason=? WHERE state=?")); 440 "UPDATE downloads SET state=?, interrupt_reason=? WHERE state=?"));
441 statement.BindInt(0, DownloadStateToInt(DownloadState::INTERRUPTED)); 441 statement.BindInt(0, DownloadStateToInt(DownloadState::INTERRUPTED));
442 statement.BindInt(1, DownloadInterruptReasonToInt(download_interrupt_crash_)); 442 statement.BindInt(
443 1, DownloadInterruptReasonToInt(download_interrupt_reason_crash_));
443 statement.BindInt(2, DownloadStateToInt(DownloadState::IN_PROGRESS)); 444 statement.BindInt(2, DownloadStateToInt(DownloadState::IN_PROGRESS));
444 445
445 statement.Run(); 446 statement.Run();
446 in_progress_entry_cleanup_completed_ = true; 447 in_progress_entry_cleanup_completed_ = true;
447 } 448 }
448 449
449 bool DownloadDatabase::CreateDownload(const DownloadRow& info) { 450 bool DownloadDatabase::CreateDownload(const DownloadRow& info) {
450 DCHECK_NE(kInvalidDownloadId, info.id); 451 DCHECK_NE(kInvalidDownloadId, info.id);
451 EnsureInProgressEntriesCleanedUp(); 452 EnsureInProgressEntriesCleanedUp();
452 453
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 size_t DownloadDatabase::CountDownloads() { 568 size_t DownloadDatabase::CountDownloads() {
568 EnsureInProgressEntriesCleanedUp(); 569 EnsureInProgressEntriesCleanedUp();
569 570
570 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 571 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
571 "SELECT count(*) from downloads")); 572 "SELECT count(*) from downloads"));
572 statement.Step(); 573 statement.Step();
573 return statement.ColumnInt(0); 574 return statement.ColumnInt(0);
574 } 575 }
575 576
576 } // namespace history 577 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/download_database.h ('k') | components/history/core/browser/history_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698