OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
yurys
2014/04/01 09:01:45
2014
horo
2014/04/02 04:31:57
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/containers/scoped_ptr_hash_map.h" | |
9 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/scoped_vector.h" | |
12 #include "base/memory/singleton.h" | |
10 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "content/browser/shared_worker/shared_worker_instance.h" | |
11 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
12 | 16 |
13 class GURL; | 17 class GURL; |
14 class WebUIBrowserTest; | |
15 | |
16 namespace base { | |
17 class DictionaryValue; | |
18 class ListValue; | |
19 } | |
20 | 18 |
21 namespace content { | 19 namespace content { |
20 class DevToolsAgentHost; | |
22 | 21 |
23 class WebUI; | 22 // SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
24 class WebUIImpl; | 23 // "enable-embedded-shared-worker" flag is set. |
24 // This class lives on UI thread. | |
25 class CONTENT_EXPORT SharedWorkerDevToolsManager { | |
26 public: | |
27 typedef std::pair<int, int> WorkerId; | |
28 class SharedWorkerDevToolsAgentHost; | |
25 | 29 |
26 // Messages sent from the DOM are forwarded via the WebUI to handler | 30 // Returns the SharedWorkerDevToolsManager singleton. |
27 // classes. These objects are owned by WebUI and destroyed when the | 31 static SharedWorkerDevToolsManager* GetInstance(); |
28 // host is destroyed. | |
29 class CONTENT_EXPORT WebUIMessageHandler { | |
30 public: | |
31 WebUIMessageHandler() : web_ui_(NULL) {} | |
32 virtual ~WebUIMessageHandler() {} | |
33 | 32 |
34 protected: | 33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
35 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractIntegerValue); | 34 int worker_route_id); |
36 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractDoubleValue); | |
37 FRIEND_TEST_ALL_PREFIXES(WebUIMessageHandlerTest, ExtractStringValue); | |
38 | 35 |
39 // Helper methods: | 36 // Returns true when the worker must be paused on start. |
40 | 37 bool WorkerCreated(int worker_process_id, |
41 // Extract an integer value from a list Value. | 38 int worker_route_id, |
42 static bool ExtractIntegerValue(const base::ListValue* value, int* out_int); | 39 const SharedWorkerInstance& instance); |
43 | 40 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
44 // Extract a floating point (double) value from a list Value. | 41 void WorkerContextStarted(int worker_process_id, int worker_route_id); |
45 static bool ExtractDoubleValue(const base::ListValue* value, | |
46 double* out_value); | |
47 | |
48 // Extract a string value from a list Value. | |
49 static base::string16 ExtractStringValue(const base::ListValue* value); | |
50 | |
51 // This is where subclasses specify which messages they'd like to handle and | |
52 // perform any additional initialization.. At this point web_ui() will return | |
53 // the associated WebUI object. | |
54 virtual void RegisterMessages() = 0; | |
55 | |
56 // Returns the attached WebUI for this handler. | |
57 WebUI* web_ui() const { return web_ui_; } | |
58 | |
59 // Sets the attached WebUI - exposed to subclasses for testing purposes. | |
60 void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; } | |
61 | 42 |
62 private: | 43 private: |
63 // Provide external classes access to web_ui() and set_web_ui(). | 44 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>; |
64 friend class WebUIImpl; | 45 friend class SharedWorkerDevToolsManagerTest; |
65 friend class ::WebUIBrowserTest; | 46 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest); |
47 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest); | |
66 | 48 |
67 WebUI* web_ui_; | 49 enum WorkerState { |
50 WORKER_UNINSPECTED, | |
51 WORKER_INSPECTED, | |
52 WORKER_TERMINATED, | |
53 WORKER_PAUSED, | |
54 }; | |
kinuko
2014/04/01 16:01:05
Ah, this is neat
| |
55 | |
56 class WorkerInfo { | |
57 public: | |
58 WorkerInfo(const SharedWorkerInstance& instance) | |
kinuko
2014/04/01 16:01:05
nit: explicit
horo
2014/04/02 04:31:57
Done.
| |
59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {} | |
60 | |
61 const SharedWorkerInstance& instance() const { return instance_; } | |
62 WorkerState state() { return state_; } | |
63 void set_state(WorkerState new_state) { state_ = new_state; } | |
64 SharedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | |
65 void set_agent_host(SharedWorkerDevToolsAgentHost* agent_host) { | |
66 agent_host_ = agent_host; | |
67 } | |
68 | |
69 private: | |
70 const SharedWorkerInstance instance_; | |
71 WorkerState state_; | |
72 SharedWorkerDevToolsAgentHost* agent_host_; | |
73 }; | |
74 | |
75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | |
76 | |
77 SharedWorkerDevToolsManager(); | |
78 virtual ~SharedWorkerDevToolsManager(); | |
79 | |
80 void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host); | |
81 | |
82 WorkerInfoMap::iterator FindExistingWorkerInfo( | |
83 const SharedWorkerInstance& instance); | |
84 | |
85 // Resets to its initial state as if newly created. | |
86 void ResetForTesting(); | |
87 | |
88 WorkerInfoMap workers_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager); | |
68 }; | 91 }; |
69 | 92 |
70 } // namespace content | 93 } // namespace content |
71 | 94 |
72 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_MESSAGE_HANDLER_H_ | 95 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |