Chromium Code Reviews| Index: content/renderer/media/capturing_link_secure_tracker.h |
| diff --git a/content/renderer/media/capturing_link_secure_tracker.h b/content/renderer/media/capturing_link_secure_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cfcda65e6270ebbeb39c935c13f15637c948ecec |
| --- /dev/null |
| +++ b/content/renderer/media/capturing_link_secure_tracker.h |
| @@ -0,0 +1,82 @@ |
| +// 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 CONTENT_RENDERER_MEDIA_CAPTURING_LINK_SECURT_TRACKER_H_ |
|
miu
2016/04/26 01:25:13
s/SECURT/SECURE/
xjz
2016/04/29 00:11:42
Done.
|
| +#define CONTENT_RENDERER_MEDIA_CAPTURING_LINK_SECURT_TRACKER_H_ |
| + |
| +#include <vector> |
| + |
| +// Tracks all connected links (video sinks / tracks), and reports if they are |
| +// all secure for video capturing. |
| +template <typename T> |
| +class CapturingLinkSecureTracker { |
|
miu
2016/04/26 01:25:14
Suggestion: Since this is tracking whether downstr
xjz
2016/04/29 00:11:42
Done.
|
| + public: |
| + CapturingLinkSecureTracker() : is_capturing_secure_(true) {} |
| + ~CapturingLinkSecureTracker() { DCHECK(links_secure_status_.empty()); } |
| + |
| + void AddLinkSecure(T* link, bool is_link_secure); |
|
miu
2016/04/26 01:25:14
naming nit: How about just Add(), Remove(), and Up
xjz
2016/04/29 00:11:42
Done.
|
| + void RemoveLinkSecure(T* link); |
| + void UpdateLinkSecure(T* link, bool is_link_secure); |
| + bool is_capturing_secure() { return is_capturing_secure_; } |
| + |
| + private: |
| + // This is true only if all connected links are reported secure. |
| + bool is_capturing_secure_; |
| + |
| + std::vector<std::pair<T*, bool>> links_secure_status_; |
|
miu
2016/04/26 01:25:14
Idea: What if this class just maintained a vector
xjz
2016/04/29 00:11:42
Done. Smart idea! Saves many lines of codes and co
|
| +}; |
| + |
| +template <typename T> |
| +void CapturingLinkSecureTracker<T>::AddLinkSecure(T* link, |
| + bool is_link_secure) { |
| + links_secure_status_.push_back(std::make_pair(link, is_link_secure)); |
| + is_capturing_secure_ &= is_link_secure; |
| +} |
| + |
| +template <typename T> |
| +void CapturingLinkSecureTracker<T>::RemoveLinkSecure(T* link) { |
| + bool is_link_secure = true; |
| + for (auto it = links_secure_status_.begin(); it != links_secure_status_.end(); |
| + ++it) { |
| + if (it->first == link) { |
| + is_link_secure = it->second; |
| + links_secure_status_.erase(it); |
| + break; |
| + } |
| + } |
| + if (is_link_secure) |
| + return; |
| + |
| + DCHECK(!is_capturing_secure_); |
| + // |is_track_secure_| needs to be updated as the removed link is insecure. |
| + is_capturing_secure_ = true; |
| + for (auto it = links_secure_status_.begin(); it != links_secure_status_.end(); |
| + ++it) |
| + is_capturing_secure_ &= it->second; |
| +} |
| + |
| +template <typename T> |
| +void CapturingLinkSecureTracker<T>::UpdateLinkSecure(T* link, |
| + bool is_link_secure) { |
| + for (auto it = links_secure_status_.begin(); it != links_secure_status_.end(); |
| + ++it) { |
| + if (it->first == link) { |
| + if (it->second == is_link_secure) |
| + return; |
| + it->second = is_link_secure; |
| + break; |
| + } |
| + } |
| + if (!is_link_secure) { |
| + is_capturing_secure_ = false; |
| + return; |
| + } |
| + |
| + is_capturing_secure_ = true; |
| + for (auto it = links_secure_status_.begin(); it != links_secure_status_.end(); |
| + ++it) |
| + is_capturing_secure_ &= it->second; |
| +} |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_CAPTURING_LINK_SECURT_TRACKER_H_ |