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

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: 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
Index: src/data_plan.cc
diff --git a/src/data_plan.cc b/src/data_plan.cc
index 9512acb7ac337f69d3f0680e15fd6063a3e979a5..0be4946fb3417e69168aee8e1b2816ee928f49fa 100644
--- a/src/data_plan.cc
+++ b/src/data_plan.cc
@@ -49,7 +49,11 @@ 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);
rtc 2010/11/23 04:38:58 I'm wondering if it would be better to have unit t
Vince Laviano 2010/11/23 05:11:04 Removed asserts that test values hardcoded in memb
+ CHECK_GE(local_bytes_used_, 0);
+ CHECK_GE(total_bytes_used_, 0);
}
DataPlan::~DataPlan() {
@@ -87,9 +91,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 +112,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 +139,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;
}

Powered by Google App Engine
This is Rietveld 408576698