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

Side by Side Diff: components/offline_pages/background/request_queue_store_sql.cc

Issue 2113383002: More detailed implementation of the RequestPicker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: second round of CR comments Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/offline_pages/background/request_queue_store_sql.h" 5 #include "components/offline_pages/background/request_queue_store_sql.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/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/offline_pages/background/save_page_request.h" 13 #include "components/offline_pages/background/save_page_request.h"
14 #include "sql/connection.h" 14 #include "sql/connection.h"
15 #include "sql/statement.h" 15 #include "sql/statement.h"
16 #include "sql/transaction.h" 16 #include "sql/transaction.h"
17 17
18 namespace offline_pages { 18 namespace offline_pages {
19 19
20 namespace { 20 namespace {
21 21
22 // This is a macro instead of a const so that 22 // This is a macro instead of a const so that
23 // it can be used inline in other SQL statements below. 23 // it can be used inline in other SQL statements below.
24 #define REQUEST_QUEUE_TABLE_NAME "request_queue_v1" 24 #define REQUEST_QUEUE_TABLE_NAME "request_queue_v1"
25 const bool kUserRequested = true;
25 26
26 bool CreateRequestQueueTable(sql::Connection* db) { 27 bool CreateRequestQueueTable(sql::Connection* db) {
27 const char kSql[] = "CREATE TABLE IF NOT EXISTS " REQUEST_QUEUE_TABLE_NAME 28 const char kSql[] = "CREATE TABLE IF NOT EXISTS " REQUEST_QUEUE_TABLE_NAME
28 " (request_id INTEGER PRIMARY KEY NOT NULL," 29 " (request_id INTEGER PRIMARY KEY NOT NULL,"
29 " creation_time INTEGER NOT NULL," 30 " creation_time INTEGER NOT NULL,"
30 " activation_time INTEGER NOT NULL DEFAULT 0," 31 " activation_time INTEGER NOT NULL DEFAULT 0,"
31 " last_attempt_time INTEGER NOT NULL DEFAULT 0," 32 " last_attempt_time INTEGER NOT NULL DEFAULT 0,"
32 " attempt_count INTEGER NOT NULL," 33 " attempt_count INTEGER NOT NULL,"
33 " url VARCHAR NOT NULL," 34 " url VARCHAR NOT NULL,"
34 " client_namespace VARCHAR NOT NULL," 35 " client_namespace VARCHAR NOT NULL,"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 base::Time::FromInternalValue(statement.ColumnInt64(1)); 87 base::Time::FromInternalValue(statement.ColumnInt64(1));
87 const base::Time activation_time = 88 const base::Time activation_time =
88 base::Time::FromInternalValue(statement.ColumnInt64(2)); 89 base::Time::FromInternalValue(statement.ColumnInt64(2));
89 const base::Time last_attempt_time = 90 const base::Time last_attempt_time =
90 base::Time::FromInternalValue(statement.ColumnInt64(3)); 91 base::Time::FromInternalValue(statement.ColumnInt64(3));
91 const int64_t last_attempt_count = statement.ColumnInt64(4); 92 const int64_t last_attempt_count = statement.ColumnInt64(4);
92 const GURL url(statement.ColumnString(5)); 93 const GURL url(statement.ColumnString(5));
93 const ClientId client_id(statement.ColumnString(6), 94 const ClientId client_id(statement.ColumnString(6),
94 statement.ColumnString(7)); 95 statement.ColumnString(7));
95 96
96 SavePageRequest request(id, url, client_id, creation_time, activation_time); 97 SavePageRequest request(
98 id, url, client_id, creation_time, activation_time, kUserRequested);
97 request.set_last_attempt_time(last_attempt_time); 99 request.set_last_attempt_time(last_attempt_time);
98 request.set_attempt_count(last_attempt_count); 100 request.set_attempt_count(last_attempt_count);
99 return request; 101 return request;
100 } 102 }
101 103
102 RequestQueueStore::UpdateStatus InsertOrReplace( 104 RequestQueueStore::UpdateStatus InsertOrReplace(
103 sql::Connection* db, 105 sql::Connection* db,
104 const SavePageRequest& request) { 106 const SavePageRequest& request) {
105 // In order to use the enums in the Bind* methods, keep the order of fields 107 // In order to use the enums in the Bind* methods, keep the order of fields
106 // the same as in the definition/select query. 108 // the same as in the definition/select query.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 318 }
317 319
318 void RequestQueueStoreSQL::OnResetDone(const ResetCallback& callback, 320 void RequestQueueStoreSQL::OnResetDone(const ResetCallback& callback,
319 bool success) { 321 bool success) {
320 // Complete connection initialization post reset. 322 // Complete connection initialization post reset.
321 OnOpenConnectionDone(success); 323 OnOpenConnectionDone(success);
322 callback.Run(success); 324 callback.Run(success);
323 } 325 }
324 326
325 } // namespace offline_pages 327 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698