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

Unified Diff: chrome/browser/extensions/activity_log/activity_log.cc

Issue 19690003: Extension activity log database refactoring (step 3) (Closed) Base URL: http://git.chromium.org/chromium/src.git@refactor2
Patch Set: Rebase Created 7 years, 5 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/extensions/activity_log/activity_log.cc
diff --git a/chrome/browser/extensions/activity_log/activity_log.cc b/chrome/browser/extensions/activity_log/activity_log.cc
index 4233e12ac192dbb6c77bb553907a690b6bbcda0f..076d7761625cad564e1bff3aaa17fb565ea4200f 100644
--- a/chrome/browser/extensions/activity_log/activity_log.cc
+++ b/chrome/browser/extensions/activity_log/activity_log.cc
@@ -8,10 +8,9 @@
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_checker.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
-#include "chrome/browser/extensions/activity_log/api_actions.h"
-#include "chrome/browser/extensions/activity_log/blocked_actions.h"
#include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h"
#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h"
#include "chrome/browser/extensions/extension_service.h"
@@ -253,6 +252,17 @@ void ActivityLog::RemoveObserver(ActivityLog::Observer* observer) {
observers_->RemoveObserver(observer);
}
+void ActivityLog::LogAction(scoped_refptr<Action> action) {
+ if (IsLogEnabled() &&
+ !ActivityLogAPI::IsExtensionWhitelisted(action->extension_id())) {
+ if (policy_)
+ policy_->ProcessAction(action);
+ observers_->Notify(&Observer::OnExtensionActivity, action);
+ if (testing_mode_)
+ LOG(INFO) << action->PrintForDebug();
+ }
+}
+
void ActivityLog::LogAPIActionInternal(const std::string& extension_id,
const std::string& api_call,
base::ListValue* args,
@@ -265,35 +275,21 @@ void ActivityLog::LogAPIActionInternal(const std::string& extension_id,
APIAction::LookupTabId(api_call, args, profile_);
}
- if (policy_) {
- scoped_ptr<base::DictionaryValue> details(new DictionaryValue());
- std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA);
- details->SetString(key, extra);
- DCHECK((type == APIAction::CALL || type == APIAction::EVENT_CALLBACK) &&
- "Unexpected APIAction call type.");
- policy_->ProcessAction(
- type == APIAction::CALL ? ActivityLogPolicy::ACTION_API :
- ActivityLogPolicy::ACTION_EVENT,
- extension_id,
- api_call,
- GURL(),
- args,
- details.get());
- }
-
- // TODO(felt) Logging should be done more efficiently, so that it
- // doesn't require construction of the action object.
- scoped_refptr<APIAction> action = new APIAction(
- extension_id,
- base::Time::Now(),
- type,
- api_call,
- MakeArgList(args),
- *args,
- extra);
-
- observers_->Notify(&Observer::OnExtensionActivity, action);
- if (testing_mode_) LOG(INFO) << action->PrintForDebug();
+ DCHECK((type == APIAction::CALL || type == APIAction::EVENT_CALLBACK) &&
+ "Unexpected APIAction call type.");
+
+ scoped_refptr<Action> action;
+ action = new Action(extension_id,
+ base::Time::Now(),
+ type == APIAction::CALL ? Action::ACTION_API_CALL
+ : Action::ACTION_API_EVENT);
+ action->set_api_name(api_call);
+ action->set_args(make_scoped_ptr(args->DeepCopy()));
+ // TODO(mvrable): Factor common key strings out as constants.
+ if (!extra.empty())
+ action->mutable_other()->SetString("extra", extra);
+
+ LogAction(action);
} else {
LOG(ERROR) << "Unknown API call! " << api_call;
}
@@ -338,29 +334,17 @@ void ActivityLog::LogBlockedAction(const std::string& extension_id,
if (!IsLogEnabled() ||
ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return;
- if (policy_) {
- scoped_ptr<base::DictionaryValue> details(new DictionaryValue());
- std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_REASON);
- details->SetInteger(key, static_cast<int>(reason));
- key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA);
- details->SetString(key, extra);
- policy_->ProcessAction(
- ActivityLogPolicy::ACTION_BLOCKED,
- extension_id,
- blocked_call,
- GURL(),
- args,
- details.get());
- }
-
- scoped_refptr<BlockedAction> action = new BlockedAction(extension_id,
- base::Time::Now(),
- blocked_call,
- MakeArgList(args),
- reason,
- extra);
- observers_->Notify(&Observer::OnExtensionActivity, action);
- if (testing_mode_) LOG(INFO) << action->PrintForDebug();
+ scoped_refptr<Action> action;
+ action =
+ new Action(extension_id, base::Time::Now(), Action::ACTION_API_BLOCKED);
+ action->set_api_name(blocked_call);
+ action->set_args(make_scoped_ptr(args->DeepCopy()));
+ // TODO(mvrable): Factor common key strings out as constants.
+ action->mutable_other()->SetInteger("reason", static_cast<int>(reason));
+ if (!extra.empty())
+ action->mutable_other()->SetString("extra", extra);
+
+ LogAction(action);
}
void ActivityLog::LogDOMAction(const std::string& extension_id,
@@ -372,40 +356,29 @@ void ActivityLog::LogDOMAction(const std::string& extension_id,
const std::string& extra) {
if (!IsLogEnabled() ||
ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return;
- if (call_type == DomActionType::METHOD && api_call == "XMLHttpRequest.open")
- call_type = DomActionType::XHR;
- if (policy_) {
- scoped_ptr<base::DictionaryValue> details(new DictionaryValue());
- std::string key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_DOM_ACTION);
- details->SetInteger(key, static_cast<int>(call_type));
- key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_URL_TITLE);
- details->SetString(key, url_title);
- key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA);
- details->SetString(key, extra);
- policy_->ProcessAction(
- ActivityLogPolicy::ACTION_DOM,
- extension_id,
- api_call,
- url,
- args,
- details.get());
+ Action::ActionType action_type = Action::ACTION_DOM_ACCESS;
+ if (call_type == DomActionType::INSERTED) {
+ action_type = Action::ACTION_CONTENT_SCRIPT;
+ } else if (call_type == DomActionType::METHOD &&
+ api_call == "XMLHttpRequest.open") {
+ call_type = DomActionType::XHR;
+ action_type = Action::ACTION_DOM_XHR;
}
-
- // TODO(felt) Logging should be done more efficiently, so that it
- // doesn't require construction of the action object.
- scoped_refptr<DOMAction> action = new DOMAction(
- extension_id,
- base::Time::Now(),
- call_type,
- url,
- url_title,
- api_call,
- MakeArgList(args),
- extra);
- observers_->Notify(&Observer::OnExtensionActivity, action);
- if (testing_mode_) LOG(INFO) << action->PrintForDebug();
+ scoped_refptr<Action> action;
+ action = new Action(extension_id, base::Time::Now(), action_type);
+ action->set_api_name(api_call);
+ if (args)
+ action->set_args(make_scoped_ptr(args->DeepCopy()));
+ action->set_page_url(url);
+ // TODO(mvrable): Factor common key strings out as constants.
+ action->set_page_title(base::UTF16ToUTF8(url_title));
+ action->mutable_other()->SetInteger("dom_verb", static_cast<int>(call_type));
+ if (!extra.empty())
+ action->mutable_other()->SetString("extra", extra);
+
+ LogAction(action);
}
void ActivityLog::LogWebRequestAction(const std::string& extension_id,
@@ -413,43 +386,20 @@ void ActivityLog::LogWebRequestAction(const std::string& extension_id,
const std::string& api_call,
scoped_ptr<DictionaryValue> details,
const std::string& extra) {
- string16 null_title;
if (!IsLogEnabled() ||
ActivityLogAPI::IsExtensionWhitelisted(extension_id)) return;
- std::string details_string;
- if (policy_) {
- scoped_ptr<base::DictionaryValue> details(new DictionaryValue());
- std::string key = policy_->GetKey(
- ActivityLogPolicy::PARAM_KEY_DETAILS_STRING);
- details->SetString(key, details_string);
- key = policy_->GetKey(ActivityLogPolicy::PARAM_KEY_EXTRA);
- details->SetString(key, extra);
- policy_->ProcessAction(
- ActivityLogPolicy::ACTION_WEB_REQUEST,
- extension_id,
- api_call,
- url,
- NULL,
- details.get());
- }
-
- JSONStringValueSerializer serializer(&details_string);
- serializer.SerializeAndOmitBinaryValues(*details);
-
- // TODO(felt) Logging should be done more efficiently, so that it
- // doesn't require construction of the action object.
- scoped_refptr<DOMAction> action = new DOMAction(
- extension_id,
- base::Time::Now(),
- DomActionType::WEBREQUEST,
- url,
- null_title,
- api_call,
- details_string,
- extra);
- observers_->Notify(&Observer::OnExtensionActivity, action);
- if (testing_mode_) LOG(INFO) << action->PrintForDebug();
+ scoped_refptr<Action> action;
+ action =
+ new Action(extension_id, base::Time::Now(), Action::ACTION_WEB_REQUEST);
+ action->set_api_name(api_call);
+ action->set_page_url(url);
+ // TODO(mvrable): Factor common key strings out as constants.
+ action->mutable_other()->Set("web_request", details.release());
+ if (!extra.empty())
+ action->mutable_other()->SetString("extra", extra);
+
+ LogAction(action);
}
void ActivityLog::GetActions(

Powered by Google App Engine
This is Rietveld 408576698