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_RENDERER_MEDIA_AEC_DUMP_MESSAGE_FILTER_H_
6 #define CONTENT_RENDERER_MEDIA_AEC_DUMP_MESSAGE_FILTER_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
11 #include "content/renderer/render_thread_impl.h"
12 #include "ipc/ipc_platform_file.h"
13 #include "ipc/message_filter.h"
16 class MessageLoopProxy;
21 // MessageFilter that handles AEC dump messages and forwards them to an
23 class CONTENT_EXPORT AecDumpMessageFilter : public IPC::MessageFilter {
25 class AecDumpDelegate {
27 virtual void OnAecDumpFile(
28 const IPC::PlatformFileForTransit& file_handle) = 0;
29 virtual void OnDisableAecDump() = 0;
30 virtual void OnIpcClosing() = 0;
34 const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
35 const scoped_refptr<base::MessageLoopProxy>& main_message_loop);
37 // Getter for the one AecDumpMessageFilter object.
38 static scoped_refptr<AecDumpMessageFilter> Get();
40 // Adds a delegate that receives the enable and disable notifications.
41 void AddDelegate(AecDumpMessageFilter::AecDumpDelegate* delegate);
43 // Removes a delegate.
44 void RemoveDelegate(AecDumpMessageFilter::AecDumpDelegate* delegate);
46 // IO message loop associated with this message filter.
47 scoped_refptr<base::MessageLoopProxy> io_message_loop() const {
48 return io_message_loop_;
52 ~AecDumpMessageFilter() override;
55 // Sends an IPC message using |sender_|.
56 void Send(IPC::Message* message);
58 // Registers a consumer of AEC dump in the browser process. This consumer will
59 // get a file handle when the AEC dump is enabled and a notification when it
61 void RegisterAecDumpConsumer(int id);
63 // Unregisters a consumer of AEC dump in the browser process.
64 void UnregisterAecDumpConsumer(int id);
66 // IPC::MessageFilter override. Called on |io_message_loop|.
67 bool OnMessageReceived(const IPC::Message& message) override;
68 void OnFilterAdded(IPC::Sender* sender) override;
69 void OnFilterRemoved() override;
70 void OnChannelClosing() override;
72 // Accessed on |io_message_loop|.
73 void OnEnableAecDump(int id, IPC::PlatformFileForTransit file_handle);
74 void OnDisableAecDump();
76 // Accessed on |main_message_loop_|.
77 void DoEnableAecDump(int id, IPC::PlatformFileForTransit file_handle);
78 void DoDisableAecDump();
79 void DoChannelClosingOnDelegates();
80 int GetIdForDelegate(AecDumpMessageFilter::AecDumpDelegate* delegate);
82 // Accessed on |io_message_loop_|.
85 // The delgates for this filter. Must only be accessed on
86 // |main_message_loop_|.
87 typedef std::map<int, AecDumpMessageFilter::AecDumpDelegate*> DelegateMap;
88 DelegateMap delegates_;
90 // Counter for generating unique IDs to delegates. Accessed on
91 // |main_message_loop_|.
92 int delegate_id_counter_;
94 // Message loop on which IPC calls are driven.
95 const scoped_refptr<base::MessageLoopProxy> io_message_loop_;
98 const scoped_refptr<base::MessageLoopProxy> main_message_loop_;
100 // The singleton instance for this filter.
101 static AecDumpMessageFilter* g_filter;
103 DISALLOW_COPY_AND_ASSIGN(AecDumpMessageFilter);
106 } // namespace content
108 #endif // CONTENT_RENDERER_MEDIA_AEC_DUMP_MESSAGE_FILTER_H_