[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / devtools / protocol / devtools_protocol_client.h
blob9297187f21c1778752372a2881912ab4c1bbe380
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
8 #include "base/callback.h"
9 #include "base/values.h"
11 namespace content {
13 using DevToolsCommandId = int;
14 class DevToolsProtocolHandler;
15 class DevToolsProtocolDispatcher;
17 class DevToolsProtocolClient {
18 public:
19 typedef base::Callback<void(const std::string& message)>
20 RawMessageCallback;
21 static const DevToolsCommandId kNoId;
23 struct Response {
24 public:
25 static Response FallThrough();
26 static Response OK();
27 static Response InvalidParams(const std::string& param);
28 static Response InternalError(const std::string& message);
29 static Response ServerError(const std::string& message);
31 int status() const;
32 const std::string& message() const;
34 bool IsFallThrough() const;
36 private:
37 friend class DevToolsProtocolHandler;
39 explicit Response(int status);
40 Response(int status, const std::string& message);
42 int status_;
43 std::string message_;
46 bool SendError(DevToolsCommandId command_id,
47 const Response& response);
49 // Sends message to client, the caller is presumed to properly
50 // format the message. Do not use unless you must.
51 void SendRawMessage(const std::string& message);
53 explicit DevToolsProtocolClient(
54 const RawMessageCallback& raw_message_callback);
55 virtual ~DevToolsProtocolClient();
57 protected:
58 void SendSuccess(DevToolsCommandId command_id,
59 scoped_ptr<base::DictionaryValue> params);
60 void SendNotification(const std::string& method,
61 scoped_ptr<base::DictionaryValue> params);
63 private:
64 friend class DevToolsProtocolDispatcher;
66 void SendMessage(const base::DictionaryValue& message);
68 RawMessageCallback raw_message_callback_;
69 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient);
72 } // namespace content
74 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_