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

Unified Diff: content/browser/devtools/shared_worker_devtools_manager.h

Issue 196503005: Make DevTools support for the embedded SharedWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: introduce WorkerState enum and add test Created 6 years, 9 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: content/browser/devtools/shared_worker_devtools_manager.h
diff --git a/content/public/browser/web_ui_message_handler.h b/content/browser/devtools/shared_worker_devtools_manager.h
similarity index 12%
copy from content/public/browser/web_ui_message_handler.h
copy to content/browser/devtools/shared_worker_devtools_manager.h
index 20a6072603317c1c71f5c5d6bb53d9c2d7e899d2..c63e8b767ee724c00c4fa95b7d4190a0d19874a1 100644
--- a/content/public/browser/web_ui_message_handler.h
+++ b/content/browser/devtools/shared_worker_devtools_manager.h
@@ -2,71 +2,94 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
-#define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
+#ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
+#define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
#include "base/basictypes.h"
+#include "base/containers/scoped_ptr_hash_map.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/singleton.h"
#include "base/strings/string16.h"
+#include "content/browser/shared_worker/shared_worker_instance.h"
#include "content/common/content_export.h"
class GURL;
-class WebUIBrowserTest;
-
-namespace base {
-class DictionaryValue;
-class ListValue;
-}
namespace content {
+class DevToolsAgentHost;
-class WebUI;
-class WebUIImpl;
-
-// Messages sent from the DOM are forwarded via the WebUI to handler
-// classes. These objects are owned by WebUI and destroyed when the
-// host is destroyed.
-class CONTENT_EXPORT WebUIMessageHandler {
+// SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
+// "enable-embedded-shared-worker" flag is set.
+// This class lives on UI thread.
+class CONTENT_EXPORT SharedWorkerDevToolsManager {
public:
- WebUIMessageHandler() : web_ui_(NULL) {}
- virtual ~WebUIMessageHandler() {}
+ typedef std::pair<int, int> WorkerId;
+ class SharedWorkerDevToolsAgentHost;
- protected:
- FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractIntegerValue);
- FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractDoubleValue);
- FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractStringValue);
+ // Returns the SharedWorkerDevToolsManager singleton.
+ static SharedWorkerDevToolsManager* GetInstance();
- // Helper methods:
+ DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id,
+ int worker_route_id);
- // Extract an integer value from a list Value.
- static bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
+ // Returns true when the worker must be paused on start.
+ bool WorkerCreated(int worker_process_id,
+ int worker_route_id,
+ const SharedWorkerInstance& instance);
+ void WorkerDestroyed(int worker_process_id, int worker_route_id);
+ void WorkerContextStarted(int worker_process_id, int worker_route_id);
- // Extract a floating point (double) value from a list Value.
- static bool ExtractDoubleValue(const base::ListValue* value,
- double* out_value);
+ private:
+ friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>;
+ friend class SharedWorkerDevToolsManagerTest;
+ FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest);
+ FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest);
- // Extract a string value from a list Value.
- static base::string16 ExtractStringValue(const base::ListValue* value);
+ enum WorkerState {
+ WORKER_UNINSPECTED,
+ WORKER_INSPECTED,
+ WORKER_TERMINATED,
+ WORKER_PAUSED,
+ };
kinuko 2014/04/01 16:01:05 Ah, this is neat
- // This is where subclasses specify which messages they'd like to handle and
- // perform any additional initialization.. At this point web_ui() will return
- // the associated WebUI object.
- virtual void RegisterMessages() = 0;
+ class WorkerInfo {
+ public:
+ WorkerInfo(const SharedWorkerInstance& instance)
kinuko 2014/04/01 16:01:05 nit: explicit
horo 2014/04/02 04:31:57 Done.
+ : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {}
- // Returns the attached WebUI for this handler.
- WebUI* web_ui() const { return web_ui_; }
+ const SharedWorkerInstance& instance() const { return instance_; }
+ WorkerState state() { return state_; }
+ void set_state(WorkerState new_state) { state_ = new_state; }
+ SharedWorkerDevToolsAgentHost* agent_host() { return agent_host_; }
+ void set_agent_host(SharedWorkerDevToolsAgentHost* agent_host) {
+ agent_host_ = agent_host;
+ }
- // Sets the attached WebUI - exposed to subclasses for testing purposes.
- void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; }
+ private:
+ const SharedWorkerInstance instance_;
+ WorkerState state_;
+ SharedWorkerDevToolsAgentHost* agent_host_;
+ };
- private:
- // Provide external classes access to web_ui() and set_web_ui().
- friend class WebUIImpl;
- friend class ::WebUIBrowserTest;
+ typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap;
+
+ SharedWorkerDevToolsManager();
+ virtual ~SharedWorkerDevToolsManager();
+
+ void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host);
+
+ WorkerInfoMap::iterator FindExistingWorkerInfo(
+ const SharedWorkerInstance& instance);
+
+ // Resets to its initial state as if newly created.
+ void ResetForTesting();
+
+ WorkerInfoMap workers_;
- WebUI* web_ui_;
+ DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager);
};
} // namespace content
-#endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_
+#endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698