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

Unified Diff: components/framelet/browser/resource_usage_range.h

Issue 1602663003: Framelet Prototype 2016 using Mojo IPC Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Disabled oilpan Created 4 years, 11 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: components/framelet/browser/resource_usage_range.h
diff --git a/components/framelet/browser/resource_usage_range.h b/components/framelet/browser/resource_usage_range.h
new file mode 100644
index 0000000000000000000000000000000000000000..c96cb43a249e25541348317ccfde954ca12cdd45
--- /dev/null
+++ b/components/framelet/browser/resource_usage_range.h
@@ -0,0 +1,62 @@
+// Copyright 2015 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 COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
+#define COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
+
+#include <algorithm>
+#include <limits>
+
+#include "base/macros.h"
+
+namespace framelet {
+
+enum class ResourceUsageRangeType { DEFAULT, LEFT_UNBOUNDED, RIGHT_UNBOUNDED };
+
+template <class T>
+class ResourceUsageRange {
+ public:
+ ResourceUsageRange(ResourceUsageRangeType range_type, T bounded_end)
+ : range_type_(range_type),
+ low_(range_type_ == ResourceUsageRangeType::LEFT_UNBOUNDED
+ ? std::numeric_limits<T>::lowest()
+ : bounded_end),
+ high_(range_type_ == ResourceUsageRangeType::RIGHT_UNBOUNDED
+ ? std::numeric_limits<T>::max()
+ : bounded_end) {}
+
+ ResourceUsageRange(T start, T end)
+ : range_type_(ResourceUsageRangeType::DEFAULT),
+ low_(std::min(start, end)),
+ high_(std::max(start, end)) {}
+
+ ~ResourceUsageRange() {}
+
+ T high() const { return high_; }
+ T low() const { return low_; }
+
+ bool IsLowerThan(T val) const {
+ if (range_type_ == ResourceUsageRangeType::RIGHT_UNBOUNDED)
+ return false;
+ return val > high_;
+ }
+
+ bool IsHigherThan(T val) const {
+ if (range_type_ == ResourceUsageRangeType::LEFT_UNBOUNDED)
+ return false;
+ return val < low_;
+ }
+
+ bool Contains(T val) const { return !IsLowerThan(val) && !IsHigherThan(val); }
+
+ private:
+ const ResourceUsageRangeType range_type_;
+ const T low_;
+ const T high_;
+ DISALLOW_COPY_AND_ASSIGN(ResourceUsageRange);
+};
+
+} // namespace framelet
+
+#endif // COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
« no previous file with comments | « components/framelet/browser/framelet_memory_tracker_client.h ('k') | components/framelet/browser/resource_usage_reporter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698