Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: net/quic/quartc/quartc_at_exit.cc

Issue 2324833004: Define Stable API for WebRTC/Quartc (Closed)
Patch Set: Fix the issues when testing with WebRTC. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/quic/quartc/quartc_at_exit.cc
diff --git a/net/quic/quartc/quartc_at_exit.cc b/net/quic/quartc/quartc_at_exit.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebd898d51f1008e5e9851218ad562832ada0e85a
--- /dev/null
+++ b/net/quic/quartc/quartc_at_exit.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/quartc/quartc_at_exit.h"
+
+namespace {
+
+// A test mode AtExitManager which is allowed be create more than one.
+// This should only be used for testing! AtExitManagers are kept on a global
+// stack, and it will be removed during destruction. This allows you to shadow
+// another AtExitManager.
+// Create a subclass as the test mode constructor of the AtExitManager is
+// protected.
pthatcher1 2016/10/14 18:58:59 "as the" => "because the"
zhihuang1 2016/10/16 00:45:27 Done.
+class AtExitManagerForTest : public base::AtExitManager {
+ public:
+ AtExitManagerForTest() : AtExitManager(true) {}
+};
+} // namespace
+
+namespace net {
+
+QuartcAtExitManager::QuartcAtExitManager() {}
+
+QuartcAtExitManager::~QuartcAtExitManager() {}
+
+void QuartcAtExitManager::SetAtExitManager(bool test_mode) {
+ if (at_exit_manager_) {
pthatcher1 2016/10/14 18:58:59 If the QuartcAtExitManager itsn't usable until aft
zhihuang1 2016/10/16 00:45:27 One reason I'm doing this when working in WebRTC,
+ LOG(WARNING) << "The AtExitManager has already been created";
+ return;
+ }
+ if (test_mode) {
+ // Only create ShadowingAtExitManager for unit tests.
+ LOG(WARNING) << "Creating an AtExitManager for tests.";
+ at_exit_manager_.reset(new AtExitManagerForTest);
+ } else {
+ at_exit_manager_.reset(new base::AtExitManager);
+ }
pthatcher1 2016/10/14 18:58:59 An alternative is to rename AtExitManagerForTest t
zhihuang1 2016/10/16 00:45:27 I think you mean we can have something like this:
+}
+
+std::unique_ptr<QuartcAtExitManagerInterface> CreateQuartcAtExitManager() {
+ return std::unique_ptr<QuartcAtExitManagerInterface>(new QuartcAtExitManager);
pthatcher1 2016/10/14 18:58:59 What's the point of having a function that just ca
zhihuang1 2016/10/16 00:45:27 I thought this QuartcAtExitManager is something li
+}
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698