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

Unified Diff: src/data_plan.cc

Issue 5321001: cashew: don't propagate inactive plans to clients (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Address rtc code review comments Created 10 years, 1 month 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
« no previous file with comments | « src/data_plan.h ('k') | src/data_plan_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/data_plan.cc
diff --git a/src/data_plan.cc b/src/data_plan.cc
index 9512acb7ac337f69d3f0680e15fd6063a3e979a5..e6c5a7198fb8b61239dc1ccac65cc4952195f155 100644
--- a/src/data_plan.cc
+++ b/src/data_plan.cc
@@ -49,7 +49,9 @@ DataPlan::DataPlan(const std::string& name, DataPlan::Type type,
: name_(name), type_(type), update_time_(update_time),
start_time_(start_time), end_time_(end_time),
data_bytes_max_(data_bytes_max), data_bytes_used_(data_bytes_used),
- local_bytes_used_(0) {
+ local_bytes_used_(0), total_bytes_used_(data_bytes_used) {
+ CHECK_GE(data_bytes_max_, 0);
+ CHECK_GE(data_bytes_used_, 0);
}
DataPlan::~DataPlan() {
@@ -87,9 +89,18 @@ Bytes DataPlan::GetLocalBytesUsed() const {
return local_bytes_used_;
}
+Bytes DataPlan::GetTotalBytesUsed() const {
+ return total_bytes_used_;
+}
+
void DataPlan::SetLocalBytesUsed(Bytes local_bytes_used) {
CHECK_GE(local_bytes_used, 0);
local_bytes_used_ = local_bytes_used;
+ total_bytes_used_ = data_bytes_used_ + local_bytes_used_;
+ if (total_bytes_used_ < 0) {
+ LOG(WARNING) << "SetLocalBytesUsed: overflow detected";
+ total_bytes_used_ = kint64max;
+ }
}
bool DataPlan::IsActive() const {
@@ -99,7 +110,7 @@ bool DataPlan::IsActive() const {
return false;
}
// is the plan exhausted?
- if (type_ != kTypeUnlimited && data_bytes_used_ >= data_bytes_max_) {
+ if (type_ != kTypeUnlimited && total_bytes_used_ >= data_bytes_max_) {
return false;
}
return true;
@@ -126,8 +137,7 @@ DBusDataPlan DataPlan::ToDBusFormat() const {
// send our best estimate of data bytes used
// this is the baseline, if any, that we received from the carrier usage API
// plus any local traffic that we've measured since then
- Bytes total_bytes_used = data_bytes_used_ + local_bytes_used_;
- plan[kCellularDataPlanDataBytesUsed].writer().append_int64(total_bytes_used);
+ plan[kCellularDataPlanDataBytesUsed].writer().append_int64(total_bytes_used_);
return plan;
}
« no previous file with comments | « src/data_plan.h ('k') | src/data_plan_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698