OLD | NEW |
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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "chrome/browser/extensions/activity_log/blocked_actions.h" | 7 #include "chrome/browser/extensions/activity_log/blocked_actions.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 using content::BrowserThread; | 10 using content::BrowserThread; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return false; | 88 return false; |
89 } | 89 } |
90 } | 90 } |
91 return InitializeTableInternal(db, | 91 return InitializeTableInternal(db, |
92 kTableName, | 92 kTableName, |
93 kTableContentFields, | 93 kTableContentFields, |
94 kTableFieldTypes, | 94 kTableFieldTypes, |
95 arraysize(kTableContentFields)); | 95 arraysize(kTableContentFields)); |
96 } | 96 } |
97 | 97 |
98 bool BlockedAction::Record(sql::Connection* db) { | 98 void BlockedAction::Record(sql::Connection* db) { |
99 std::string sql_str = "INSERT INTO " + std::string(kTableName) | 99 std::string sql_str = "INSERT INTO " + std::string(kTableName) |
100 + " (extension_id, time, api_call, args, reason, extra)" | 100 + " (extension_id, time, api_call, args, reason, extra)" |
101 " VALUES (?,?,?,?,?,?)"; | 101 " VALUES (?,?,?,?,?,?)"; |
102 sql::Statement statement(db->GetCachedStatement( | 102 sql::Statement statement(db->GetCachedStatement( |
103 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | 103 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); |
104 statement.BindString(0, extension_id()); | 104 statement.BindString(0, extension_id()); |
105 statement.BindInt64(1, time().ToInternalValue()); | 105 statement.BindInt64(1, time().ToInternalValue()); |
106 statement.BindString(2, api_call_); | 106 statement.BindString(2, api_call_); |
107 statement.BindString(3, args_); | 107 statement.BindString(3, args_); |
108 statement.BindInt(4, static_cast<int>(reason_)); | 108 statement.BindInt(4, static_cast<int>(reason_)); |
109 statement.BindString(5, extra_); | 109 statement.BindString(5, extra_); |
110 if (!statement.Run()) { | 110 if (!statement.Run()) |
111 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; | 111 LOG(ERROR) << "Activity log database I/O failed: " << sql_str; |
112 statement.Clear(); | |
113 return false; | |
114 } else { | |
115 return true; | |
116 } | |
117 } | 112 } |
118 | 113 |
119 std::string BlockedAction::PrintForDebug() { | 114 std::string BlockedAction::PrintForDebug() { |
120 return "ID: " + extension_id() + ", blocked action " + api_call_ + | 115 return "ID: " + extension_id() + ", blocked action " + api_call_ + |
121 ", reason: " + ReasonAsString(); | 116 ", reason: " + ReasonAsString(); |
122 } | 117 } |
123 | 118 |
124 std::string BlockedAction::ReasonAsString() const { | 119 std::string BlockedAction::ReasonAsString() const { |
125 if (reason_ == ACCESS_DENIED) | 120 if (reason_ == ACCESS_DENIED) |
126 return std::string("access_denied"); | 121 return std::string("access_denied"); |
127 else if (reason_ == QUOTA_EXCEEDED) | 122 else if (reason_ == QUOTA_EXCEEDED) |
128 return std::string("quota_exceeded"); | 123 return std::string("quota_exceeded"); |
129 else | 124 else |
130 return std::string("unknown_reason_type"); // To avoid Win header name. | 125 return std::string("unknown_reason_type"); // To avoid Win header name. |
131 } | 126 } |
132 | 127 |
133 } // namespace extensions | 128 } // namespace extensions |
134 | 129 |
OLD | NEW |