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

Unified Diff: chrome/browser/history/shortcuts_database.cc

Issue 10701043: Make ShortcutsBackend a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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/history/shortcuts_database.cc
===================================================================
--- chrome/browser/history/shortcuts_database.cc (revision 145147)
+++ chrome/browser/history/shortcuts_database.cc (working copy)
@@ -12,12 +12,13 @@
#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/time.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_constants.h"
#include "sql/statement.h"
namespace {
-// Using define instead of const char, so I could use ## in the statements.
-#define kShortcutsDBName "omni_box_shortcuts"
+const char* kShortcutsTableName = "omni_box_shortcuts";
void BindShortcutToStatement(
const history::ShortcutsBackend::Shortcut& shortcut,
@@ -40,7 +41,7 @@
const std::string& id,
sql::Connection& db) {
sql::Statement s(db.GetUniqueStatement(
- base::StringPrintf("DELETE FROM %s WHERE %s = ?", kShortcutsDBName,
+ base::StringPrintf("DELETE FROM %s WHERE %s = ?", kShortcutsTableName,
field_name).c_str()));
s.BindString(0, id);
@@ -51,11 +52,8 @@
namespace history {
-const FilePath::CharType ShortcutsDatabase::kShortcutsDatabaseName[] =
- FILE_PATH_LITERAL("Shortcuts");
-
-ShortcutsDatabase::ShortcutsDatabase(const FilePath& folder_path)
- : database_path_(folder_path.Append(FilePath(kShortcutsDatabaseName))) {
+ShortcutsDatabase::ShortcutsDatabase(Profile* profile) {
+ database_path_ = profile->GetPath().Append(chrome::kShortcutsDatabaseName);
}
bool ShortcutsDatabase::Init() {
@@ -81,10 +79,10 @@
bool ShortcutsDatabase::AddShortcut(
const ShortcutsBackend::Shortcut& shortcut) {
sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
- "INSERT INTO " kShortcutsDBName
- " (id, text, url, contents, contents_class, description,"
- " description_class, last_access_time, number_of_hits) "
- "VALUES (?,?,?,?,?,?,?,?,?)"));
+ base::StringPrintf("INSERT INTO %s (id, text, url, contents, "
+ "contents_class, description, description_class, last_access_time, "
+ "number_of_hits) VALUES (?,?,?,?,?,?,?,?,?)",
+ kShortcutsTableName).c_str()));
BindShortcutToStatement(shortcut, &s);
return s.Run();
@@ -93,11 +91,10 @@
bool ShortcutsDatabase::UpdateShortcut(
const ShortcutsBackend::Shortcut& shortcut) {
sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
- "UPDATE " kShortcutsDBName " "
- "SET id=?, text=?, url=?, contents=?, contents_class=?,"
- " description=?, description_class=?, last_access_time=?,"
- " number_of_hits=? "
- "WHERE id=?"));
+ base::StringPrintf("UPDATE %s SET id=?, text=?, url=?, contents=?, "
+ "contents_class=?, description=?, description_class=?, "
+ "last_access_time=?, number_of_hits=? WHERE id=?",
+ kShortcutsTableName).c_str()));
BindShortcutToStatement(shortcut, &s);
s.BindString(9, shortcut.id);
@@ -125,7 +122,8 @@
}
bool ShortcutsDatabase::DeleteAllShortcuts() {
- if (!db_.Execute("DELETE FROM " kShortcutsDBName))
+ if (!db_.Execute(base::StringPrintf("DELETE FROM %s",
+ kShortcutsTableName).c_str()))
return false;
ignore_result(db_.Execute("VACUUM"));
@@ -136,9 +134,9 @@
bool ShortcutsDatabase::LoadShortcuts(GuidToShortcutMap* shortcuts) {
DCHECK(shortcuts);
sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
- "SELECT id, text, url, contents, contents_class, "
- "description, description_class, last_access_time, number_of_hits "
- "FROM " kShortcutsDBName));
+ base::StringPrintf("SELECT id, text, url, contents, contents_class, "
+ "description, description_class, last_access_time, number_of_hits "
+ "FROM %s", kShortcutsTableName).c_str()));
if (!s.is_valid())
return false;
@@ -159,7 +157,7 @@
ShortcutsDatabase::~ShortcutsDatabase() {}
bool ShortcutsDatabase::EnsureTable() {
- if (!db_.DoesTableExist(kShortcutsDBName)) {
+ if (!db_.DoesTableExist(kShortcutsTableName)) {
if (!db_.Execute(base::StringPrintf(
"CREATE TABLE %s ( "
"id VARCHAR PRIMARY KEY, "
@@ -170,7 +168,7 @@
"description VARCHAR, "
"description_class VARCHAR, "
"last_access_time INTEGER, "
- "number_of_hits INTEGER)", kShortcutsDBName).c_str())) {
+ "number_of_hits INTEGER)", kShortcutsTableName).c_str())) {
NOTREACHED();
return false;
}

Powered by Google App Engine
This is Rietveld 408576698