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

Side by Side Diff: components/precache/core/precache_database.cc

Issue 1961153003: Add pause/resume functionality to precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test fix Created 4 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/precache/core/precache_database.h" 5 #include "components/precache/core/precache_database.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/history/core/browser/history_constants.h" 14 #include "components/history/core/browser/history_constants.h"
15 #include "components/precache/core/proto/unfinished_work.pb.h"
15 #include "sql/connection.h" 16 #include "sql/connection.h"
16 #include "sql/transaction.h" 17 #include "sql/transaction.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace { 20 namespace {
20 21
21 // The number of days old that an entry in the precache URL table can be before 22 // The number of days old that an entry in the precache URL table can be before
22 // it is considered "old" and is removed from the table. 23 // it is considered "old" and is removed from the table.
23 const int kPrecacheHistoryExpiryPeriodDays = 60; 24 const int kPrecacheHistoryExpiryPeriodDays = 60;
24 25
(...skipping 19 matching lines...) Expand all
44 45
45 db_.reset(new sql::Connection()); 46 db_.reset(new sql::Connection());
46 db_->set_histogram_tag("Precache"); 47 db_->set_histogram_tag("Precache");
47 48
48 if (!db_->Open(db_path)) { 49 if (!db_->Open(db_path)) {
49 // Don't initialize the URL table if unable to access 50 // Don't initialize the URL table if unable to access
50 // the database. 51 // the database.
51 return false; 52 return false;
52 } 53 }
53 54
54 if (!precache_url_table_.Init(db_.get())) { 55 if (!precache_url_table_.Init(db_.get()) ||
56 !precache_session_table_.Init(db_.get())) {
55 // Raze and close the database connection to indicate that it's not usable, 57 // Raze and close the database connection to indicate that it's not usable,
56 // and so that the database will be created anew next time, in case it's 58 // and so that the database will be created anew next time, in case it's
57 // corrupted. 59 // corrupted.
58 db_->RazeAndClose(); 60 db_->RazeAndClose();
59 return false; 61 return false;
60 } 62 }
61 return true; 63 return true;
62 } 64 }
63 65
64 void PrecacheDatabase::DeleteExpiredPrecacheHistory( 66 void PrecacheDatabase::DeleteExpiredPrecacheHistory(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Post a delayed task to flush the buffer in 1 second, so that multiple 254 // Post a delayed task to flush the buffer in 1 second, so that multiple
253 // database writes can be buffered up and flushed together in the same 255 // database writes can be buffered up and flushed together in the same
254 // transaction. 256 // transaction.
255 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 257 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
256 FROM_HERE, base::Bind(&PrecacheDatabase::PostedFlush, 258 FROM_HERE, base::Bind(&PrecacheDatabase::PostedFlush,
257 weak_factory_.GetWeakPtr()), 259 weak_factory_.GetWeakPtr()),
258 base::TimeDelta::FromSeconds(1)); 260 base::TimeDelta::FromSeconds(1));
259 is_flush_posted_ = true; 261 is_flush_posted_ = true;
260 } 262 }
261 263
264 std::unique_ptr<PrecacheUnfinishedWork>
265 PrecacheDatabase::GetUnfinishedWork() {
266 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work =
267 precache_session_table_.GetUnfinishedWork();
268 precache_session_table_.DeleteUnfinishedWork();
269 return unfinished_work;
270 }
271
272 void PrecacheDatabase::SaveUnfinishedWork(
273 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) {
274 precache_session_table_.SaveUnfinishedWork(
275 std::move(unfinished_work));
276 }
277
278 void PrecacheDatabase::DeleteUnfinishedWork() {
279 precache_session_table_.DeleteUnfinishedWork();
280 }
281
282 base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() {
283 return weak_factory_.GetWeakPtr();
284 }
285
262 } // namespace precache 286 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/core/precache_database.h ('k') | components/precache/core/precache_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698