OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 using DevToolsCommandId = int; | 13 using DevToolsCommandId = int; |
14 class DevToolsProtocolHandler; | 14 class DevToolsProtocolHandler; |
15 class DevToolsProtocolDispatcher; | 15 class DevToolsProtocolDispatcher; |
16 | 16 |
17 class DevToolsProtocolClient { | 17 class DevToolsProtocolClient { |
18 public: | 18 public: |
19 typedef base::Callback<void(const std::string& message)> | 19 typedef base::Callback<void(int, const std::string& message)> |
20 RawMessageCallback; | 20 RawMessageCallback; |
21 static const DevToolsCommandId kNoId; | 21 static const DevToolsCommandId kNoId; |
22 | 22 |
23 struct Response { | 23 struct Response { |
24 public: | 24 public: |
25 static Response FallThrough(); | 25 static Response FallThrough(); |
26 static Response OK(); | 26 static Response OK(); |
27 static Response InvalidParams(const std::string& param); | 27 static Response InvalidParams(const std::string& param); |
28 static Response InternalError(const std::string& message); | 28 static Response InternalError(const std::string& message); |
29 static Response ServerError(const std::string& message); | 29 static Response ServerError(const std::string& message); |
30 | 30 |
31 int status() const; | 31 int status() const; |
32 const std::string& message() const; | 32 const std::string& message() const; |
33 | 33 |
34 bool IsFallThrough() const; | 34 bool IsFallThrough() const; |
35 | 35 |
36 private: | 36 private: |
37 friend class DevToolsProtocolHandler; | 37 friend class DevToolsProtocolHandler; |
38 | 38 |
39 explicit Response(int status); | 39 explicit Response(int status); |
40 Response(int status, const std::string& message); | 40 Response(int status, const std::string& message); |
41 | 41 |
42 int status_; | 42 int status_; |
43 std::string message_; | 43 std::string message_; |
44 }; | 44 }; |
45 | 45 |
46 bool SendError(DevToolsCommandId command_id, | 46 bool SendError(int session_id, |
| 47 DevToolsCommandId command_id, |
47 const Response& response); | 48 const Response& response); |
48 | 49 |
49 // Sends message to client, the caller is presumed to properly | 50 // Sends message to client, the caller is presumed to properly |
50 // format the message. Do not use unless you must. | 51 // format the message. Do not use unless you must. |
51 void SendRawMessage(const std::string& message); | 52 void SendRawMessage(int session_id, const std::string& message); |
52 | 53 |
53 explicit DevToolsProtocolClient( | 54 explicit DevToolsProtocolClient( |
54 const RawMessageCallback& raw_message_callback); | 55 const RawMessageCallback& raw_message_callback); |
55 virtual ~DevToolsProtocolClient(); | 56 virtual ~DevToolsProtocolClient(); |
56 | 57 |
57 protected: | 58 protected: |
58 void SendSuccess(DevToolsCommandId command_id, | 59 void SendSuccess(int session_id, |
| 60 DevToolsCommandId command_id, |
59 scoped_ptr<base::DictionaryValue> params); | 61 scoped_ptr<base::DictionaryValue> params); |
60 void SendNotification(const std::string& method, | 62 void SendNotification(const std::string& method, |
61 scoped_ptr<base::DictionaryValue> params); | 63 scoped_ptr<base::DictionaryValue> params); |
62 | 64 |
63 private: | 65 private: |
64 friend class DevToolsProtocolDispatcher; | 66 friend class DevToolsProtocolDispatcher; |
65 | 67 |
66 void SendMessage(const base::DictionaryValue& message); | 68 void SendMessage(int session_id, const base::DictionaryValue& message); |
67 | 69 |
68 RawMessageCallback raw_message_callback_; | 70 RawMessageCallback raw_message_callback_; |
69 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); | 71 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); |
70 }; | 72 }; |
71 | 73 |
72 } // namespace content | 74 } // namespace content |
73 | 75 |
74 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 76 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
OLD | NEW |