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

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

Issue 2933243002: [DevTools] Make DevToolsSession own it's DevToolsMessageChunkProcessor (Closed)
Patch Set: more concise Created 3 years, 6 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_ 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_ 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
7 7
8 #include <unordered_map>
caseq 2017/06/13 19:52:26 consider using regular maps? see https://groups.go
dgozman 2017/06/16 17:58:46 Done.
9
8 #include "base/containers/flat_map.h" 10 #include "base/containers/flat_map.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "content/browser/devtools/devtools_agent_host_impl.h" 13 #include "content/browser/devtools/devtools_agent_host_impl.h"
12 #include "content/browser/devtools/protocol/devtools_domain_handler.h" 14 #include "content/browser/devtools/protocol/devtools_domain_handler.h"
13 #include "content/browser/devtools/protocol/protocol.h" 15 #include "content/browser/devtools/protocol/protocol.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 class DevToolsAgentHostClient; 19 class DevToolsAgentHostClient;
18 class RenderFrameHostImpl; 20 class RenderFrameHostImpl;
19 21
20 class DevToolsSession : public protocol::FrontendChannel { 22 class DevToolsSession : public protocol::FrontendChannel {
21 public: 23 public:
22 DevToolsSession(DevToolsAgentHostImpl* agent_host, 24 DevToolsSession(DevToolsAgentHostImpl* agent_host,
23 DevToolsAgentHostClient* client, 25 DevToolsAgentHostClient* client,
24 int session_id); 26 int session_id);
25 ~DevToolsSession() override; 27 ~DevToolsSession() override;
26 28
27 int session_id() const { return session_id_; } 29 int session_id() const { return session_id_; }
28 void AddHandler(std::unique_ptr<protocol::DevToolsDomainHandler> handler); 30 void AddHandler(std::unique_ptr<protocol::DevToolsDomainHandler> handler);
29 void SetRenderFrameHost(RenderFrameHostImpl* host); 31 void SetRenderFrameHost(RenderFrameHostImpl* host);
30 void SetFallThroughForNotFound(bool value); 32 void SetFallThroughForNotFound(bool value);
31 33
34 struct Message {
35 std::string method;
36 std::string message;
37 };
38 using MessageByCallId = std::unordered_map<int, Message>;
39 MessageByCallId& waiting_messages() { return waiting_for_response_messages_; }
40 const std::string& state_cookie() { return chunk_processor_.state_cookie(); }
41
32 protocol::Response::Status Dispatch( 42 protocol::Response::Status Dispatch(
33 const std::string& message, 43 const std::string& message,
34 int* call_id, 44 int* call_id,
35 std::string* method); 45 std::string* method);
46 bool ReceiveMessageChunk(const DevToolsMessageChunk& chunk);
36 47
37 // Only used by DevToolsAgentHostImpl. 48 // Only used by DevToolsAgentHostImpl.
38 DevToolsAgentHostClient* client() const { return client_; } 49 DevToolsAgentHostClient* client() const { return client_; }
39 50
40 template <typename Handler> 51 template <typename Handler>
41 static std::vector<Handler*> HandlersForAgentHost( 52 static std::vector<Handler*> HandlersForAgentHost(
42 DevToolsAgentHostImpl* agent_host, 53 DevToolsAgentHostImpl* agent_host,
43 const std::string& name) { 54 const std::string& name) {
44 std::vector<Handler*> result; 55 std::vector<Handler*> result;
45 if (agent_host->sessions_.empty()) 56 if (agent_host->sessions_.empty())
46 return result; 57 return result;
47 for (const auto& session : agent_host->sessions_) { 58 for (const auto& session : agent_host->sessions_) {
48 auto it = session->handlers_.find(name); 59 auto it = session->handlers_.find(name);
49 if (it != session->handlers_.end()) 60 if (it != session->handlers_.end())
50 result.push_back(static_cast<Handler*>(it->second.get())); 61 result.push_back(static_cast<Handler*>(it->second.get()));
51 } 62 }
52 return result; 63 return result;
53 } 64 }
54 65
55 private: 66 private:
56 void sendResponse(std::unique_ptr<base::DictionaryValue> response); 67 void SendMessageToClient(int session_id, const std::string& message);
68 void SendResponse(std::unique_ptr<base::DictionaryValue> response);
69
57 // protocol::FrontendChannel implementation. 70 // protocol::FrontendChannel implementation.
58 void sendProtocolResponse( 71 void sendProtocolResponse(
59 int call_id, 72 int call_id,
60 std::unique_ptr<protocol::Serializable> message) override; 73 std::unique_ptr<protocol::Serializable> message) override;
61 void sendProtocolNotification( 74 void sendProtocolNotification(
62 std::unique_ptr<protocol::Serializable> message) override; 75 std::unique_ptr<protocol::Serializable> message) override;
63 void flushProtocolNotifications() override; 76 void flushProtocolNotifications() override;
64 77
65 DevToolsAgentHostImpl* agent_host_; 78 DevToolsAgentHostImpl* agent_host_;
66 DevToolsAgentHostClient* client_; 79 DevToolsAgentHostClient* client_;
67 int session_id_; 80 int session_id_;
68 base::flat_map<std::string, std::unique_ptr<protocol::DevToolsDomainHandler>> 81 base::flat_map<std::string, std::unique_ptr<protocol::DevToolsDomainHandler>>
69 handlers_; 82 handlers_;
70 RenderFrameHostImpl* host_; 83 RenderFrameHostImpl* host_;
71 std::unique_ptr<protocol::UberDispatcher> dispatcher_; 84 std::unique_ptr<protocol::UberDispatcher> dispatcher_;
85 // Chunk processor's state cookie always corresponds to a state before
86 // any of the waiting for response messages have been handled.
87 DevToolsMessageChunkProcessor chunk_processor_;
88 MessageByCallId waiting_for_response_messages_;
caseq 2017/06/13 19:52:26 nit: messages_waiting_for_response_?
dgozman 2017/06/16 17:58:46 Acknowledged.
72 89
73 base::WeakPtrFactory<DevToolsSession> weak_factory_; 90 base::WeakPtrFactory<DevToolsSession> weak_factory_;
74 }; 91 };
75 92
76 } // namespace content 93 } // namespace content
77 94
78 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_ 95 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698