| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS 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 #include "src/data_plan.h" |
| 6 |
| 7 #include <glog/logging.h> |
| 8 |
| 9 namespace cashew { |
| 10 |
| 11 // libcros CellularDataPlan property names |
| 12 static const char* kCellularDataPlanName = "CellularPlanName"; |
| 13 static const char* kCellularDataPlanType = "CellularPlanType"; |
| 14 static const char* kCellularDataPlanUpdateTime = "CellularPlanUpdateTime"; |
| 15 static const char* kCellularDataPlanStartTime = "CellularPlanStart"; |
| 16 static const char* kCellularDataPlanEndTime = "CellularPlanEnd"; |
| 17 static const char* kCellularDataPlanDataBytesMax = "CellularPlanDataBytes"; |
| 18 static const char* kCellularDataPlanDataBytesUsed = "CellularDataBytesUsed"; |
| 19 |
| 20 // libcros CellularDataPlan type values |
| 21 static const char* kCellularDataPlanTypeUnlimited = "UNLIMITED"; |
| 22 static const char* kCellularDataPlanTypeMeteredFree = "METERED_BASE"; |
| 23 static const char* kCellularDataPlanTypeMeteredPaid = "METERED_PAID"; |
| 24 |
| 25 DataPlan::DataPlan(const std::string& name, DataPlan::Type type, |
| 26 base::Time update_time, base::Time start_time, |
| 27 base::Time end_time, Bytes data_bytes_max, |
| 28 Bytes data_bytes_used) |
| 29 : name_(name), type_(type), update_time_(update_time), |
| 30 start_time_(start_time), end_time_(end_time), |
| 31 data_bytes_max_(data_bytes_max), data_bytes_used_(data_bytes_used) { |
| 32 } |
| 33 |
| 34 DataPlan::~DataPlan() { |
| 35 } |
| 36 |
| 37 const std::string& DataPlan::GetName() const { |
| 38 return name_; |
| 39 } |
| 40 |
| 41 DataPlan::Type DataPlan::GetType() const { |
| 42 return type_; |
| 43 } |
| 44 |
| 45 base::Time DataPlan::GetUpdateTime() const { |
| 46 return update_time_; |
| 47 } |
| 48 |
| 49 base::Time DataPlan::GetStartTime() const { |
| 50 return start_time_; |
| 51 } |
| 52 |
| 53 base::Time DataPlan::GetEndTime() const { |
| 54 return end_time_; |
| 55 } |
| 56 |
| 57 Bytes DataPlan::GetDataBytesMax() const { |
| 58 return data_bytes_max_; |
| 59 } |
| 60 |
| 61 Bytes DataPlan::GetDataBytesUsed() const { |
| 62 return data_bytes_used_; |
| 63 } |
| 64 |
| 65 DBusDataPlan DataPlan::ToDBusFormat() const { |
| 66 DBusDataPlan plan; |
| 67 // Indexing into map w/ nonexistent key causes empty DBus::Variant to be |
| 68 // created and inserted. We then fill in the desired value via its writer |
| 69 // DBus::MessageIterator. |
| 70 plan[kCellularDataPlanName].writer().append_string(name_.c_str()); |
| 71 plan[kCellularDataPlanType].writer().append_string(TypeToString(type_)); |
| 72 plan[kCellularDataPlanUpdateTime].writer().append_int64( |
| 73 update_time_.ToInternalValue()); |
| 74 plan[kCellularDataPlanStartTime].writer().append_int64( |
| 75 start_time_.ToInternalValue()); |
| 76 plan[kCellularDataPlanEndTime].writer().append_int64( |
| 77 end_time_.ToInternalValue()); |
| 78 // omit max bytes field for unlimited plans |
| 79 // can libcros/Chrome deal? if not, can set this to int64 max. |
| 80 if (type_ != kTypeUnlimited) { |
| 81 plan[kCellularDataPlanDataBytesMax].writer().append_int64(data_bytes_max_); |
| 82 } |
| 83 plan[kCellularDataPlanDataBytesUsed].writer().append_int64(data_bytes_used_); |
| 84 return plan; |
| 85 } |
| 86 |
| 87 // private methods |
| 88 |
| 89 const char* DataPlan::TypeToString(DataPlan::Type type) const { |
| 90 switch (type) { |
| 91 case kTypeUnlimited: |
| 92 return kCellularDataPlanTypeUnlimited; |
| 93 case kTypeMeteredFree: |
| 94 return kCellularDataPlanTypeMeteredFree; |
| 95 case kTypeMeteredPaid: |
| 96 return kCellularDataPlanTypeMeteredPaid; |
| 97 default: |
| 98 DCHECK(false); |
| 99 } |
| 100 } |
| 101 |
| 102 } // namespace cashew |
| OLD | NEW |