Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / content / browser / devtools / protocol / devtools_protocol_client.h
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.
4
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
7
8 #include "content/browser/devtools/devtools_protocol.h"
9
10 namespace content {
11
12 class DevToolsProtocolClient {
13  public:
14   typedef base::Callback<void(const std::string& message)>
15       RawMessageCallback;
16
17   enum ResponseStatus {
18     RESPONSE_STATUS_FALLTHROUGH,
19     RESPONSE_STATUS_OK,
20     RESPONSE_STATUS_INVALID_PARAMS,
21     RESPONSE_STATUS_INTERNAL_ERROR,
22     RESPONSE_STATUS_SERVER_ERROR,
23   };
24
25   struct Response {
26    public:
27     static Response FallThrough();
28     static Response OK();
29     static Response InvalidParams(const std::string& message);
30     static Response InternalError(const std::string& message);
31     static Response ServerError(const std::string& message);
32
33     ResponseStatus status() const;
34     const std::string& message() const;
35
36    private:
37     Response();
38
39     ResponseStatus status_;
40     std::string message_;
41   };
42
43   void SendInvalidParamsResponse(
44       scoped_refptr<DevToolsProtocol::Command> command,
45       const std::string& message);
46   void SendInternalErrorResponse(
47       scoped_refptr<DevToolsProtocol::Command> command,
48       const std::string& message);
49   void SendServerErrorResponse(
50       scoped_refptr<DevToolsProtocol::Command> command,
51       const std::string& message);
52
53   // Sends message to client, the caller is presumed to properly
54   // format the message. Do not use unless you must.
55   void SendRawMessage(const std::string& message);
56
57  protected:
58   DevToolsProtocolClient(const RawMessageCallback& raw_message_callback);
59
60   virtual ~DevToolsProtocolClient();
61
62   void SendNotification(const std::string& method,
63                         base::DictionaryValue* params);
64
65   void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response);
66
67  private:
68   RawMessageCallback raw_message_callback_;
69
70   DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient);
71 };
72
73 }  // namespace content
74
75 #endif  // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_