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

Side by Side Diff: chrome/browser/extensions/activity_database.cc

Issue 12262025: Alter the ActivityLog db table schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/extensions/activity_database.h" 8 #include "chrome/browser/extensions/activity_database.h"
9 #include "chrome/browser/history/url_database.h" 9 #include "chrome/browser/history/url_database.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (!committer.Begin()) 43 if (!committer.Begin())
44 return LogInitFailure(); 44 return LogInitFailure();
45 45
46 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
47 // Exclude the database from backups. 47 // Exclude the database from backups.
48 base::mac::SetFileBackupExclusion(db_name); 48 base::mac::SetFileBackupExclusion(db_name);
49 #endif 49 #endif
50 50
51 db_.Preload(); 51 db_.Preload();
52 52
53 // Create the UrlAction database. 53 // Create the DOMAction database.
54 if (InitializeTable(UrlAction::kTableName, UrlAction::kTableStructure) != 54 if (!DOMAction::InitializeTable(&db_))
55 sql::INIT_OK)
56 return LogInitFailure(); 55 return LogInitFailure();
57 56
58 // Create the APIAction database. 57 // Create the APIAction database.
59 if (!APIAction::InitializeTable(&db_)) 58 if (!APIAction::InitializeTable(&db_))
60 return LogInitFailure(); 59 return LogInitFailure();
61 60
62 // Create the BlockedAction database. 61 // Create the BlockedAction database.
63 if (InitializeTable(BlockedAction::kTableName, BlockedAction::kTableStructure) 62 if (!BlockedAction::InitializeTable(&db_))
64 != sql::INIT_OK)
65 return LogInitFailure(); 63 return LogInitFailure();
66 64
67 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 65 sql::InitStatus stat = committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
68 if (stat == sql::INIT_OK) 66 if (stat == sql::INIT_OK)
69 initialized_ = true; 67 initialized_ = true;
70 else 68 else
71 return LogInitFailure(); 69 return LogInitFailure();
72 } 70 }
73 71
74 void ActivityDatabase::LogInitFailure() { 72 void ActivityDatabase::LogInitFailure() {
75 LOG(ERROR) << "Couldn't initialize the activity log database."; 73 LOG(ERROR) << "Couldn't initialize the activity log database.";
76 } 74 }
77 75
78 sql::InitStatus ActivityDatabase::InitializeTable(const char* table_name,
79 const char* table_structure) {
80 if (!db_.DoesTableExist(table_name)) {
81 char table_creator[1000];
82 base::snprintf(table_creator,
83 arraysize(table_creator),
84 "CREATE TABLE %s %s", table_name, table_structure);
85 if (!db_.Execute(table_creator))
86 return sql::INIT_FAILURE;
87 }
88 return sql::INIT_OK;
89 }
90
91 void ActivityDatabase::RecordAction(scoped_refptr<Action> action) { 76 void ActivityDatabase::RecordAction(scoped_refptr<Action> action) {
92 if (initialized_) 77 if (initialized_)
93 action->Record(&db_); 78 action->Record(&db_);
94 } 79 }
95 80
96 void ActivityDatabase::BeginTransaction() { 81 void ActivityDatabase::BeginTransaction() {
97 db_.BeginTransaction(); 82 db_.BeginTransaction();
98 } 83 }
99 84
100 void ActivityDatabase::CommitTransaction() { 85 void ActivityDatabase::CommitTransaction() {
(...skipping 10 matching lines...) Expand all
111 96
112 void ActivityDatabase::Close() { 97 void ActivityDatabase::Close() {
113 db_.Close(); 98 db_.Close();
114 } 99 }
115 100
116 void ActivityDatabase::KillDatabase() { 101 void ActivityDatabase::KillDatabase() {
117 db_.RazeAndClose(); 102 db_.RazeAndClose();
118 } 103 }
119 104
120 } // namespace extensions 105 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_database.h ('k') | chrome/browser/extensions/activity_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698