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

Unified Diff: services/media/framework/safe_clone.h

Issue 1678433002: Motown: Remove LPCM optimizations, fix prepare, add flush, add ActiveMultistreamSink model/stage (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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: services/media/framework/safe_clone.h
diff --git a/services/media/framework/safe_clone.h b/services/media/framework/safe_clone.h
new file mode 100644
index 0000000000000000000000000000000000000000..86e7afbbbe80e81263447268b9178ebcec3f096d
--- /dev/null
+++ b/services/media/framework/safe_clone.h
@@ -0,0 +1,38 @@
+// Copyright 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.
+
+#ifndef SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_
+#define SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_
+
+#include <memory>
+#include <vector>
+
+namespace mojo {
+namespace media {
+
+template<typename T>
+std::unique_ptr<T> SafeClone(const std::unique_ptr<T>& t_ptr) {
+ return t_ptr ? t_ptr.get()->Clone() : nullptr;
+}
+
+template<typename T>
+std::unique_ptr<std::vector<std::unique_ptr<T>>> SafeClone(
+ const std::unique_ptr<std::vector<std::unique_ptr<T>>>& vec) {
+ if (vec == nullptr) {
+ return nullptr;
+ }
+
+ std::vector<std::unique_ptr<T>>* result =
johngro 2016/02/08 22:33:36 why not just wrap result in a std::unique_ptr to b
dalesat 2016/02/09 00:34:11 This seemed simpler, but I don't really care one w
+ new std::vector<std::unique_ptr<T>>(vec->size());
+ for (const std::unique_ptr<T>& t_ptr : *vec.get()) {
+ result->push_back(SafeClone(t_ptr));
+ }
+
+ return std::unique_ptr<std::vector<std::unique_ptr<T>>>(result);
+}
+
+} // namespace media
+} // namespace mojo
+
+#endif // SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_

Powered by Google App Engine
This is Rietveld 408576698