Commit 39b1f6cc authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Move WebRtcEventLogManager code into own namespace

This helps avoid polluting the global namespace with some
functions like GetBrowserContextId().

Bug: 775415
Change-Id: Iac37e7067be5a42141cf06481a5cc1c97fae3b8c
Reviewed-on: https://chromium-review.googlesource.com/1195482
Commit-Queue: Elad Alon <eladalon@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587500}
parent 544a2f36
......@@ -40,7 +40,6 @@ class ChromeResourceDispatcherHostDelegate;
class DevToolsAutoOpener;
class RemoteDebuggingServer;
class PrefRegistrySimple;
class WebRtcEventLogManager;
#if BUILDFLAG(ENABLE_PLUGINS)
class PluginsResourceService;
......@@ -71,6 +70,10 @@ namespace resource_coordinator {
class TabLifecycleUnitSource;
}
namespace webrtc_event_logging {
class WebRtcEventLogManager;
} // namespace webrtc_event_logging
// Real implementation of BrowserProcess that creates and returns the services.
class BrowserProcessImpl : public BrowserProcess,
public KeepAliveStateObserver {
......@@ -186,6 +189,8 @@ class BrowserProcessImpl : public BrowserProcess,
static void RegisterPrefs(PrefRegistrySimple* registry);
private:
using WebRtcEventLogManager = webrtc_event_logging::WebRtcEventLogManager;
// KeepAliveStateObserver implementation
void OnKeepAliveStateChanged(bool is_keeping_alive) override;
void OnKeepAliveRestartStateChanged(bool can_restart) override;
......
......@@ -39,6 +39,10 @@ class BrowserContext;
class PluginDataRemover;
}
namespace webrtc_event_logging {
class WebRtcEventLogManager;
} // namespace webrtc_event_logging
// A delegate used by BrowsingDataRemover to delete data specific to Chrome
// as the embedder.
class ChromeBrowsingDataRemoverDelegate
......@@ -178,6 +182,8 @@ class ChromeBrowsingDataRemoverDelegate
#endif
private:
using WebRtcEventLogManager = webrtc_event_logging::WebRtcEventLogManager;
// Called by the closures returned by CreatePendingTaskCompletionClosure().
// Checks if all tasks have completed, and if so, calls callback_.
void OnTaskComplete();
......
......@@ -38,16 +38,26 @@ using compression::GzipUncompress;
using extensions::Extension;
using extensions::WebrtcLoggingPrivateDiscardFunction;
using extensions::WebrtcLoggingPrivateSetMetaDataFunction;
using extensions::WebrtcLoggingPrivateStartAudioDebugRecordingsFunction;
using extensions::WebrtcLoggingPrivateStartEventLoggingFunction;
using extensions::WebrtcLoggingPrivateStartFunction;
using extensions::WebrtcLoggingPrivateStartRtpDumpFunction;
using extensions::WebrtcLoggingPrivateStopAudioDebugRecordingsFunction;
using extensions::WebrtcLoggingPrivateStopFunction;
using extensions::WebrtcLoggingPrivateStopRtpDumpFunction;
using extensions::WebrtcLoggingPrivateStoreFunction;
using extensions::WebrtcLoggingPrivateUploadFunction;
using extensions::WebrtcLoggingPrivateUploadStoredFunction;
using extensions::WebrtcLoggingPrivateStartAudioDebugRecordingsFunction;
using extensions::WebrtcLoggingPrivateStopAudioDebugRecordingsFunction;
using extensions::WebrtcLoggingPrivateStartEventLoggingFunction;
using webrtc_event_logging::kMaxRemoteLogFileSizeBytes;
using webrtc_event_logging::kStartRemoteLoggingFailureAlreadyLogging;
using webrtc_event_logging::kStartRemoteLoggingFailureFeatureDisabled;
using webrtc_event_logging::kStartRemoteLoggingFailureMaxSizeTooLarge;
using webrtc_event_logging::kStartRemoteLoggingFailureMaxSizeTooSmall;
using webrtc_event_logging::
kStartRemoteLoggingFailureUnknownOrInactivePeerConnection;
using webrtc_event_logging::kStartRemoteLoggingFailureUnlimitedSizeDisallowed;
using webrtc_event_logging::kWebRtcEventLogManagerUnlimitedFileSize;
using webrtc_event_logging::WebRtcEventLogManager;
namespace utils = extension_function_test_utils;
......
......@@ -16,6 +16,8 @@
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_process_host.h"
namespace webrtc_event_logging {
namespace {
using BrowserContext = content::BrowserContext;
......@@ -912,3 +914,5 @@ void WebRtcEventLogManager::ShutDownForTesting(base::OnceClosure reply) {
base::Unretained(&remote_logs_manager_),
std::move(reply)));
}
} // namespace webrtc_event_logging
......@@ -23,11 +23,15 @@
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/webrtc_event_logger.h"
class WebRTCInternalsIntegrationBrowserTest;
namespace content {
class BrowserContext;
class NetworkConnectionTracker;
};
namespace webrtc_event_logging {
// This is a singleton class running in the browser UI thread (ownership of
// the only instance lies in BrowserContext). It is in charge of writing WebRTC
// event logs to temporary files, then uploading those files to remote servers,
......@@ -153,9 +157,8 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
base::OnceClosure reply);
private:
friend class SigninManagerAndroidTest;
friend class WebRtcEventLogManagerTestBase;
friend class WebRTCInternalsIntegrationBrowserTest;
friend class ::WebRTCInternalsIntegrationBrowserTest;
using PeerConnectionKey = WebRtcEventLogPeerConnectionKey;
......@@ -375,4 +378,6 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogManager);
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_H_
......@@ -15,6 +15,8 @@
#include "content/public/browser/render_process_host.h"
#include "third_party/zlib/zlib.h"
namespace webrtc_event_logging {
using BrowserContextId = WebRtcEventLogPeerConnectionKey::BrowserContextId;
const size_t kWebRtcEventLogManagerUnlimitedFileSize = 0;
......@@ -810,3 +812,5 @@ base::FilePath GetRemoteBoundWebRtcEventLogsDir(
FILE_PATH_LITERAL("webrtc_event_logs");
return browser_context_dir.Append(kRemoteBoundLogSubDirectory);
}
} // namespace webrtc_event_logging
......@@ -17,6 +17,8 @@ namespace content {
class BrowserContext;
} // namespace content
namespace webrtc_event_logging {
// This file is intended for:
// 1. Code shared between WebRtcEventLogManager, WebRtcLocalEventLogManager
// and WebRtcRemoteEventLogManager.
......@@ -423,4 +425,6 @@ WebRtcEventLogPeerConnectionKey::BrowserContextId GetBrowserContextId(
base::FilePath GetRemoteBoundWebRtcEventLogsDir(
const base::FilePath& browser_context_dir);
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_COMMON_H_
......@@ -19,6 +19,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/google/compression_utils.h"
namespace webrtc_event_logging {
namespace {
constexpr LogCompressor::Result OK = LogCompressor::Result::OK;
constexpr LogCompressor::Result DISALLOWED = LogCompressor::Result::DISALLOWED;
......@@ -649,3 +651,5 @@ TEST_F(GzippedLogFileWriterTest,
EXPECT_FALSE(writer->Close());
EXPECT_FALSE(base::PathExists(path_)); // Errored files deleted by Close().
}
} // namespace webrtc_event_logging
......@@ -9,6 +9,8 @@
#include "chrome/browser/media/webrtc/webrtc_event_log_manager.h"
#include "content/public/browser/browser_context.h"
namespace webrtc_event_logging {
WebRtcEventLogManagerKeyedService::WebRtcEventLogManagerKeyedService(
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
......@@ -30,3 +32,5 @@ void WebRtcEventLogManagerKeyedService::Shutdown() {
manager->DisableForBrowserContext(browser_context_, base::OnceClosure());
}
}
} // namespace webrtc_event_logging
......@@ -12,6 +12,8 @@ namespace content {
class BrowserContext;
} // namespace content
namespace webrtc_event_logging {
// KeyedService working on behalf of WebRtcEventLogManager, informing it when
// new BrowserContext-s are loaded.
class WebRtcEventLogManagerKeyedService : public KeyedService {
......@@ -36,4 +38,6 @@ class WebRtcEventLogManagerKeyedService : public KeyedService {
DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogManagerKeyedService);
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_KEYED_SERVICE_H_
......@@ -9,6 +9,8 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
namespace webrtc_event_logging {
// static
WebRtcEventLogManagerKeyedServiceFactory*
WebRtcEventLogManagerKeyedServiceFactory::GetInstance() {
......@@ -34,3 +36,5 @@ KeyedService* WebRtcEventLogManagerKeyedServiceFactory::BuildServiceInstanceFor(
DCHECK(!context->IsOffTheRecord());
return new WebRtcEventLogManagerKeyedService(context);
}
} // namespace webrtc_event_logging
......@@ -15,6 +15,8 @@ namespace content {
class BrowserContext;
} // namespace content
namespace webrtc_event_logging {
// Produces WebRtcEventLogManagerKeyedService-s for non-incognito profiles.
class WebRtcEventLogManagerKeyedServiceFactory
: public BrowserContextKeyedServiceFactory {
......@@ -37,4 +39,6 @@ class WebRtcEventLogManagerKeyedServiceFactory
DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogManagerKeyedServiceFactory);
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_KEYED_SERVICE_FACTORY_H_
......@@ -16,6 +16,8 @@
#define IntToStringType base::IntToString
#endif
namespace webrtc_event_logging {
#if defined(OS_ANDROID)
const size_t kDefaultMaxLocalLogFileSizeBytes = 10000000;
const size_t kMaxNumberLocalWebRtcEventLogFiles = 3;
......@@ -252,3 +254,5 @@ base::FilePath WebRtcLocalEventLogManager::GetFilePath(
.AddExtension(log_file_writer_factory_.Extension())
.InsertBeforeExtensionASCII(base::StringPiece(stamp));
}
} // namespace webrtc_event_logging
......@@ -15,6 +15,8 @@
#include "base/time/clock.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h"
namespace webrtc_event_logging {
class WebRtcLocalEventLogManager final {
using LogFilesMap =
std::map<WebRtcEventLogPeerConnectionKey, std::unique_ptr<LogFileWriter>>;
......@@ -91,4 +93,6 @@ class WebRtcLocalEventLogManager final {
DISALLOW_COPY_AND_ASSIGN(WebRtcLocalEventLogManager);
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_LOCAL_H_
......@@ -21,6 +21,8 @@
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
namespace webrtc_event_logging {
// TODO(crbug.com/775415): Change max back to (1u << 29) after resolving the
// issue where we read the entire file into memory.
const size_t kMaxRemoteLogFileSizeBytes = 50000000u;
......@@ -905,3 +907,5 @@ WebRtcRemoteEventLogManager::FindNextPeerConnection(
}
return end;
}
} // namespace webrtc_event_logging
......@@ -18,6 +18,8 @@
// TODO(crbug.com/775415): Avoid uploading logs when Chrome shutdown imminent.
namespace webrtc_event_logging {
class WebRtcRemoteEventLogManager final
: public network::NetworkConnectionTracker::NetworkConnectionObserver {
using BrowserContextId = WebRtcEventLogPeerConnectionKey::BrowserContextId;
......@@ -403,4 +405,6 @@ class WebRtcRemoteEventLogManager final
DISALLOW_COPY_AND_ASSIGN(WebRtcRemoteEventLogManager);
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_REMOTE_H_
......@@ -57,6 +57,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/google/compression_utils.h"
namespace webrtc_event_logging {
#if defined(OS_WIN)
#define IntToStringType base::IntToString16
#else
......@@ -4320,3 +4322,5 @@ TEST_F(WebRtcEventLogManagerTestOnMobileDevices, RemoteBoundLoggingDisabled) {
}
#endif
} // namespace webrtc_event_logging
......@@ -8,6 +8,8 @@
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace webrtc_event_logging {
// Produce a LogFileWriter::Factory object.
std::unique_ptr<LogFileWriter::Factory> CreateLogFileWriterFactory(
WebRtcEventLogCompression compression) {
......@@ -92,3 +94,5 @@ size_t GzippedSize(const std::vector<std::string>& uncompressed) {
return result;
}
} // namespace webrtc_event_logging
......@@ -12,6 +12,8 @@
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h"
namespace webrtc_event_logging {
// Which type of compression, if any, LogFileWriterTest should use.
enum class WebRtcEventLogCompression {
NONE,
......@@ -75,4 +77,6 @@ size_t GzippedSize(const std::string& uncompressed);
// Same as other version, but with elements compressed in sequence.
size_t GzippedSize(const std::vector<std::string>& uncompressed);
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_UNITTEST_HELPERS_H_
......@@ -20,6 +20,8 @@
#include "services/network/public/cpp/simple_url_loader.h"
#include "ui/base/text/bytes_formatting.h"
namespace webrtc_event_logging {
namespace {
// TODO(crbug.com/817495): Eliminate the duplication with other uploaders.
const char kUploadContentType[] = "multipart/form-data";
......@@ -312,3 +314,5 @@ void WebRtcEventLogUploaderImpl::DeleteLogFile() {
LOG(ERROR) << "Could not delete pending WebRTC event log file.";
}
}
} // namespace webrtc_event_logging
......@@ -18,6 +18,8 @@ namespace network {
class SimpleURLLoader;
} // namespace network
namespace webrtc_event_logging {
// A sublcass of this interface will take ownership of a file, and either
// upload it to a remote server (actual implementation), or pretend to do so
// (in unit tests). Upon completion, success/failure will be reported by posting
......@@ -136,4 +138,6 @@ class WebRtcEventLogUploaderImpl : public WebRtcEventLogUploader {
scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
};
} // namespace webrtc_event_logging
#endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_UPLOADER_H_
......@@ -26,6 +26,8 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace webrtc_event_logging {
using ::testing::StrictMock;
using BrowserContextId = WebRtcEventLogPeerConnectionKey::BrowserContextId;
......@@ -376,3 +378,5 @@ TEST_F(WebRtcEventLogUploaderImplTest,
// TODO(crbug.com/775415): Add a unit test that shows that files with
// non-ASCII filenames are discard. (Or, alternatively, add support for them.)
} // namespace webrtc_event_logging
......@@ -15,6 +15,8 @@
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
using webrtc_event_logging::WebRtcEventLogManager;
namespace {
const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
}
......
......@@ -30,6 +30,7 @@
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
using content::BrowserThread;
using webrtc_event_logging::WebRtcEventLogManager;
// Key used to attach the handler to the RenderProcessHost.
const char WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey[] =
......
......@@ -303,9 +303,10 @@
using content::BrowserThread;
using net::URLRequestMockHTTPJob;
using testing::_;
using testing::Mock;
using testing::Return;
using testing::_;
using webrtc_event_logging::WebRtcEventLogManager;
namespace policy {
......
......@@ -395,7 +395,7 @@ void ChromeBrowserMainExtraPartsProfiles::
web_app::WebAppProviderFactory::GetInstance();
#endif
WebDataServiceFactory::GetInstance();
WebRtcEventLogManagerKeyedServiceFactory::GetInstance();
webrtc_event_logging::WebRtcEventLogManagerKeyedServiceFactory::GetInstance();
}
void ChromeBrowserMainExtraPartsProfiles::PreProfileInit() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment