Index: chrome/browser/extensions/activity_actions.cc |
diff --git a/chrome/browser/extensions/activity_actions.cc b/chrome/browser/extensions/activity_actions.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0d197fa0919e5c4fa1b4851aa6385fbb203e51e4 |
--- /dev/null |
+++ b/chrome/browser/extensions/activity_actions.cc |
@@ -0,0 +1,46 @@ |
+// Copyright (c) 2013 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 <string> |
+#include "base/logging.h" |
+#include "base/stringprintf.h" |
+#include "chrome/browser/extensions/api_actions.h" |
+ |
+namespace extensions { |
+ |
+// static |
+bool Action::InitializeTableInternal(sql::Connection* db, |
+ const char* table_name, |
+ const char* basic_fields, |
+ const char* content_fields[], |
+ const int num_content_fields) { |
+ if (!db->DoesTableExist(table_name)) { |
+ std::string table_creator = base::StringPrintf( |
+ "CREATE TABLE %s (%s", table_name, basic_fields); |
+ for (int i = 0; i < num_content_fields; i++) { |
+ table_creator += base::StringPrintf(", %s LONGVARCHAR", |
+ content_fields[i]); |
+ } |
+ table_creator += ")"; |
+ if (!db->Execute(table_creator.c_str())) |
+ return false; |
+ } else { |
+ // In case we ever want to add new fields, this initializes them to be |
+ // empty strings. |
+ for (int i = 0; i < num_content_fields; i++) { |
+ if (!db->DoesColumnExist(table_name, content_fields[i])) { |
+ std::string table_updater = base::StringPrintf( |
+ "ALTER TABLE %s ADD COLUMN %s LONGVARCHAR; ", |
+ table_name, |
+ content_fields[i]); |
+ if (!db->Execute(table_updater.c_str())) |
+ return false; |
+ } |
+ } |
+ } |
+ return true; |
+} |
+ |
+} // namespace extensions |
+ |