• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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 MOJO_PUBLIC_CPP_BINDINGS_PIPE_CONTROL_MESSAGE_HANDLER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_PIPE_CONTROL_MESSAGE_HANDLER_H_
7 
8 #include <string>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "mojo/public/cpp/bindings/bindings_export.h"
13 #include "mojo/public/cpp/bindings/message.h"
14 
15 namespace mojo {
16 
17 class PipeControlMessageHandlerDelegate;
18 
19 // Handler for messages defined in pipe_control_messages.mojom.
20 class MOJO_CPP_BINDINGS_EXPORT PipeControlMessageHandler
21     : public MessageReceiver {
22  public:
23   explicit PipeControlMessageHandler(
24       PipeControlMessageHandlerDelegate* delegate);
25   ~PipeControlMessageHandler() override;
26 
27   // Sets the description for this handler. Used only when reporting validation
28   // errors.
29   void SetDescription(const std::string& description);
30 
31   // NOTE: |message| must have passed message header validation.
32   static bool IsPipeControlMessage(const Message* message);
33 
34   // MessageReceiver implementation:
35 
36   // NOTE: |message| must:
37   //   - have passed message header validation; and
38   //   - be a pipe control message (i.e., IsPipeControlMessage() returns true).
39   // If the method returns false, the message pipe should be closed.
40   bool Accept(Message* message) override;
41 
42  private:
43   // |message| must have passed message header validation.
44   bool Validate(Message* message);
45   bool RunOrClosePipe(Message* message);
46 
47   std::string description_;
48   PipeControlMessageHandlerDelegate* const delegate_;
49 
50   DISALLOW_COPY_AND_ASSIGN(PipeControlMessageHandler);
51 };
52 
53 }  // namespace mojo
54 
55 #endif  // MOJO_PUBLIC_CPP_BINDINGS_PIPE_CONTROL_MESSAGE_HANDLER_H_
56