• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_COMMON_RESPONSE_MANAGER_H_
6 #define CEF_LIBCEF_COMMON_RESPONSE_MANAGER_H_
7 #pragma once
8 
9 #include <map>
10 
11 #include "include/cef_base.h"
12 
13 #include "base/sequence_checker.h"
14 
15 struct Cef_Response_Params;
16 
17 // This class is not thread-safe.
18 class CefResponseManager {
19  public:
20   // Used for handling response messages.
21   class Handler : public virtual CefBaseRefCounted {
22    public:
23     virtual void OnResponse(const Cef_Response_Params& params) = 0;
24   };
25 
26   // Used for handling response ack messages.
27   class AckHandler : public virtual CefBaseRefCounted {
28    public:
29     virtual void OnResponseAck() = 0;
30   };
31 
32   CefResponseManager();
33 
34   // Returns the next unique request id.
35   int GetNextRequestId();
36 
37   // Register a response handler and return the unique request id.
38   int RegisterHandler(CefRefPtr<Handler> handler);
39 
40   // Run the response handler for the specified request id. Returns true if a
41   // handler was run.
42   bool RunHandler(const Cef_Response_Params& params);
43 
44   // Register a response ack handler for the specified request id.
45   void RegisterAckHandler(int request_id, CefRefPtr<AckHandler> handler);
46 
47   // Run the response ack handler for the specified request id. Returns true if
48   // a handler was run.
49   bool RunAckHandler(int request_id);
50 
51  private:
52   // Used for generating unique request ids.
53   int next_request_id_;
54 
55   // Map of unique request ids to Handler references.
56   typedef std::map<int, CefRefPtr<Handler>> HandlerMap;
57   HandlerMap handlers_;
58 
59   // Map of unique request ids to AckHandler references.
60   typedef std::map<int, CefRefPtr<AckHandler>> AckHandlerMap;
61   AckHandlerMap ack_handlers_;
62 
63   SEQUENCE_CHECKER(sequence_checker_);
64 };
65 
66 #endif  // CEF_LIBCEF_COMMON_RESPONSE_MANAGER_H_
67