| 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 void BlockedAction::Record(sql::Connection* db) { | 98 bool 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 } |
| 112 } | 117 } |
| 113 | 118 |
| 114 std::string BlockedAction::PrintForDebug() { | 119 std::string BlockedAction::PrintForDebug() { |
| 115 return "ID: " + extension_id() + ", blocked action " + api_call_ + | 120 return "ID: " + extension_id() + ", blocked action " + api_call_ + |
| 116 ", reason: " + ReasonAsString(); | 121 ", reason: " + ReasonAsString(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 std::string BlockedAction::ReasonAsString() const { | 124 std::string BlockedAction::ReasonAsString() const { |
| 120 if (reason_ == ACCESS_DENIED) | 125 if (reason_ == ACCESS_DENIED) |
| 121 return std::string("access_denied"); | 126 return std::string("access_denied"); |
| 122 else if (reason_ == QUOTA_EXCEEDED) | 127 else if (reason_ == QUOTA_EXCEEDED) |
| 123 return std::string("quota_exceeded"); | 128 return std::string("quota_exceeded"); |
| 124 else | 129 else |
| 125 return std::string("unknown_reason_type"); // To avoid Win header name. | 130 return std::string("unknown_reason_type"); // To avoid Win header name. |
| 126 } | 131 } |
| 127 | 132 |
| 128 } // namespace extensions | 133 } // namespace extensions |
| 129 | 134 |
| OLD | NEW |