| Index: chrome/browser/extensions/manager_actions.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/manager_actions.cc (revision 0)
|
| +++ chrome/browser/extensions/manager_actions.cc (revision 0)
|
| @@ -0,0 +1,131 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// User of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <string>
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/extensions/manager_actions.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +const char* manager_table_name_ = "activitylog_managers";
|
| +const char* manager_table_structure_ = "("
|
| + "extension_id LONGVARCHAR NOT NULL, "
|
| + "time INTEGER NOT NULL, "
|
| + "manager_action_type LONGVARCHAR NOT NULL, "
|
| + "target_type LONGVARCHAR NOT NULL, "
|
| + "api_call LONGVARCHAR NOT NULL)";
|
| +
|
| +ManagerAction::ManagerAction(const std::string& extension_id,
|
| + const ManagerActionType verb,
|
| + const ManagerTargetType target,
|
| + const std::string& api_call,
|
| + const base::Time& time)
|
| + : extension_id_(extension_id),
|
| + verb_(verb),
|
| + target_(target),
|
| + api_call_(api_call),
|
| + time_(time) { }
|
| +
|
| +ManagerAction::~ManagerAction() {
|
| +}
|
| +
|
| +std::string ManagerAction::PrettyPrintFori18n() {
|
| + // TODO(felt): implement this for real when the UI is redesigned.
|
| + return PrettyPrintForDebug();
|
| +}
|
| +
|
| +std::string ManagerAction::PrettyPrintForDebug() {
|
| + // TODO(felt): implement this for real when the UI is redesigned.
|
| + return "ID: " + extension_id_ + ", VERB: " + VerbAsString() +
|
| + ", TARGET: " + TargetAsString() + ", API: " + api_call_;
|
| +}
|
| +
|
| +std::string ManagerAction::VerbAsString() const {
|
| + switch (verb_) {
|
| + case READ:
|
| + return "READ";
|
| + case MODIFIED:
|
| + return "MODIFIED";
|
| + case DELETED:
|
| + return "DELETED";
|
| + case ADDED:
|
| + return "ADDED";
|
| + case ENABLED:
|
| + return "ENABLED";
|
| + case DISABLED:
|
| + return "DISABLED";
|
| + case CREATED:
|
| + return "CREATED";
|
| + default:
|
| + return "UNKNOWN_ACTION";
|
| + }
|
| +}
|
| +
|
| +std::string ManagerAction::TargetAsString() const {
|
| + switch (target_) {
|
| + case BOOKMARK:
|
| + return "BOOKMARK";
|
| + case TABS:
|
| + return "TABS";
|
| + case HISTORY:
|
| + return "HISTORY";
|
| + case COOKIES:
|
| + return "COOKIES";
|
| + case BROWSER_ACTION:
|
| + return "BROWSER_ACTION";
|
| + case NOTIFICATION:
|
| + return "NOTIFICATION";
|
| + case OMNIBOX:
|
| + return "OMNIBOX";
|
| + default:
|
| + return "UNKNOWN_TARGET";
|
| + }
|
| +}
|
| +
|
| +ManagerAction::ManagerActionType ManagerAction::StringAsActionType(
|
| + const std::string& str) {
|
| + if (str == "READ") {
|
| + return READ;
|
| + } else if (str == "MODIFIED") {
|
| + return MODIFIED;
|
| + } else if (str == "DELETED") {
|
| + return DELETED;
|
| + } else if (str == "ADDED") {
|
| + return ADDED;
|
| + } else if (str == "ENABLED") {
|
| + return ENABLED;
|
| + } else if (str == "DISABLED") {
|
| + return DISABLED;
|
| + } else if (str == "CREATED") {
|
| + return CREATED;
|
| + } else {
|
| + return UNKNOWN_ACTION;
|
| + }
|
| +}
|
| +
|
| +// The all-caps strings match the enum names. The lowercase strings match the
|
| +// actual manager object names (e.g., cookies.remove(...);).
|
| +ManagerAction::ManagerTargetType ManagerAction::StringAsTargetType(
|
| + const std::string& str) {
|
| + if (str == "BOOKMARK" || str == "bookmark") {
|
| + return BOOKMARK;
|
| + } else if (str == "TABS" || str == "tabs") {
|
| + return TABS;
|
| + } else if (str == "HISTORY" || str == "history") {
|
| + return HISTORY;
|
| + } else if (str == "COOKIES" || str == "cookies") {
|
| + return COOKIES;
|
| + } else if (str == "BROWSER_ACTION" || str == "browser_action") {
|
| + return BROWSER_ACTION;
|
| + } else if (str == "NOTIFICATION" || str == "notification") {
|
| + return NOTIFICATION;
|
| + } else if (str == "OMNIBOX" || str == "omnibox") {
|
| + return OMNIBOX;
|
| + } else {
|
| + return UNKNOWN_TARGET;
|
| + }
|
| +}
|
| +
|
| +} // namespace extensions
|
| +
|
|
|