| 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 "chrome/browser/extensions/activity_log/activity_actions.h" | 5 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 void Action::ParseArgUrl(const std::string& url) { | 125 void Action::ParseArgUrl(const std::string& url) { |
| 126 set_arg_incognito(base::StartsWith(url, constants::kIncognitoUrl, | 126 set_arg_incognito(base::StartsWith(url, constants::kIncognitoUrl, |
| 127 base::CompareCase::SENSITIVE)); | 127 base::CompareCase::SENSITIVE)); |
| 128 if (arg_incognito()) | 128 if (arg_incognito()) |
| 129 set_arg_url(GURL(url.substr(strlen(constants::kIncognitoUrl)))); | 129 set_arg_url(GURL(url.substr(strlen(constants::kIncognitoUrl)))); |
| 130 else | 130 else |
| 131 set_arg_url(GURL(url)); | 131 set_arg_url(GURL(url)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 scoped_ptr<ExtensionActivity> Action::ConvertToExtensionActivity() { | 134 ExtensionActivity Action::ConvertToExtensionActivity() { |
| 135 scoped_ptr<ExtensionActivity> result(new ExtensionActivity); | 135 ExtensionActivity result; |
| 136 | 136 |
| 137 // We do this translation instead of using the same enum because the database | 137 // We do this translation instead of using the same enum because the database |
| 138 // values need to be stable; this allows us to change the extension API | 138 // values need to be stable; this allows us to change the extension API |
| 139 // without affecting the database. | 139 // without affecting the database. |
| 140 switch (action_type()) { | 140 switch (action_type()) { |
| 141 case ACTION_API_CALL: | 141 case ACTION_API_CALL: |
| 142 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_CALL; | 142 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_CALL; |
| 143 break; | 143 break; |
| 144 case ACTION_API_EVENT: | 144 case ACTION_API_EVENT: |
| 145 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_EVENT; | 145 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_EVENT; |
| 146 break; | 146 break; |
| 147 case ACTION_CONTENT_SCRIPT: | 147 case ACTION_CONTENT_SCRIPT: |
| 148 result->activity_type = | 148 result.activity_type = |
| 149 activity_log::EXTENSION_ACTIVITY_TYPE_CONTENT_SCRIPT; | 149 activity_log::EXTENSION_ACTIVITY_TYPE_CONTENT_SCRIPT; |
| 150 break; | 150 break; |
| 151 case ACTION_DOM_ACCESS: | 151 case ACTION_DOM_ACCESS: |
| 152 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_DOM_ACCESS; | 152 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_DOM_ACCESS; |
| 153 break; | 153 break; |
| 154 case ACTION_DOM_EVENT: | 154 case ACTION_DOM_EVENT: |
| 155 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_DOM_EVENT; | 155 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_DOM_EVENT; |
| 156 break; | 156 break; |
| 157 case ACTION_WEB_REQUEST: | 157 case ACTION_WEB_REQUEST: |
| 158 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_WEB_REQUEST; | 158 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_WEB_REQUEST; |
| 159 break; | 159 break; |
| 160 case UNUSED_ACTION_API_BLOCKED: | 160 case UNUSED_ACTION_API_BLOCKED: |
| 161 case ACTION_ANY: | 161 case ACTION_ANY: |
| 162 default: | 162 default: |
| 163 // This shouldn't be reached, but some people might have old or otherwise | 163 // This shouldn't be reached, but some people might have old or otherwise |
| 164 // weird db entries. Treat it like an API call if that happens. | 164 // weird db entries. Treat it like an API call if that happens. |
| 165 result->activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_CALL; | 165 result.activity_type = activity_log::EXTENSION_ACTIVITY_TYPE_API_CALL; |
| 166 break; | 166 break; |
| 167 } | 167 } |
| 168 | 168 |
| 169 result->extension_id.reset(new std::string(extension_id())); | 169 result.extension_id.reset(new std::string(extension_id())); |
| 170 result->time.reset(new double(time().ToJsTime())); | 170 result.time.reset(new double(time().ToJsTime())); |
| 171 result->count.reset(new double(count())); | 171 result.count.reset(new double(count())); |
| 172 result->api_call.reset(new std::string(api_name())); | 172 result.api_call.reset(new std::string(api_name())); |
| 173 result->args.reset(new std::string(Serialize(args()))); | 173 result.args.reset(new std::string(Serialize(args()))); |
| 174 if (action_id() != -1) | 174 if (action_id() != -1) |
| 175 result->activity_id.reset( | 175 result.activity_id.reset( |
| 176 new std::string(base::StringPrintf("%" PRId64, action_id()))); | 176 new std::string(base::StringPrintf("%" PRId64, action_id()))); |
| 177 if (page_url().is_valid()) { | 177 if (page_url().is_valid()) { |
| 178 if (!page_title().empty()) | 178 if (!page_title().empty()) |
| 179 result->page_title.reset(new std::string(page_title())); | 179 result.page_title.reset(new std::string(page_title())); |
| 180 result->page_url.reset(new std::string(SerializePageUrl())); | 180 result.page_url.reset(new std::string(SerializePageUrl())); |
| 181 } | 181 } |
| 182 if (arg_url().is_valid()) | 182 if (arg_url().is_valid()) |
| 183 result->arg_url.reset(new std::string(SerializeArgUrl())); | 183 result.arg_url.reset(new std::string(SerializeArgUrl())); |
| 184 | 184 |
| 185 if (other()) { | 185 if (other()) { |
| 186 scoped_ptr<ExtensionActivity::Other> other_field( | 186 scoped_ptr<ExtensionActivity::Other> other_field( |
| 187 new ExtensionActivity::Other); | 187 new ExtensionActivity::Other); |
| 188 bool prerender; | 188 bool prerender; |
| 189 if (other()->GetBooleanWithoutPathExpansion(constants::kActionPrerender, | 189 if (other()->GetBooleanWithoutPathExpansion(constants::kActionPrerender, |
| 190 &prerender)) { | 190 &prerender)) { |
| 191 other_field->prerender.reset(new bool(prerender)); | 191 other_field->prerender.reset(new bool(prerender)); |
| 192 } | 192 } |
| 193 const base::DictionaryValue* web_request; | 193 const base::DictionaryValue* web_request; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 other_field->dom_verb = | 230 other_field->dom_verb = |
| 231 activity_log::EXTENSION_ACTIVITY_DOM_VERB_MODIFIED; | 231 activity_log::EXTENSION_ACTIVITY_DOM_VERB_MODIFIED; |
| 232 break; | 232 break; |
| 233 default: | 233 default: |
| 234 other_field->dom_verb = | 234 other_field->dom_verb = |
| 235 activity_log::EXTENSION_ACTIVITY_DOM_VERB_NONE; | 235 activity_log::EXTENSION_ACTIVITY_DOM_VERB_NONE; |
| 236 } | 236 } |
| 237 } else { | 237 } else { |
| 238 other_field->dom_verb = activity_log::EXTENSION_ACTIVITY_DOM_VERB_NONE; | 238 other_field->dom_verb = activity_log::EXTENSION_ACTIVITY_DOM_VERB_NONE; |
| 239 } | 239 } |
| 240 result->other.reset(other_field.release()); | 240 result.other.reset(other_field.release()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 return result; | 243 return result; |
| 244 } | 244 } |
| 245 | 245 |
| 246 std::string Action::PrintForDebug() const { | 246 std::string Action::PrintForDebug() const { |
| 247 std::string result = base::StringPrintf("ACTION ID=%" PRId64, action_id()); | 247 std::string result = base::StringPrintf("ACTION ID=%" PRId64, action_id()); |
| 248 result += " EXTENSION ID=" + extension_id() + " CATEGORY="; | 248 result += " EXTENSION ID=" + extension_id() + " CATEGORY="; |
| 249 switch (action_type_) { | 249 switch (action_type_) { |
| 250 case ACTION_API_CALL: | 250 case ACTION_API_CALL: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); | 359 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); |
| 360 if (lhs_other != rhs_other) | 360 if (lhs_other != rhs_other) |
| 361 return lhs_other < rhs_other; | 361 return lhs_other < rhs_other; |
| 362 } | 362 } |
| 363 | 363 |
| 364 // All fields compare as equal if this point is reached. | 364 // All fields compare as equal if this point is reached. |
| 365 return false; | 365 return false; |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace extensions | 368 } // namespace extensions |
| OLD | NEW |