Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2013 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_MEDIA_WEBRTC_INTERNALS_H_
      6 #define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
      7 
      8 #include "base/memory/singleton.h"
      9 #include "base/observer_list.h"
     10 #include "base/process/process.h"
     11 #include "base/values.h"
     12 #include "content/common/content_export.h"
     13 #include "content/public/browser/browser_child_process_observer.h"
     14 #include "content/public/browser/notification_observer.h"
     15 #include "content/public/browser/notification_registrar.h"
     16 
     17 namespace content {
     18 class WebRTCInternalsUIObserver;
     19 
     20 // This is a singleton class running in the browser UI thread.
     21 // It collects peer connection infomation from the renderers,
     22 // forwards the data to WebRTCInternalsUIObserver and
     23 // sends data collecting commands to the renderers.
     24 class CONTENT_EXPORT WebRTCInternals : public BrowserChildProcessObserver,
     25                                        public NotificationObserver {
     26  public:
     27   static WebRTCInternals* GetInstance();
     28 
     29   // This method is called when a PeerConnection is created.
     30   // |render_process_id| is the id of the render process (not OS pid), which is
     31   // needed because we might not be able to get the OS process id when the
     32   // render process terminates and we want to clean up.
     33   // |pid| is the renderer process id, |lid| is the renderer local id used to
     34   // identify a PeerConnection, |url| is the url of the tab owning the
     35   // PeerConnection, |servers| is the servers configuration, |constraints| is
     36   // the media constraints used to initialize the PeerConnection.
     37   void OnAddPeerConnection(int render_process_id,
     38                            base::ProcessId pid,
     39                            int lid,
     40                            const std::string& url,
     41                            const std::string& servers,
     42                            const std::string& constraints);
     43 
     44   // This method is called when PeerConnection is destroyed.
     45   // |pid| is the renderer process id, |lid| is the renderer local id.
     46   void OnRemovePeerConnection(base::ProcessId pid, int lid);
     47 
     48   // This method is called when a PeerConnection is updated.
     49   // |pid| is the renderer process id, |lid| is the renderer local id,
     50   // |type| is the update type, |value| is the detail of the update.
     51   void OnUpdatePeerConnection(base::ProcessId pid,
     52                               int lid,
     53                               const std::string& type,
     54                               const std::string& value);
     55 
     56   // This method is called when results from PeerConnectionInterface::GetStats
     57   // are available. |pid| is the renderer process id, |lid| is the renderer
     58   // local id, |value| is the list of stats reports.
     59   void OnAddStats(base::ProcessId pid, int lid, const base::ListValue& value);
     60 
     61   // Methods for adding or removing WebRTCInternalsUIObserver.
     62   void AddObserver(WebRTCInternalsUIObserver *observer);
     63   void RemoveObserver(WebRTCInternalsUIObserver *observer);
     64 
     65   // Sends all update data to the observers.
     66   void SendAllUpdates();
     67 
     68   // Tells the renderer processes to start or stop recording RTP packets.
     69   void StartRtpRecording();
     70   void StopRtpRecording();
     71 
     72  private:
     73   friend struct DefaultSingletonTraits<WebRTCInternals>;
     74 
     75   WebRTCInternals();
     76   virtual ~WebRTCInternals();
     77 
     78   void SendUpdate(const std::string& command, base::Value* value);
     79 
     80   // BrowserChildProcessObserver implementation.
     81   virtual void BrowserChildProcessCrashed(
     82       const ChildProcessData& data) OVERRIDE;
     83 
     84   // NotificationObserver implementation.
     85   virtual void Observe(int type,
     86                        const NotificationSource& source,
     87                        const NotificationDetails& details) OVERRIDE;
     88 
     89   // Called when a renderer exits (including crashes).
     90   void OnRendererExit(int render_process_id);
     91 
     92   void SendRtpRecordingUpdate();
     93 
     94   ObserverList<WebRTCInternalsUIObserver> observers_;
     95 
     96   // |peer_connection_data_| is a list containing all the PeerConnection
     97   // updates.
     98   // Each item of the list represents the data for one PeerConnection, which
     99   // contains these fields:
    100   // "pid" -- processId of the renderer that creates the PeerConnection.
    101   // "lid" -- local Id assigned to the PeerConnection.
    102   // "url" -- url of the web page that created the PeerConnection.
    103   // "servers" and "constraints" -- server configuration and media constraints
    104   // used to initialize the PeerConnection respectively.
    105   // "log" -- a ListValue contains all the updates for the PeerConnection. Each
    106   // list item is a DictionaryValue containing "type" and "value", both of which
    107   // are strings.
    108   base::ListValue peer_connection_data_;
    109 
    110   NotificationRegistrar registrar_;
    111 
    112   bool is_recording_rtp_;
    113 };
    114 
    115 }  // namespace content
    116 
    117 #endif  // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
    118