| 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" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 16 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 16 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | 17 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
| 17 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 18 #include "extensions/common/dom_action_types.h" | 19 #include "extensions/common/dom_action_types.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 Action::~Action() {} | 58 Action::~Action() {} |
| 58 | 59 |
| 59 // TODO(mvrable): As an optimization, we might return this directly if the | 60 // TODO(mvrable): As an optimization, we might return this directly if the |
| 60 // refcount is one. However, there are likely to be other stray references in | 61 // refcount is one. However, there are likely to be other stray references in |
| 61 // many cases that will prevent this optimization. | 62 // many cases that will prevent this optimization. |
| 62 scoped_refptr<Action> Action::Clone() const { | 63 scoped_refptr<Action> Action::Clone() const { |
| 63 scoped_refptr<Action> clone( | 64 scoped_refptr<Action> clone( |
| 64 new Action( | 65 new Action( |
| 65 extension_id(), time(), action_type(), api_name(), action_id())); | 66 extension_id(), time(), action_type(), api_name(), action_id())); |
| 66 if (args()) | 67 if (args()) |
| 67 clone->set_args(make_scoped_ptr(args()->DeepCopy())); | 68 clone->set_args(base::WrapUnique(args()->DeepCopy())); |
| 68 clone->set_page_url(page_url()); | 69 clone->set_page_url(page_url()); |
| 69 clone->set_page_title(page_title()); | 70 clone->set_page_title(page_title()); |
| 70 clone->set_page_incognito(page_incognito()); | 71 clone->set_page_incognito(page_incognito()); |
| 71 clone->set_arg_url(arg_url()); | 72 clone->set_arg_url(arg_url()); |
| 72 clone->set_arg_incognito(arg_incognito()); | 73 clone->set_arg_incognito(arg_incognito()); |
| 73 if (other()) | 74 if (other()) |
| 74 clone->set_other(make_scoped_ptr(other()->DeepCopy())); | 75 clone->set_other(base::WrapUnique(other()->DeepCopy())); |
| 75 return clone; | 76 return clone; |
| 76 } | 77 } |
| 77 | 78 |
| 78 void Action::set_args(scoped_ptr<base::ListValue> args) { | 79 void Action::set_args(std::unique_ptr<base::ListValue> args) { |
| 79 args_.reset(args.release()); | 80 args_.reset(args.release()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 base::ListValue* Action::mutable_args() { | 83 base::ListValue* Action::mutable_args() { |
| 83 if (!args_.get()) { | 84 if (!args_.get()) { |
| 84 args_.reset(new base::ListValue()); | 85 args_.reset(new base::ListValue()); |
| 85 } | 86 } |
| 86 return args_.get(); | 87 return args_.get(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void Action::set_page_url(const GURL& page_url) { | 90 void Action::set_page_url(const GURL& page_url) { |
| 90 page_url_ = page_url; | 91 page_url_ = page_url; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void Action::set_arg_url(const GURL& arg_url) { | 94 void Action::set_arg_url(const GURL& arg_url) { |
| 94 arg_url_ = arg_url; | 95 arg_url_ = arg_url; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void Action::set_other(scoped_ptr<base::DictionaryValue> other) { | 98 void Action::set_other(std::unique_ptr<base::DictionaryValue> other) { |
| 98 other_.reset(other.release()); | 99 other_.reset(other.release()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 base::DictionaryValue* Action::mutable_other() { | 102 base::DictionaryValue* Action::mutable_other() { |
| 102 if (!other_.get()) { | 103 if (!other_.get()) { |
| 103 other_.reset(new base::DictionaryValue()); | 104 other_.reset(new base::DictionaryValue()); |
| 104 } | 105 } |
| 105 return other_.get(); | 106 return other_.get(); |
| 106 } | 107 } |
| 107 | 108 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 new std::string(base::StringPrintf("%" PRId64, action_id()))); | 177 new std::string(base::StringPrintf("%" PRId64, action_id()))); |
| 177 if (page_url().is_valid()) { | 178 if (page_url().is_valid()) { |
| 178 if (!page_title().empty()) | 179 if (!page_title().empty()) |
| 179 result.page_title.reset(new std::string(page_title())); | 180 result.page_title.reset(new std::string(page_title())); |
| 180 result.page_url.reset(new std::string(SerializePageUrl())); | 181 result.page_url.reset(new std::string(SerializePageUrl())); |
| 181 } | 182 } |
| 182 if (arg_url().is_valid()) | 183 if (arg_url().is_valid()) |
| 183 result.arg_url.reset(new std::string(SerializeArgUrl())); | 184 result.arg_url.reset(new std::string(SerializeArgUrl())); |
| 184 | 185 |
| 185 if (other()) { | 186 if (other()) { |
| 186 scoped_ptr<ExtensionActivity::Other> other_field( | 187 std::unique_ptr<ExtensionActivity::Other> other_field( |
| 187 new ExtensionActivity::Other); | 188 new ExtensionActivity::Other); |
| 188 bool prerender; | 189 bool prerender; |
| 189 if (other()->GetBooleanWithoutPathExpansion(constants::kActionPrerender, | 190 if (other()->GetBooleanWithoutPathExpansion(constants::kActionPrerender, |
| 190 &prerender)) { | 191 &prerender)) { |
| 191 other_field->prerender.reset(new bool(prerender)); | 192 other_field->prerender.reset(new bool(prerender)); |
| 192 } | 193 } |
| 193 const base::DictionaryValue* web_request; | 194 const base::DictionaryValue* web_request; |
| 194 if (other()->GetDictionaryWithoutPathExpansion(constants::kActionWebRequest, | 195 if (other()->GetDictionaryWithoutPathExpansion(constants::kActionWebRequest, |
| 195 &web_request)) { | 196 &web_request)) { |
| 196 other_field->web_request.reset(new std::string( | 197 other_field->web_request.reset(new std::string( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); | 360 std::string rhs_other = ActivityLogPolicy::Util::Serialize(rhs->other()); |
| 360 if (lhs_other != rhs_other) | 361 if (lhs_other != rhs_other) |
| 361 return lhs_other < rhs_other; | 362 return lhs_other < rhs_other; |
| 362 } | 363 } |
| 363 | 364 |
| 364 // All fields compare as equal if this point is reached. | 365 // All fields compare as equal if this point is reached. |
| 365 return false; | 366 return false; |
| 366 } | 367 } |
| 367 | 368 |
| 368 } // namespace extensions | 369 } // namespace extensions |
| OLD | NEW |