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

Side by Side Diff: content/browser/devtools/devtools_session.h

Issue 2863623003: [DevTools] Support multiple sessions in content/ domain handlers (Closed)
Patch Set: addressed review comments Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
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_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
7
8 #include "base/containers/flat_map.h"
5 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
6 #include "base/values.h" 10 #include "base/values.h"
11 #include "content/browser/devtools/devtools_agent_host_impl.h"
7 #include "content/browser/devtools/protocol/devtools_domain_handler.h" 12 #include "content/browser/devtools/protocol/devtools_domain_handler.h"
8 #include "content/browser/devtools/protocol/protocol.h" 13 #include "content/browser/devtools/protocol/protocol.h"
9 14
10 namespace content { 15 namespace content {
11 16
12 class DevToolsAgentHostImpl;
13 class DevToolsAgentHostClient; 17 class DevToolsAgentHostClient;
14 class RenderFrameHostImpl; 18 class RenderFrameHostImpl;
15 19
16 class DevToolsSession : public protocol::FrontendChannel { 20 class DevToolsSession : public protocol::FrontendChannel {
17 public: 21 public:
18 DevToolsSession(DevToolsAgentHostImpl* agent_host, 22 DevToolsSession(DevToolsAgentHostImpl* agent_host,
19 DevToolsAgentHostClient* client, 23 DevToolsAgentHostClient* client,
20 int session_id); 24 int session_id);
21 ~DevToolsSession() override; 25 ~DevToolsSession() override;
22 26
23 int session_id() const { return session_id_; } 27 int session_id() const { return session_id_; }
24 void AddHandler(std::unique_ptr<protocol::DevToolsDomainHandler> handler); 28 void AddHandler(std::unique_ptr<protocol::DevToolsDomainHandler> handler);
25 void SetRenderFrameHost(RenderFrameHostImpl* host); 29 void SetRenderFrameHost(RenderFrameHostImpl* host);
26 void SetFallThroughForNotFound(bool value); 30 void SetFallThroughForNotFound(bool value);
27 protocol::DevToolsDomainHandler* GetHandlerByName(const std::string& name);
28 31
29 protocol::Response::Status Dispatch( 32 protocol::Response::Status Dispatch(
30 const std::string& message, 33 const std::string& message,
31 int* call_id, 34 int* call_id,
32 std::string* method); 35 std::string* method);
33 36
34 // Only used by DevToolsAgentHostImpl. 37 // Only used by DevToolsAgentHostImpl.
35 DevToolsAgentHostClient* client() const { return client_; } 38 DevToolsAgentHostClient* client() const { return client_; }
36 39
40 template <typename Handler>
41 static std::vector<Handler*> HandlersForAgentHost(
42 DevToolsAgentHostImpl* agent_host,
43 const std::string& name) {
44 std::vector<Handler*> result;
45 if (agent_host->sessions_.empty())
46 return result;
47 for (const auto& session : agent_host->sessions_) {
48 auto it = session->handlers_.find(name);
49 if (it != session->handlers_.end())
50 result.push_back(static_cast<Handler*>(it->second.get()));
51 }
52 return result;
53 }
54
37 private: 55 private:
38 void sendResponse(std::unique_ptr<base::DictionaryValue> response); 56 void sendResponse(std::unique_ptr<base::DictionaryValue> response);
39 // protocol::FrontendChannel implementation. 57 // protocol::FrontendChannel implementation.
40 void sendProtocolResponse( 58 void sendProtocolResponse(
41 int call_id, 59 int call_id,
42 std::unique_ptr<protocol::Serializable> message) override; 60 std::unique_ptr<protocol::Serializable> message) override;
43 void sendProtocolNotification( 61 void sendProtocolNotification(
44 std::unique_ptr<protocol::Serializable> message) override; 62 std::unique_ptr<protocol::Serializable> message) override;
45 void flushProtocolNotifications() override; 63 void flushProtocolNotifications() override;
46 64
47 DevToolsAgentHostImpl* agent_host_; 65 DevToolsAgentHostImpl* agent_host_;
48 DevToolsAgentHostClient* client_; 66 DevToolsAgentHostClient* client_;
49 int session_id_; 67 int session_id_;
50 std::unordered_map<std::string, 68 base::flat_map<std::string, std::unique_ptr<protocol::DevToolsDomainHandler>>
51 std::unique_ptr<protocol::DevToolsDomainHandler>> handlers_; 69 handlers_;
52 RenderFrameHostImpl* host_; 70 RenderFrameHostImpl* host_;
53 std::unique_ptr<protocol::UberDispatcher> dispatcher_; 71 std::unique_ptr<protocol::UberDispatcher> dispatcher_;
54 72
55 base::WeakPtrFactory<DevToolsSession> weak_factory_; 73 base::WeakPtrFactory<DevToolsSession> weak_factory_;
56 }; 74 };
57 75
58 } // namespace content 76 } // namespace content
77
78 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_io_context.h ('k') | content/browser/devtools/devtools_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698