| OLD | NEW |
| 1 // Copyright (c) 2010, 2011 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010, 2011 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/service_impl.h" | 5 #include "src/service_impl.h" |
| 6 | 6 |
| 7 #include <glog/logging.h> | 7 #include <glog/logging.h> |
| 8 | 8 |
| 9 #include "src/data_plan_provider.h" | 9 #include "src/data_plan_provider.h" |
| 10 #include "src/device.h" | 10 #include "src/device.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // if we already have usage url, set new provider in motion | 252 // if we already have usage url, set new provider in motion |
| 253 if (!usage_url_.empty()) { | 253 if (!usage_url_.empty()) { |
| 254 provider_->SetUsageUrl(usage_url_); | 254 provider_->SetUsageUrl(usage_url_); |
| 255 ReconsiderSendingUsageRequests(); | 255 ReconsiderSendingUsageRequests(); |
| 256 } else { | 256 } else { |
| 257 // we'll do this later in OnUsageUrlUpdate | 257 // we'll do this later in OnUsageUrlUpdate |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 void ServiceImpl::OnByteCounterUpdate(uint64 rx_bytes, uint64 tx_bytes) { | 261 void ServiceImpl::OnByteCounterUpdate(uint64 rx_bytes, uint64 tx_bytes) { |
| 262 DCHECK(device_ != NULL); | |
| 263 DCHECK(device_->ByteCounterRunning()); | |
| 264 DLOG(INFO) << path_ << ": OnByteCounterUpdate: rx_bytes = " << rx_bytes | 262 DLOG(INFO) << path_ << ": OnByteCounterUpdate: rx_bytes = " << rx_bytes |
| 265 << ", tx_bytes = " << tx_bytes; | 263 << ", tx_bytes = " << tx_bytes; |
| 266 DataPlan *active_plan = DataPlan::GetActivePlan(data_plans_); | 264 // dispatch this notification to our data plans list and consider sending |
| 267 if (active_plan == NULL) { | 265 // out a signal if any plans were updated |
| 268 DLOG(WARNING) << path_ << ": OnByteCounterUpdate: no active plan"; | 266 if (DataPlan::OnByteCounterUpdate(&data_plans_, this, parent_, device_, |
| 269 return; | 267 rx_bytes, tx_bytes)) { |
| 268 MaybeEmitDataPlansUpdate(); |
| 270 } | 269 } |
| 271 Bytes local_bytes_used = rx_bytes + tx_bytes; | |
| 272 DLOG(INFO) << path_ << ": OnByteCounterUpdate: local_bytes_used = " | |
| 273 << local_bytes_used; | |
| 274 // try to detect two error conditions: | |
| 275 // (1) overflow of the unsigned addition above prior to the assignment | |
| 276 // (2) no overflow, but result has high order bit set and so is interpreted as | |
| 277 // a negative number when assigned to |local_bytes_used| | |
| 278 if (local_bytes_used < 0 || | |
| 279 static_cast<uint64>(local_bytes_used) < rx_bytes || | |
| 280 static_cast<uint64>(local_bytes_used) < tx_bytes) { | |
| 281 LOG(WARNING) << path_ << ": OnByteCounterUpdate: overflow detected"; | |
| 282 return; | |
| 283 } | |
| 284 active_plan->SetLocalBytesUsed(local_bytes_used); | |
| 285 DLOG(INFO) << path_ | |
| 286 << ": OnByteCounterUpdate: updated plan state: data bytes used = " | |
| 287 << active_plan->GetDataBytesUsed() << ", local bytes used = " | |
| 288 << active_plan->GetLocalBytesUsed() << ", total bytes used = " | |
| 289 << active_plan->GetTotalBytesUsed(); | |
| 290 MaybeEmitDataPlansUpdate(); | |
| 291 } | 270 } |
| 292 | 271 |
| 293 // DataPlanProviderDelegate methods | 272 // DataPlanProviderDelegate methods |
| 294 | 273 |
| 295 void ServiceImpl::OnRequestComplete(const DataPlanProvider *provider, | 274 void ServiceImpl::OnRequestComplete(const DataPlanProvider *provider, |
| 296 bool successful, | 275 bool successful, |
| 297 const Value *parsed_usage_update) { | 276 const Value *parsed_usage_update) { |
| 298 DCHECK(provider != NULL); | 277 DCHECK(provider != NULL); |
| 299 DCHECK(!successful || parsed_usage_update != NULL); | 278 DCHECK(!successful || parsed_usage_update != NULL); |
| 300 if (provider != provider_) { | 279 if (provider != provider_) { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 } | 668 } |
| 690 } | 669 } |
| 691 | 670 |
| 692 void ServiceImpl::AddHardcodedDataPlan() { | 671 void ServiceImpl::AddHardcodedDataPlan() { |
| 693 const std::string name = "Chromium OS Test Plan"; | 672 const std::string name = "Chromium OS Test Plan"; |
| 694 DataPlan::Type type = DataPlan::kTypeMeteredPaid; | 673 DataPlan::Type type = DataPlan::kTypeMeteredPaid; |
| 695 base::Time update_time = base::Time::Now(); | 674 base::Time update_time = base::Time::Now(); |
| 696 base::TimeDelta twelve_hours = base::TimeDelta::FromHours(12); | 675 base::TimeDelta twelve_hours = base::TimeDelta::FromHours(12); |
| 697 base::Time start_time = base::Time::Now() - twelve_hours; | 676 base::Time start_time = base::Time::Now() - twelve_hours; |
| 698 base::Time end_time = base::Time::Now() + twelve_hours; | 677 base::Time end_time = base::Time::Now() + twelve_hours; |
| 699 Bytes data_bytes_max = 100*1024*1024; // 100 MB | 678 ByteCount data_bytes_max = 100*1024*1024; // 100 MB |
| 700 Bytes data_bytes_used = 30*1024*1024; // 30 MB | 679 ByteCount data_bytes_used = 30*1024*1024; // 30 MB |
| 701 | 680 |
| 702 DataPlan *plan = new(std::nothrow) DataPlan(name, type, update_time, | 681 DataPlan *plan = new(std::nothrow) DataPlan(name, type, update_time, |
| 703 start_time, end_time, | 682 start_time, end_time, |
| 704 data_bytes_max, data_bytes_used); | 683 data_bytes_max, data_bytes_used); |
| 705 if (plan == NULL) { | 684 if (plan == NULL) { |
| 706 LOG(ERROR) << path_ << ": AddHardcodedDataPlan: could not create plan"; | 685 LOG(ERROR) << path_ << ": AddHardcodedDataPlan: could not create plan"; |
| 707 return; | 686 return; |
| 708 } | 687 } |
| 709 | 688 |
| 710 data_plans_.push_back(plan); | 689 data_plans_.push_back(plan); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 DCHECK(policy_ != NULL); | 893 DCHECK(policy_ != NULL); |
| 915 if (policy_->ShouldEmitDataPlansUpdate(data_plans_)) { | 894 if (policy_->ShouldEmitDataPlansUpdate(data_plans_)) { |
| 916 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: sending update"; | 895 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: sending update"; |
| 917 parent_->EmitDataPlansUpdate(*this); | 896 parent_->EmitDataPlansUpdate(*this); |
| 918 } else { | 897 } else { |
| 919 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: not sending update"; | 898 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: not sending update"; |
| 920 } | 899 } |
| 921 } | 900 } |
| 922 | 901 |
| 923 } // namespace cashew | 902 } // namespace cashew |
| OLD | NEW |