diff options
author | limasdf <limasdf@gmail.com> | 2015-12-15 22:12:08 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-16 06:13:51 +0000 |
commit | 4e0992ba1a9d3c8d15bae3ffbb60f52a02f52680 (patch) | |
tree | 1a1b79aa81158b5b3da78822d7cef153fd0a21f7 /extensions/renderer | |
parent | 0d19169180f5aa8a2dbbc8c890aee8bd958b51a1 (diff) | |
download | chromium_src-4e0992ba1a9d3c8d15bae3ffbb60f52a02f52680.zip chromium_src-4e0992ba1a9d3c8d15bae3ffbb60f52a02f52680.tar.gz chromium_src-4e0992ba1a9d3c8d15bae3ffbb60f52a02f52680.tar.bz2 |
Remove ScopedVector from /extenisons part#3
C++ 11 enables containers that contain move-only type, scoped_ptr.
So, Use std::vector<scoped_ptr<Foo>> instead of ScopedVector.
Also, use std::move() instead of scoped_ptr::Pass() where possible.
BUG=554289
R=rdevlin.cronin@chromium.org
Review URL: https://codereview.chromium.org/1522373002
Cr-Commit-Position: refs/heads/master@{#365485}
Diffstat (limited to 'extensions/renderer')
-rw-r--r-- | extensions/renderer/i18n_custom_bindings.cc | 13 | ||||
-rw-r--r-- | extensions/renderer/script_injection_manager.cc | 65 | ||||
-rw-r--r-- | extensions/renderer/script_injection_manager.h | 10 | ||||
-rw-r--r-- | extensions/renderer/user_script_set.cc | 4 | ||||
-rw-r--r-- | extensions/renderer/user_script_set.h | 3 | ||||
-rw-r--r-- | extensions/renderer/user_script_set_manager.cc | 2 | ||||
-rw-r--r-- | extensions/renderer/user_script_set_manager.h | 3 |
7 files changed, 52 insertions, 48 deletions
diff --git a/extensions/renderer/i18n_custom_bindings.cc b/extensions/renderer/i18n_custom_bindings.cc index 6a743cc..386b22e 100644 --- a/extensions/renderer/i18n_custom_bindings.cc +++ b/extensions/renderer/i18n_custom_bindings.cc @@ -4,6 +4,8 @@ #include "extensions/renderer/i18n_custom_bindings.h" +#include <vector> + #include "base/bind.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_thread.h" @@ -55,7 +57,7 @@ struct LanguageDetectionResult { // Array of detectedLanguage of size 1-3. The null is returned if // there were no languages detected - ScopedVector<DetectedLanguage> languages; + std::vector<scoped_ptr<DetectedLanguage>> languages; private: DISALLOW_COPY_AND_ASSIGN(LanguageDetectionResult); @@ -98,9 +100,10 @@ v8::Local<v8::Value> LanguageDetectionResult::ToValue(ScriptContext* context) { return handle_scope.Escape(result); } -void InitDetectedLanguages(CLD2::Language* languages, - int* percents, - ScopedVector<DetectedLanguage>* detected_languages) { +void InitDetectedLanguages( + CLD2::Language* languages, + int* percents, + std::vector<scoped_ptr<DetectedLanguage>>* detected_languages) { for (int i = 0; i < kCldNumLangs; i++) { std::string language_code; // Convert LanguageCode 'zh' to 'zh-CN' and 'zh-Hant' to 'zh-TW' for @@ -115,7 +118,7 @@ void InitDetectedLanguages(CLD2::Language* languages, CLD2::LanguageCode(static_cast<CLD2::Language>(languages[i])); } detected_languages->push_back( - new DetectedLanguage(language_code, percents[i])); + make_scoped_ptr(new DetectedLanguage(language_code, percents[i]))); } } diff --git a/extensions/renderer/script_injection_manager.cc b/extensions/renderer/script_injection_manager.cc index 5ab712f..90622c7 100644 --- a/extensions/renderer/script_injection_manager.cc +++ b/extensions/renderer/script_injection_manager.cc @@ -4,8 +4,11 @@ #include "extensions/renderer/script_injection_manager.h" +#include <utility> + #include "base/auto_reset.h" #include "base/bind.h" +#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/values.h" #include "content/public/renderer/render_frame.h" @@ -223,15 +226,15 @@ ScriptInjectionManager::ScriptInjectionManager( } ScriptInjectionManager::~ScriptInjectionManager() { - for (ScriptInjection* injection : pending_injections_) + for (const auto& injection : pending_injections_) injection->invalidate_render_frame(); - for (ScriptInjection* injection : running_injections_) + for (const auto& injection : running_injections_) injection->invalidate_render_frame(); } void ScriptInjectionManager::OnRenderFrameCreated( content::RenderFrame* render_frame) { - rfo_helpers_.push_back(new RFOHelper(render_frame, this)); + rfo_helpers_.push_back(make_scoped_ptr(new RFOHelper(render_frame, this))); } void ScriptInjectionManager::OnExtensionUnloaded( @@ -249,10 +252,11 @@ void ScriptInjectionManager::OnExtensionUnloaded( void ScriptInjectionManager::OnInjectionFinished( ScriptInjection* injection) { - ScopedVector<ScriptInjection>::iterator iter = - std::find(running_injections_.begin(), - running_injections_.end(), - injection); + auto iter = + std::find_if(running_injections_.begin(), running_injections_.end(), + [injection](const scoped_ptr<ScriptInjection>& mode) { + return injection == mode.get(); + }); if (iter != running_injections_.end()) running_injections_.erase(iter); } @@ -260,8 +264,7 @@ void ScriptInjectionManager::OnInjectionFinished( void ScriptInjectionManager::OnUserScriptsUpdated( const std::set<HostID>& changed_hosts, const std::vector<UserScript*>& scripts) { - for (ScopedVector<ScriptInjection>::iterator iter = - pending_injections_.begin(); + for (auto iter = pending_injections_.begin(); iter != pending_injections_.end();) { if (changed_hosts.count((*iter)->host_id()) > 0) iter = pending_injections_.erase(iter); @@ -271,10 +274,8 @@ void ScriptInjectionManager::OnUserScriptsUpdated( } void ScriptInjectionManager::RemoveObserver(RFOHelper* helper) { - for (ScopedVector<RFOHelper>::iterator iter = rfo_helpers_.begin(); - iter != rfo_helpers_.end(); - ++iter) { - if (*iter == helper) { + for (auto iter = rfo_helpers_.begin(); iter != rfo_helpers_.end(); ++iter) { + if (iter->get() == helper) { rfo_helpers_.erase(iter); break; } @@ -286,8 +287,7 @@ void ScriptInjectionManager::InvalidateForFrame(content::RenderFrame* frame) { // note it. active_injection_frames_.erase(frame); - for (ScopedVector<ScriptInjection>::iterator iter = - pending_injections_.begin(); + for (auto iter = pending_injections_.begin(); iter != pending_injections_.end();) { if ((*iter)->render_frame() == frame) iter = pending_injections_.erase(iter); @@ -337,13 +337,12 @@ void ScriptInjectionManager::InjectScripts( content::RenderFrame* frame, UserScript::RunLocation run_location) { // Find any injections that want to run on the given frame. - ScopedVector<ScriptInjection> frame_injections; - for (ScopedVector<ScriptInjection>::iterator iter = - pending_injections_.begin(); + ScriptInjectionVector frame_injections; + for (auto iter = pending_injections_.begin(); iter != pending_injections_.end();) { if ((*iter)->render_frame() == frame) { - frame_injections.push_back(*iter); - iter = pending_injections_.weak_erase(iter); + frame_injections.push_back(std::move(*iter)); + iter = pending_injections_.erase(iter); } else { ++iter; } @@ -351,22 +350,21 @@ void ScriptInjectionManager::InjectScripts( // Add any injections for user scripts. int tab_id = ExtensionFrameHelper::Get(frame)->tab_id(); - user_script_set_manager_->GetAllInjections( - &frame_injections, frame, tab_id, run_location); + user_script_set_manager_->GetAllInjections(&frame_injections, frame, tab_id, + run_location); // Note that we are running in |frame|. active_injection_frames_.insert(frame); ScriptsRunInfo scripts_run_info(frame, run_location); - for (ScopedVector<ScriptInjection>::iterator iter = frame_injections.begin(); - iter != frame_injections.end();) { + for (auto iter = frame_injections.begin(); iter != frame_injections.end();) { // It's possible for the frame to be invalidated in the course of injection // (if a script removes its own frame, for example). If this happens, abort. if (!active_injection_frames_.count(frame)) break; - scoped_ptr<ScriptInjection> injection(*iter); - iter = frame_injections.weak_erase(iter); - TryToInject(injection.Pass(), run_location, &scripts_run_info); + scoped_ptr<ScriptInjection> injection(std::move(*iter)); + iter = frame_injections.erase(iter); + TryToInject(std::move(injection), run_location, &scripts_run_info); } // We are done running in the frame. @@ -390,10 +388,10 @@ void ScriptInjectionManager::TryToInject( base::Bind(&ScriptInjectionManager::OnInjectionFinished, base::Unretained(this)))) { case ScriptInjection::INJECTION_WAITING: - pending_injections_.push_back(injection.Pass()); + pending_injections_.push_back(std::move(injection)); break; case ScriptInjection::INJECTION_BLOCKED: - running_injections_.push_back(injection.Pass()); + running_injections_.push_back(std::move(injection)); break; case ScriptInjection::INJECTION_FINISHED: break; @@ -453,8 +451,7 @@ void ScriptInjectionManager::HandleExecuteDeclarativeScript( } void ScriptInjectionManager::HandlePermitScriptInjection(int64 request_id) { - ScopedVector<ScriptInjection>::iterator iter = - pending_injections_.begin(); + auto iter = pending_injections_.begin(); for (; iter != pending_injections_.end(); ++iter) { if ((*iter)->request_id() == request_id) { DCHECK((*iter)->host_id().type() == HostID::EXTENSIONS); @@ -469,15 +466,15 @@ void ScriptInjectionManager::HandlePermitScriptInjection(int64 request_id) { // RFOHelper's DidStartProvisionalLoad callback would have caused it to be // cleared out). - scoped_ptr<ScriptInjection> injection(*iter); - pending_injections_.weak_erase(iter); + scoped_ptr<ScriptInjection> injection(std::move(*iter)); + pending_injections_.erase(iter); ScriptsRunInfo scripts_run_info(injection->render_frame(), UserScript::RUN_DEFERRED); ScriptInjection::InjectionResult res = injection->OnPermissionGranted( &scripts_run_info); if (res == ScriptInjection::INJECTION_BLOCKED) - running_injections_.push_back(injection.Pass()); + running_injections_.push_back(std::move(injection)); scripts_run_info.LogRun(); } diff --git a/extensions/renderer/script_injection_manager.h b/extensions/renderer/script_injection_manager.h index 7d79f1c..c85b4fe 100644 --- a/extensions/renderer/script_injection_manager.h +++ b/extensions/renderer/script_injection_manager.h @@ -8,9 +8,9 @@ #include <map> #include <set> #include <string> +#include <vector> #include "base/callback.h" -#include "base/memory/scoped_vector.h" #include "base/scoped_observer.h" #include "extensions/common/user_script.h" #include "extensions/renderer/script_injection.h" @@ -50,6 +50,8 @@ class ScriptInjectionManager : public UserScriptSetManager::Observer { using FrameStatusMap = std::map<content::RenderFrame*, UserScript::RunLocation>; + using ScriptInjectionVector = std::vector<scoped_ptr<ScriptInjection>>; + // Notifies that an injection has been finished. void OnInjectionFinished(ScriptInjection* injection); @@ -98,17 +100,17 @@ class ScriptInjectionManager : public UserScriptSetManager::Observer { std::set<content::RenderFrame*> active_injection_frames_; // The collection of RFOHelpers. - ScopedVector<RFOHelper> rfo_helpers_; + std::vector<scoped_ptr<RFOHelper>> rfo_helpers_; // The set of UserScripts associated with extensions. Owned by the Dispatcher. UserScriptSetManager* user_script_set_manager_; // Pending injections which are waiting for either the proper run location or // user consent. - ScopedVector<ScriptInjection> pending_injections_; + ScriptInjectionVector pending_injections_; // Running injections which are waiting for async callbacks from blink. - ScopedVector<ScriptInjection> running_injections_; + ScriptInjectionVector running_injections_; ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> user_script_set_manager_observer_; diff --git a/extensions/renderer/user_script_set.cc b/extensions/renderer/user_script_set.cc index 23cb833..5667f2d 100644 --- a/extensions/renderer/user_script_set.cc +++ b/extensions/renderer/user_script_set.cc @@ -63,7 +63,7 @@ void UserScriptSet::GetActiveExtensionIds( } void UserScriptSet::GetInjections( - ScopedVector<ScriptInjection>* injections, + std::vector<scoped_ptr<ScriptInjection>>* injections, content::RenderFrame* render_frame, int tab_id, UserScript::RunLocation run_location) { @@ -77,7 +77,7 @@ void UserScriptSet::GetInjections( document_url, false /* is_declarative */); if (injection.get()) - injections->push_back(injection.Pass()); + injections->push_back(std::move(injection)); } } diff --git a/extensions/renderer/user_script_set.h b/extensions/renderer/user_script_set.h index 231722e..42d3190 100644 --- a/extensions/renderer/user_script_set.h +++ b/extensions/renderer/user_script_set.h @@ -7,6 +7,7 @@ #include <set> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/macros.h" @@ -52,7 +53,7 @@ class UserScriptSet { // |tab_id|, at the given |run_location|, to |injections|. // |extensions| is passed in to verify the corresponding extension is still // valid. - void GetInjections(ScopedVector<ScriptInjection>* injections, + void GetInjections(std::vector<scoped_ptr<ScriptInjection>>* injections, content::RenderFrame* render_frame, int tab_id, UserScript::RunLocation run_location); diff --git a/extensions/renderer/user_script_set_manager.cc b/extensions/renderer/user_script_set_manager.cc index c131577..0404e05 100644 --- a/extensions/renderer/user_script_set_manager.cc +++ b/extensions/renderer/user_script_set_manager.cc @@ -61,7 +61,7 @@ bool UserScriptSetManager::OnControlMessageReceived( } void UserScriptSetManager::GetAllInjections( - ScopedVector<ScriptInjection>* injections, + std::vector<scoped_ptr<ScriptInjection>>* injections, content::RenderFrame* render_frame, int tab_id, UserScript::RunLocation run_location) { diff --git a/extensions/renderer/user_script_set_manager.h b/extensions/renderer/user_script_set_manager.h index 3be8fff..bf878fe 100644 --- a/extensions/renderer/user_script_set_manager.h +++ b/extensions/renderer/user_script_set_manager.h @@ -8,6 +8,7 @@ #include <map> #include <set> #include <string> +#include <vector> #include "base/memory/linked_ptr.h" #include "base/memory/shared_memory.h" @@ -67,7 +68,7 @@ class UserScriptSetManager : public content::RenderProcessObserver { // Append all injections from |static_scripts| and each of // |programmatic_scripts_| to |injections|. - void GetAllInjections(ScopedVector<ScriptInjection>* injections, + void GetAllInjections(std::vector<scoped_ptr<ScriptInjection>>* injections, content::RenderFrame* render_frame, int tab_id, UserScript::RunLocation run_location); |