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

Unified Diff: chrome/browser/predictors/glowplug_key_value_table.cc

Issue 2851473002: predictors: Extract sql key-value tables into separate class. (Closed)
Patch Set: Rebase. Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/predictors/glowplug_key_value_table.cc
diff --git a/chrome/browser/predictors/glowplug_key_value_table.cc b/chrome/browser/predictors/glowplug_key_value_table.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5656b17c5935dc10e7beeeea11810f6816462b0
--- /dev/null
+++ b/chrome/browser/predictors/glowplug_key_value_table.cc
@@ -0,0 +1,40 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/predictors/glowplug_key_value_table.h"
+
+#include "third_party/protobuf/src/google/protobuf/message_lite.h"
+
+namespace predictors {
+
+namespace internal {
+
+void BindDataToStatement(const std::string& key,
+ const google::protobuf::MessageLite& data,
+ sql::Statement* statement) {
+ int size = data.ByteSize();
+ DCHECK_GT(size, 0);
+ std::vector<char> proto_buffer(size);
+ data.SerializeToArray(&proto_buffer[0], size);
+
+ statement->BindString(0, key);
+ statement->BindBlob(1, &proto_buffer[0], size);
+}
+
+std::string GetSelectAllSql(const std::string& table_name) {
+ return base::StringPrintf("SELECT * FROM %s", table_name.c_str());
+}
+std::string GetReplaceSql(const std::string& table_name) {
+ return base::StringPrintf("REPLACE INTO %s (key, proto) VALUES (?,?)",
+ table_name.c_str());
+}
+std::string GetDeleteSql(const std::string& table_name) {
+ return base::StringPrintf("DELETE FROM %s WHERE key=?", table_name.c_str());
+}
+std::string GetDeleteAllSql(const std::string& table_name) {
+ return base::StringPrintf("DELETE FROM %s", table_name.c_str());
+}
+
+} // namespace internal
+} // namespace predictors
« no previous file with comments | « chrome/browser/predictors/glowplug_key_value_table.h ('k') | chrome/browser/predictors/resource_prefetch_predictor_tables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698