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

Side by Side Diff: src/data_plan.cc

Issue 4114002: cashew: data plans: used bytes should be optional for unlimited plans (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: jglasgow review fixes 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/data_plan_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 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/data_plan.h" 5 #include "src/data_plan.h"
6 6
7 #include <time.h> 7 #include <time.h>
8 8
9 #include <glog/logging.h> 9 #include <glog/logging.h>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 plan[kCellularDataPlanName].writer().append_string(name_.c_str()); 90 plan[kCellularDataPlanName].writer().append_string(name_.c_str());
91 plan[kCellularDataPlanType].writer().append_string( 91 plan[kCellularDataPlanType].writer().append_string(
92 TypeToLibcrosString(type_)); 92 TypeToLibcrosString(type_));
93 plan[kCellularDataPlanUpdateTime].writer().append_int64( 93 plan[kCellularDataPlanUpdateTime].writer().append_int64(
94 update_time_.ToInternalValue()); 94 update_time_.ToInternalValue());
95 plan[kCellularDataPlanStartTime].writer().append_int64( 95 plan[kCellularDataPlanStartTime].writer().append_int64(
96 start_time_.ToInternalValue()); 96 start_time_.ToInternalValue());
97 plan[kCellularDataPlanEndTime].writer().append_int64( 97 plan[kCellularDataPlanEndTime].writer().append_int64(
98 end_time_.ToInternalValue()); 98 end_time_.ToInternalValue());
99 // omit max bytes field for unlimited plans 99 // omit max bytes field for unlimited plans
100 // can libcros/Chrome deal? if not, can set this to int64 max.
101 if (type_ != kTypeUnlimited) { 100 if (type_ != kTypeUnlimited) {
102 plan[kCellularDataPlanDataBytesMax].writer().append_int64(data_bytes_max_); 101 plan[kCellularDataPlanDataBytesMax].writer().append_int64(data_bytes_max_);
103 } 102 }
103 // always send used bytes field, even if we had to assume a value of 0
104 // because this is an unlimited plan and the property was absent in the
105 // usage API replies that we received
106 // TODO(vlaviano): we'll be able to do better when we have local counters
104 plan[kCellularDataPlanDataBytesUsed].writer().append_int64(data_bytes_used_); 107 plan[kCellularDataPlanDataBytesUsed].writer().append_int64(data_bytes_used_);
105 return plan; 108 return plan;
106 } 109 }
107 110
108 // static 111 // static
109 DataPlan* DataPlan::FromDictionaryValue(const DictionaryValue *value, 112 DataPlan* DataPlan::FromDictionaryValue(const DictionaryValue *value,
110 const Policy *policy) { 113 const Policy *policy) {
111 CHECK_NOTNULL(value); 114 CHECK_NOTNULL(value);
112 CHECK_NOTNULL(policy); 115 CHECK_NOTNULL(policy);
113 std::string last_update_iso8601; 116 std::string last_update_iso8601;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 158 }
156 if (max_bytes < 0) { 159 if (max_bytes < 0) {
157 LOG(WARNING) << "FromDictionaryValue: max bytes is negative"; 160 LOG(WARNING) << "FromDictionaryValue: max bytes is negative";
158 return NULL; 161 return NULL;
159 } 162 }
160 DLOG(INFO) << "FromDictionaryValue: max bytes = " << max_bytes; 163 DLOG(INFO) << "FromDictionaryValue: max bytes = " << max_bytes;
161 } 164 }
162 165
163 int used_bytes = 0; 166 int used_bytes = 0;
164 if (!value->GetInteger(kCrosUsageDataPlanUsedBytesProperty, &used_bytes)) { 167 if (!value->GetInteger(kCrosUsageDataPlanUsedBytesProperty, &used_bytes)) {
165 LOG(WARNING) << "FromDictionaryValue: no used bytes property"; 168 // used bytes is required for metered plans, optional for unlimited plans
166 return NULL; 169 if (plan_type != kTypeUnlimited) {
170 LOG(WARNING) << "FromDictionaryValue: no used bytes property";
171 return NULL;
172 } else {
173 DLOG(INFO)
174 << "FromDictionaryValue: no used bytes property (using default of 0)";
175 }
167 } 176 }
168 if (used_bytes < 0) { 177 if (used_bytes < 0) {
169 LOG(WARNING) << "FromDictionaryValue: used bytes is negative"; 178 LOG(WARNING) << "FromDictionaryValue: used bytes is negative";
170 return NULL; 179 return NULL;
171 } 180 }
172 DLOG(INFO) << "FromDictionaryValue: used bytes = " << used_bytes; 181 DLOG(INFO) << "FromDictionaryValue: used bytes = " << used_bytes;
173 182
174 std::string start_time_iso8601; 183 std::string start_time_iso8601;
175 if (!value->GetString(kCrosUsageDataPlanStartTimeProperty, 184 if (!value->GetString(kCrosUsageDataPlanStartTimeProperty,
176 &start_time_iso8601)) { 185 &start_time_iso8601)) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 *type_out = kTypeMeteredFree; 291 *type_out = kTypeMeteredFree;
283 } else if (type_string == kCrosUsageDataPlanTypeMeteredPaid) { 292 } else if (type_string == kCrosUsageDataPlanTypeMeteredPaid) {
284 *type_out = kTypeMeteredPaid; 293 *type_out = kTypeMeteredPaid;
285 } else { 294 } else {
286 return false; 295 return false;
287 } 296 }
288 return true; 297 return true;
289 } 298 }
290 299
291 } // namespace cashew 300 } // namespace cashew
OLDNEW
« no previous file with comments | « no previous file | src/data_plan_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698