Chromium Code Reviews| Index: extensions/common/user_script.cc |
| diff --git a/extensions/common/user_script.cc b/extensions/common/user_script.cc |
| index ddf1fb39c0545226441ebdcd0809d996483d004f..50fb06269886679633301d040d3e595a64fe77a8 100644 |
| --- a/extensions/common/user_script.cc |
| +++ b/extensions/common/user_script.cc |
| @@ -95,11 +95,42 @@ UserScript::UserScript() |
| match_about_blank_(false), |
| incognito_enabled_(false) {} |
| -UserScript::UserScript(const UserScript& other) = default; |
| - |
| UserScript::~UserScript() { |
| } |
| +// static. |
| +std::unique_ptr<UserScript> UserScript::CopyFrom(const UserScript& other) { |
| + std::unique_ptr<UserScript> script(new UserScript()); |
| + script->run_location_ = other.run_location_; |
| + script->name_space_ = other.name_space_; |
| + script->name_ = other.name_; |
| + script->description_ = other.description_; |
| + script->version_ = other.version_; |
| + script->globs_ = other.globs_; |
| + script->exclude_globs_ = other.exclude_globs_; |
| + script->url_set_ = other.url_set_; |
| + script->exclude_url_set_ = other.exclude_url_set_; |
| + |
| + // Note: File content is not copied. |
|
Devlin
2016/08/17 16:39:31
Won't this copy file content? The copy ctor is de
lazyboy
2016/08/17 18:55:52
Good catch, I've made the copy ctor non-default.
|
| + for (const std::unique_ptr<File>& file : other.js_scripts()) { |
| + std::unique_ptr<File> file_copy(new File(*file)); |
| + script->js_scripts_.push_back(std::move(file_copy)); |
| + } |
| + for (const std::unique_ptr<File>& file : other.css_scripts()) { |
| + std::unique_ptr<File> file_copy(new File(*file)); |
| + script->css_scripts_.push_back(std::move(file_copy)); |
| + } |
| + script->host_id_ = other.host_id_; |
| + script->consumer_instance_type_ = other.consumer_instance_type_; |
| + script->user_script_id_ = other.user_script_id_; |
| + script->emulate_greasemonkey_ = other.emulate_greasemonkey_; |
| + script->match_all_frames_ = other.match_all_frames_; |
| + script->match_about_blank_ = other.match_about_blank_; |
| + script->incognito_enabled_ = other.incognito_enabled_; |
| + |
| + return script; |
| +} |
| + |
| void UserScript::add_url_pattern(const URLPattern& pattern) { |
| url_set_.AddPattern(pattern); |
| } |
| @@ -193,10 +224,8 @@ void UserScript::PickleURLPatternSet(base::Pickle* pickle, |
| void UserScript::PickleScripts(base::Pickle* pickle, |
| const FileList& scripts) const { |
| pickle->WriteUInt32(scripts.size()); |
| - for (FileList::const_iterator file = scripts.begin(); |
| - file != scripts.end(); ++file) { |
| + for (const std::unique_ptr<File>& file : scripts) |
| file->Pickle(pickle); |
| - } |
| } |
| void UserScript::Unpickle(const base::Pickle& pickle, |
| @@ -282,9 +311,9 @@ void UserScript::UnpickleScripts(const base::Pickle& pickle, |
| CHECK(iter->ReadUInt32(&num_files)); |
| scripts->clear(); |
| for (uint32_t i = 0; i < num_files; ++i) { |
| - File file; |
| - file.Unpickle(pickle, iter); |
| - scripts->push_back(file); |
| + std::unique_ptr<File> file(new File()); |
| + file->Unpickle(pickle, iter); |
| + scripts->push_back(std::move(file)); |
| } |
| } |
| @@ -297,11 +326,4 @@ bool operator<(const UserScriptIDPair& a, const UserScriptIDPair& b) { |
| return a.id < b.id; |
| } |
| -bool operator<(const UserScript& script1, const UserScript& script2) { |
| - // The only kind of script that should be compared is the kind that has its |
| - // IDs initialized to a meaningful value. |
| - DCHECK(script1.id() != -1 && script2.id() != -1); |
| - return script1.id() < script2.id(); |
| -} |
| - |
| } // namespace extensions |