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

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

Issue 10754004: Remove the refcount from ScriptBadgeController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert 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.h
diff --git a/chrome/browser/extensions/script_executor.h b/chrome/browser/extensions/script_executor.h
index 2119cc63ce82f4ddc9287e757dddf1287f6440ea..d81fa14805d201dbec339b3d0bf96f4d9bc1b043 100644
--- a/chrome/browser/extensions/script_executor.h
+++ b/chrome/browser/extensions/script_executor.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/callback_forward.h"
+#include "base/observer_list.h"
#include "chrome/common/extensions/user_script.h"
namespace content {
@@ -22,7 +23,9 @@ namespace extensions {
// caller when responded with ExtensionHostMsg_ExecuteCodeFinished.
class ScriptExecutor {
public:
- virtual ~ScriptExecutor() {}
+ explicit ScriptExecutor(content::WebContents* web_contents);
+
+ ~ScriptExecutor();
// The type of script being injected.
enum ScriptType {
@@ -47,19 +50,51 @@ class ScriptExecutor {
typedef base::Callback<void(bool, int32, const std::string&)>
ExecuteScriptCallback;
+ class Observer {
+ public:
+ // Automatically observes and unobserves *script_executor on construction
+ // and destruction. *script_executor must outlive *this.
+ explicit Observer(ScriptExecutor* script_executor);
+ virtual ~Observer();
+
+ virtual void OnExecuteScriptFinished(const std::string& extension_id,
+ bool success,
+ int32 page_id,
+ const std::string& error) = 0;
+ private:
+ ScriptExecutor& script_executor_;
+ };
+
// Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in
// extension_messages.h (request_id is populated automatically).
//
// |callback| will always be called even if the IPC'd renderer is destroyed
// before a response is received (in this case the callback will be with a
// failure and appropriate error message).
- virtual void ExecuteScript(const std::string& extension_id,
- ScriptType script_type,
- const std::string& code,
- FrameScope frame_scope,
- UserScript::RunLocation run_at,
- WorldType world_type,
- const ExecuteScriptCallback& callback) = 0;
+ void ExecuteScript(const std::string& extension_id,
+ ScriptType script_type,
+ const std::string& code,
+ FrameScope frame_scope,
+ UserScript::RunLocation run_at,
+ WorldType world_type,
+ const ExecuteScriptCallback& callback);
+
+ void AddObserver(Observer* obs) {
+ observer_list_.AddObserver(obs);
+ }
+
+ void RemoveObserver(Observer* obs) {
+ observer_list_.RemoveObserver(obs);
+ }
+
+ private:
+ // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params.
+ int next_request_id_;
+
+ // The WebContents this is bound to.
+ content::WebContents* web_contents_;
+
+ ObserverList<Observer> observer_list_;
};
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/script_badge_controller_unittest.cc ('k') | chrome/browser/extensions/script_executor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698