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

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

Issue 10754004: Remove the refcount from ScriptBadgeController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With ScopedObserver Created 8 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/script_executor.cc
diff --git a/chrome/browser/extensions/script_executor_impl.cc b/chrome/browser/extensions/script_executor.cc
similarity index 77%
rename from chrome/browser/extensions/script_executor_impl.cc
rename to chrome/browser/extensions/script_executor.cc
index e8f6199c15198e03749100b48e5886a12c22f009..2e818ca6a6a71b8c60c92a7a6e7b78d657d0a4ee 100644
--- a/chrome/browser/extensions/script_executor_impl.cc
+++ b/chrome/browser/extensions/script_executor.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/script_executor_impl.h"
+#include "chrome/browser/extensions/script_executor.h"
#include "base/callback.h"
#include "base/logging.h"
@@ -25,10 +25,13 @@ const char* kRendererDestroyed = "The tab was closed.";
// corresponding response comes from the renderer, or the renderer is destroyed.
class Handler : public content::WebContentsObserver {
public:
- Handler(content::WebContents* web_contents,
+ Handler(ObserverList<ScriptExecutor::Observer>* observer_list,
+ content::WebContents* web_contents,
const ExtensionMsg_ExecuteCode_Params& params,
const ScriptExecutor::ExecuteScriptCallback& callback)
: content::WebContentsObserver(web_contents),
+ observer_list_(AsWeakPtr(observer_list)),
+ extension_id_(params.extension_id),
request_id_(params.request_id),
callback_(callback) {
content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
@@ -67,24 +70,36 @@ class Handler : public content::WebContentsObserver {
bool success,
int32 page_id,
const std::string& error) {
+ if (observer_list_) {
+ FOR_EACH_OBSERVER(ScriptExecutor::Observer, *observer_list_,
+ OnExecuteScriptFinished(extension_id_, success,
+ page_id, error));
+ }
+
callback_.Run(success, page_id, error);
delete this;
}
+ base::WeakPtr<ObserverList<ScriptExecutor::Observer> > observer_list_;
+ std::string extension_id_;
int request_id_;
ScriptExecutor::ExecuteScriptCallback callback_;
};
} // namespace
-ScriptExecutorImpl::ScriptExecutorImpl(
- content::WebContents* web_contents)
+ScriptExecutor::Observer::Observer(ScriptExecutor* script_executor)
+ : scoped_observer_(this) {
+ scoped_observer_.Add(script_executor);
+}
+
+ScriptExecutor::ScriptExecutor(content::WebContents* web_contents)
: next_request_id_(0),
web_contents_(web_contents) {}
-ScriptExecutorImpl::~ScriptExecutorImpl() {}
+ScriptExecutor::~ScriptExecutor() {}
-void ScriptExecutorImpl::ExecuteScript(
+void ScriptExecutor::ExecuteScript(
const std::string& extension_id,
ScriptExecutor::ScriptType script_type,
const std::string& code,
@@ -102,7 +117,7 @@ void ScriptExecutorImpl::ExecuteScript(
params.in_main_world = (world_type == MAIN_WORLD);
// Handler handles IPCs and deletes itself on completion.
- new Handler(web_contents_, params, callback);
+ new Handler(&observer_list_, web_contents_, params, callback);
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698