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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
6 #define COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
7
8 #include <algorithm>
9 #include <limits>
10
11 #include "base/macros.h"
12
13 namespace framelet {
14
15 enum class ResourceUsageRangeType { DEFAULT, LEFT_UNBOUNDED, RIGHT_UNBOUNDED };
16
17 template <class T>
18 class ResourceUsageRange {
19 public:
20 ResourceUsageRange(ResourceUsageRangeType range_type, T bounded_end)
21 : range_type_(range_type),
22 low_(range_type_ == ResourceUsageRangeType::LEFT_UNBOUNDED
23 ? std::numeric_limits<T>::lowest()
24 : bounded_end),
25 high_(range_type_ == ResourceUsageRangeType::RIGHT_UNBOUNDED
26 ? std::numeric_limits<T>::max()
27 : bounded_end) {}
28
29 ResourceUsageRange(T start, T end)
30 : range_type_(ResourceUsageRangeType::DEFAULT),
31 low_(std::min(start, end)),
32 high_(std::max(start, end)) {}
33
34 ~ResourceUsageRange() {}
35
36 T high() const { return high_; }
37 T low() const { return low_; }
38
39 bool IsLowerThan(T val) const {
40 if (range_type_ == ResourceUsageRangeType::RIGHT_UNBOUNDED)
41 return false;
42 return val > high_;
43 }
44
45 bool IsHigherThan(T val) const {
46 if (range_type_ == ResourceUsageRangeType::LEFT_UNBOUNDED)
47 return false;
48 return val < low_;
49 }
50
51 bool Contains(T val) const { return !IsLowerThan(val) && !IsHigherThan(val); }
52
53 private:
54 const ResourceUsageRangeType range_type_;
55 const T low_;
56 const T high_;
57 DISALLOW_COPY_AND_ASSIGN(ResourceUsageRange);
58 };
59
60 } // namespace framelet
61
62 #endif // COMPONENTS_FRAMELET_BROWSER_RESOURCE_USAGE_RANGE_H_
OLDNEW
« 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