tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rlogconnector.h (4364B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 // Some of this code is cut-and-pasted from nICEr. Copyright is:
      8 
      9 /*
     10 Copyright (c) 2007, Adobe Systems, Incorporated
     11 All rights reserved.
     12 
     13 Redistribution and use in source and binary forms, with or without
     14 modification, are permitted provided that the following conditions are
     15 met:
     16 
     17 * Redistributions of source code must retain the above copyright
     18  notice, this list of conditions and the following disclaimer.
     19 
     20 * Redistributions in binary form must reproduce the above copyright
     21  notice, this list of conditions and the following disclaimer in the
     22  documentation and/or other materials provided with the distribution.
     23 
     24 * Neither the name of Adobe Systems, Network Resonance nor the names of its
     25  contributors may be used to endorse or promote products derived from
     26  this software without specific prior written permission.
     27 
     28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     39 */
     40 
     41 /* This Source Code Form is subject to the terms of the Mozilla Public
     42 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     43 * You can obtain one at http://mozilla.org/MPL/2.0/. */
     44 
     45 /* Original author: bcampen@mozilla.com */
     46 
     47 /*
     48   This file defines an r_dest_vlog that can be used to accumulate log messages
     49   for later inspection/filtering. The intent is to use this for interactive
     50   debug purposes on an about:webrtc page or similar.
     51 */
     52 
     53 #ifndef rlogconnector_h__
     54 #define rlogconnector_h__
     55 
     56 #include <stdint.h>
     57 
     58 #include <deque>
     59 #include <string>
     60 #include <vector>
     61 
     62 #include "m_cpp_utils.h"
     63 #include "mozilla/Mutex.h"
     64 
     65 namespace mozilla {
     66 
     67 class RLogConnector {
     68 public:
     69  /*
     70     NB: These are not threadsafe, nor are they safe to call during static
     71     init/deinit.
     72  */
     73  static RLogConnector* CreateInstance();
     74  static RLogConnector* GetInstance();
     75  static void DestroyInstance();
     76 
     77  /*
     78     Retrieves log statements that match a given substring, subject to a
     79     limit. |matching_logs| will be filled in chronological order (front()
     80     is oldest, back() is newest). |limit| == 0 will be interpreted as no
     81     limit.
     82  */
     83  void Filter(const std::string& substring, uint32_t limit,
     84              std::deque<std::string>* matching_logs);
     85 
     86  void FilterAny(const std::vector<std::string>& substrings, uint32_t limit,
     87                 std::deque<std::string>* matching_logs);
     88 
     89  inline void GetAny(uint32_t limit, std::deque<std::string>* matching_logs) {
     90    Filter("", limit, matching_logs);
     91  }
     92 
     93  void SetLogLimit(uint32_t new_limit);
     94  bool ShouldLog(int level) const;
     95  void Log(int level, std::string&& log);
     96  void Clear();
     97 
     98  // Methods to signal when a PeerConnection exists in a Private Window.
     99  void EnterPrivateMode();
    100  void ExitPrivateMode();
    101 
    102 private:
    103  RLogConnector();
    104  ~RLogConnector();
    105  void RemoveOld();
    106  void AddMsg(std::string&& msg);
    107 
    108  static RLogConnector* instance;
    109 
    110  /*
    111   * Might be worthwhile making this a circular buffer, but I think it is
    112   * preferable to take up as little space as possible if no logging is
    113   * happening/the ringbuffer is not being used.
    114   */
    115  std::deque<std::string> log_messages_;
    116  /* Max size of log buffer (should we use time-depth instead/also?) */
    117  uint32_t log_limit_;
    118  OffTheBooksMutex mutex_;
    119  uint32_t disableCount_;
    120 
    121  DISALLOW_COPY_ASSIGN(RLogConnector);
    122 };  // class RLogConnector
    123 
    124 }  // namespace mozilla
    125 
    126 #endif  // rlogconnector_h__