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

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

Issue 11421192: Save extension activity log to a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6 #include "chrome/browser/extensions/activity_database.h"
7 #include "chrome/browser/history/url_database.h"
8
9 namespace activity {
10
11 ActivityDatabase::ActivityDatabase() {
12 }
13
14 ActivityDatabase::~ActivityDatabase() {
15 }
16
17 sql::InitStatus ActivityDatabase::Init(const FilePath& db_name,
18 sql::ErrorDelegate* error_delegate) {
19 db_.set_error_delegate(error_delegate);
20 db_.set_page_size(4096);
21 db_.set_cache_size(32);
22
23 if (!db_.Open(db_name)) {
24 LOG(ERROR) << db_.GetErrorMessage();
25 return sql::INIT_FAILURE;
26 }
27
28 // Wrap the initialization in a transaction so that the db doesn't
29 // get corrupted if init fails/crashes.
30 sql::Transaction committer(&db_);
31 if (!committer.Begin())
32 return sql::INIT_FAILURE;
33
34 db_.Preload();
35
36 // Create the UrlAction database.
37 if (!db_.DoesTableExist(activity::url_table_name_.c_str()))
38 if (!db_.Execute(url_table_creator_.c_str()))
39 return sql::INIT_FAILURE;
40
41 // Create the ManagerAction database.
42 if (!db_.DoesTableExist(activity::manager_table_name_.c_str()))
43 if (!db_.Execute(activity::manager_table_creator_.c_str()))
44 return sql::INIT_FAILURE;
45
46 // TODO(felt): do we need to do a version check?
47
48 return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
49 }
50
51 // The table structure is defined by activity::url_table_creator
52 // in url_actions.h.
53 bool ActivityDatabase::RecordAction(const UrlAction& action) {
54 std::string sql_str = "INSERT INTO " + activity::url_table_name_ +
55 " (extension_id, time, url_action_type, url, url_title, api_call)"
56 " VALUES (?,?,?,?,?,?)";
57 sql::Statement statement(db_.GetCachedStatement(
58 sql::StatementID("url_action_insertion"), sql_str.c_str()));
59 statement.BindString(0, action.extension_id());
60 statement.BindInt64(1, action.time().ToInternalValue());
61 statement.BindString(2, action.VerbAsString());
62 statement.BindString(3,
63 history::URLDatabase::GURLToDatabaseURL(action.url()));
64 statement.BindString16(4, action.url_title());
65 statement.BindString(5, action.api_call());
66 return statement.Run();
67 }
68
69 // The table structure is defined by activity::manager_table_creator
70 // in manager_actions.h.
71 bool ActivityDatabase::RecordAction(const ManagerAction& action) {
72 std::string sql_str = "INSERT INTO " + activity::manager_table_name_ +
73 " (extension_id, time, manager_action_type, target_type, api_call)"
74 " VALUES (?,?,?,?,?)";
75 sql::Statement statement(db_.GetCachedStatement(
76 sql::StatementID("manager_action_insertion"), sql_str.c_str()));
77 statement.BindString(0, action.extension_id());
78 statement.BindInt64(2, action.time().ToInternalValue());
79 statement.BindString(3, action.VerbAsString());
80 statement.BindString(4, action.TargetAsString());
81 statement.BindString(5, action.api_call());
82 return statement.Run();
83 }
84 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698