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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_actions.cc

Issue 14774012: Replaced enum strings with ints in Activity Log database (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing Singleton dep Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <string> 5 #include <string>
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/extensions/activity_log/api_actions.h" 8 #include "chrome/browser/extensions/activity_log/api_actions.h"
9 9
10 namespace extensions { 10 namespace extensions {
11 11
12 const char* Action::kTableBasicFields = 12 const char* Action::kTableBasicFields =
13 "extension_id LONGVARCHAR NOT NULL, " 13 "extension_id LONGVARCHAR NOT NULL, "
14 "time INTEGER NOT NULL"; 14 "time INTEGER NOT NULL";
15 15
16 Action::Action(const std::string& extension_id, 16 Action::Action(const std::string& extension_id,
17 const base::Time& time) 17 const base::Time& time)
18 : extension_id_(extension_id), 18 : extension_id_(extension_id),
19 time_(time) {} 19 time_(time) {}
20 20
21 // static 21 // static
22 bool Action::InitializeTableInternal(sql::Connection* db, 22 bool Action::InitializeTableInternal(sql::Connection* db,
23 const char* table_name, 23 const char* table_name,
24 const char* content_fields[], 24 const char* content_fields[],
25 const char* field_types[],
25 const int num_content_fields) { 26 const int num_content_fields) {
26 if (!db->DoesTableExist(table_name)) { 27 if (!db->DoesTableExist(table_name)) {
27 std::string table_creator = base::StringPrintf( 28 std::string table_creator = base::StringPrintf(
28 "CREATE TABLE %s (%s", table_name, kTableBasicFields); 29 "CREATE TABLE %s (%s", table_name, kTableBasicFields);
29 for (int i = 0; i < num_content_fields; i++) { 30 for (int i = 0; i < num_content_fields; i++) {
30 table_creator += base::StringPrintf(", %s LONGVARCHAR", 31 table_creator += base::StringPrintf(", %s %s",
31 content_fields[i]); 32 content_fields[i],
33 field_types[i]);
32 } 34 }
33 table_creator += ")"; 35 table_creator += ")";
34 if (!db->Execute(table_creator.c_str())) 36 if (!db->Execute(table_creator.c_str()))
35 return false; 37 return false;
36 } else { 38 } else {
37 // In case we ever want to add new fields, this initializes them to be 39 // In case we ever want to add new fields, this initializes them to be
38 // empty strings. 40 // empty strings.
39 for (int i = 0; i < num_content_fields; i++) { 41 for (int i = 0; i < num_content_fields; i++) {
40 if (!db->DoesColumnExist(table_name, content_fields[i])) { 42 if (!db->DoesColumnExist(table_name, content_fields[i])) {
41 std::string table_updater = base::StringPrintf( 43 std::string table_updater = base::StringPrintf(
42 "ALTER TABLE %s ADD COLUMN %s LONGVARCHAR; ", 44 "ALTER TABLE %s ADD COLUMN %s %s; ",
43 table_name, 45 table_name,
44 content_fields[i]); 46 content_fields[i],
47 field_types[i]);
45 if (!db->Execute(table_updater.c_str())) 48 if (!db->Execute(table_updater.c_str()))
46 return false; 49 return false;
47 } 50 }
48 } 51 }
49 } 52 }
50 return true; 53 return true;
51 } 54 }
52 55
53 } // namespace extensions 56 } // namespace extensions
54 57
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698