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