| OLD | NEW |
| 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/service.h" | 5 #include "src/service.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" |
| 11 #include "src/policy.h" | 11 #include "src/policy.h" |
| 12 #include "src/service_manager.h" | 12 #include "src/service_manager.h" |
| 13 | 13 |
| 14 namespace cashew { | 14 namespace cashew { |
| 15 | 15 |
| 16 // Flimflam Service D-Bus identifiers | 16 // Flimflam Service D-Bus identifiers |
| 17 static const char *kFlimflamServiceName = "org.chromium.flimflam"; | 17 static const char *kFlimflamServiceName = "org.chromium.flimflam"; |
| 18 | 18 |
| 19 // Flimflam Service property names | 19 // Flimflam Service property names |
| 20 static const char *kFlimflamServiceDeviceProperty = "Device"; | 20 static const char *kFlimflamServiceDeviceProperty = "Device"; |
| 21 static const char *kFlimflamServiceStateProperty = "State"; | 21 static const char *kFlimflamServiceStateProperty = "State"; |
| 22 static const char *kFlimflamServiceTypeProperty = "Type"; | 22 static const char *kFlimflamServiceTypeProperty = "Type"; |
| 23 static const char *kFlimflamServiceUsageUrlProperty = "Cellular.UsageUrl"; | 23 static const char *kFlimflamServiceUsageUrlProperty = "Cellular.UsageUrl"; |
| 24 static const char *kFlimflamServiceRestrictedPoolProperty = |
| 25 "Cellular.RestrictedPool"; |
| 24 | 26 |
| 25 // Flimflam Service on-the-wire State values | 27 // Flimflam Service on-the-wire State values |
| 26 static const char *kFlimflamServiceStateIdle = "idle"; | 28 static const char *kFlimflamServiceStateIdle = "idle"; |
| 27 static const char *kFlimflamServiceStateCarrier = "carrier"; | 29 static const char *kFlimflamServiceStateCarrier = "carrier"; |
| 28 static const char *kFlimflamServiceStateAssociation = "association"; | 30 static const char *kFlimflamServiceStateAssociation = "association"; |
| 29 static const char *kFlimflamServiceStateConfiguration = "configuration"; | 31 static const char *kFlimflamServiceStateConfiguration = "configuration"; |
| 30 static const char *kFlimflamServiceStateReady = "ready"; | 32 static const char *kFlimflamServiceStateReady = "ready"; |
| 31 static const char *kFlimflamServiceStateDisconnect = "disconnect"; | 33 static const char *kFlimflamServiceStateDisconnect = "disconnect"; |
| 32 static const char *kFlimflamServiceStateFailure = "failure"; | 34 static const char *kFlimflamServiceStateFailure = "failure"; |
| 33 static const char *kFlimflamServiceStateActivationFailure = | 35 static const char *kFlimflamServiceStateActivationFailure = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 68 |
| 67 Service::Service(ServiceManager * const parent, | 69 Service::Service(ServiceManager * const parent, |
| 68 DBus::Connection& connection, // NOLINT | 70 DBus::Connection& connection, // NOLINT |
| 69 const DBus::Path& path) | 71 const DBus::Path& path) |
| 70 : DBus::ObjectProxy(connection, path, kFlimflamServiceName), | 72 : DBus::ObjectProxy(connection, path, kFlimflamServiceName), |
| 71 parent_(CHECK_NOTNULL(parent)), connection_(connection), path_(path), | 73 parent_(CHECK_NOTNULL(parent)), connection_(connection), path_(path), |
| 72 state_(kStateUnknown), type_(kTypeUnknown), device_(NULL), | 74 state_(kStateUnknown), type_(kTypeUnknown), device_(NULL), |
| 73 provider_(NULL), request_in_progress_(false), | 75 provider_(NULL), request_in_progress_(false), |
| 74 update_timeout_source_(NULL), policy_(NULL), | 76 update_timeout_source_(NULL), policy_(NULL), |
| 75 is_default_service_(false), get_properties_source_id_(0), | 77 is_default_service_(false), get_properties_source_id_(0), |
| 76 retrying_get_properties_(false) { | 78 retrying_get_properties_(false), restricted_pool_(false) { |
| 77 // schedule a GetProperties() call to our Flimflam service path to init state | 79 // schedule a GetProperties() call to our Flimflam service path to init state |
| 78 // we'll keep trying periodically until we succeed | 80 // we'll keep trying periodically until we succeed |
| 79 // we'll subsequently update this state by monitoring PropertyChanged signals | 81 // we'll subsequently update this state by monitoring PropertyChanged signals |
| 80 get_properties_source_id_ = | 82 get_properties_source_id_ = |
| 81 g_idle_add(StaticGetServicePropertiesCallback, this); | 83 g_idle_add(StaticGetServicePropertiesCallback, this); |
| 82 if (get_properties_source_id_ == 0) { | 84 if (get_properties_source_id_ == 0) { |
| 83 LOG(ERROR) << path_ << ": ctor: g_idle_add failed"; | 85 LOG(ERROR) << path_ << ": ctor: g_idle_add failed"; |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // cross-check with parent's idea of default technology | 152 // cross-check with parent's idea of default technology |
| 151 if (parent_->GetDefaultTechnology() != kTypeCellular) { | 153 if (parent_->GetDefaultTechnology() != kTypeCellular) { |
| 152 DLOG(WARNING) << path_ << ": IsDefaultService: " | 154 DLOG(WARNING) << path_ << ": IsDefaultService: " |
| 153 << "service manager doesn't think default technology is cellular"; | 155 << "service manager doesn't think default technology is cellular"; |
| 154 } | 156 } |
| 155 return true; | 157 return true; |
| 156 } | 158 } |
| 157 return false; | 159 return false; |
| 158 } | 160 } |
| 159 | 161 |
| 162 bool Service::RestrictedPool() const { |
| 163 // NOTE: For now, we rely strictly on the Cellular.RestrictedPool Flimflam |
| 164 // Service property, and we ignore the optional 'restricted' boolean that's |
| 165 // defined as part of the usage API. |
| 166 return restricted_pool_; |
| 167 } |
| 168 |
| 160 // Flimflam Service D-Bus Proxy methods | 169 // Flimflam Service D-Bus Proxy methods |
| 161 | 170 |
| 162 void Service::PropertyChanged(const std::string& property_name, | 171 void Service::PropertyChanged(const std::string& property_name, |
| 163 const DBus::Variant& new_value) { | 172 const DBus::Variant& new_value) { |
| 164 DLOG(INFO) << path_ << ": PropertyChanged: property_name = " << property_name; | 173 DLOG(INFO) << path_ << ": PropertyChanged: property_name = " << property_name; |
| 165 if (property_name == kFlimflamServiceDeviceProperty) { | 174 if (property_name == kFlimflamServiceDeviceProperty) { |
| 166 OnDeviceUpdate(new_value.reader().get_path()); | 175 OnDeviceUpdate(new_value.reader().get_path()); |
| 167 } else if (property_name == kFlimflamServiceStateProperty) { | 176 } else if (property_name == kFlimflamServiceStateProperty) { |
| 168 OnStateUpdate(new_value.reader().get_string()); | 177 OnStateUpdate(new_value.reader().get_string()); |
| 169 } else if (property_name == kFlimflamServiceTypeProperty) { | 178 } else if (property_name == kFlimflamServiceTypeProperty) { |
| 170 OnTypeUpdate(new_value.reader().get_string()); | 179 OnTypeUpdate(new_value.reader().get_string()); |
| 171 } else if (property_name == kFlimflamServiceUsageUrlProperty) { | 180 } else if (property_name == kFlimflamServiceUsageUrlProperty) { |
| 172 OnUsageUrlUpdate(new_value.reader().get_string()); | 181 OnUsageUrlUpdate(new_value.reader().get_string()); |
| 182 } else if (property_name == kFlimflamServiceRestrictedPoolProperty) { |
| 183 OnRestrictedPoolUpdate(new_value.reader().get_bool()); |
| 173 } else { | 184 } else { |
| 174 // we don't care about this property | 185 // we don't care about this property |
| 175 } | 186 } |
| 176 } | 187 } |
| 177 | 188 |
| 178 // Device methods | 189 // Device methods |
| 179 | 190 |
| 180 void Service::OnCarrierUpdate(const std::string& carrier) { | 191 void Service::OnCarrierUpdate(const std::string& carrier) { |
| 181 DLOG(INFO) << path_ << ": OnCarrierUpdate: carrier = " << carrier; | 192 DLOG(INFO) << path_ << ": OnCarrierUpdate: carrier = " << carrier; |
| 182 // NOTE: device_ can be NULL here because we may still be in Device ctor | 193 DCHECK(device_ != NULL); |
| 183 DCHECK(device_ == NULL || carrier == device_->GetCarrier()); | 194 DCHECK(carrier == device_->GetCarrier()); |
| 184 | 195 |
| 185 // get rid of state associated with old carrier | 196 // get rid of state associated with old carrier |
| 186 if (provider_ != NULL) { | 197 if (provider_ != NULL) { |
| 187 DCHECK(carrier != provider_->GetCarrier()); | 198 DCHECK(carrier != provider_->GetCarrier()); |
| 188 } | 199 } |
| 189 DeleteCarrierState(); | 200 DeleteCarrierState(); |
| 190 | 201 |
| 191 // if we don't have new carrier info, we can't do anything now | 202 // if we don't have new carrier info, we can't do anything now |
| 192 if (carrier == Device::kCarrierUnknown) { | 203 if (carrier.empty()) { |
| 193 return; | 204 return; |
| 194 } | 205 } |
| 195 | 206 |
| 196 // create state for new carrier | 207 // create state for new carrier |
| 197 DLOG(INFO) << path_ << ": OnCarrierUpdate: creating data plan provider"; | 208 DLOG(INFO) << path_ << ": OnCarrierUpdate: creating data plan provider"; |
| 198 provider_ = new(std::nothrow) DataPlanProvider(carrier); | 209 provider_ = new(std::nothrow) DataPlanProvider(carrier); |
| 199 if (provider_ == NULL) { | 210 if (provider_ == NULL) { |
| 200 LOG(ERROR) << path_ | 211 LOG(ERROR) << path_ |
| 201 << ": OnCarrierUpdate: could not create data plan provider"; | 212 << ": OnCarrierUpdate: could not create data plan provider"; |
| 202 return; | 213 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 213 | 224 |
| 214 // if we already have usage url, set new provider in motion | 225 // if we already have usage url, set new provider in motion |
| 215 if (!usage_url_.empty()) { | 226 if (!usage_url_.empty()) { |
| 216 provider_->SetUsageUrl(usage_url_); | 227 provider_->SetUsageUrl(usage_url_); |
| 217 ReconsiderSendingUsageRequests(); | 228 ReconsiderSendingUsageRequests(); |
| 218 } else { | 229 } else { |
| 219 // we'll do this later in OnUsageUrlUpdate | 230 // we'll do this later in OnUsageUrlUpdate |
| 220 } | 231 } |
| 221 } | 232 } |
| 222 | 233 |
| 234 void Service::OnByteCounterUpdate(uint64 rx_bytes, uint64 tx_bytes) { |
| 235 DCHECK(device_ != NULL); |
| 236 DCHECK(device_->ByteCounterRunning()); |
| 237 DLOG(INFO) << path_ << ": OnByteCounterUpdate: rx_bytes = " << rx_bytes |
| 238 << ", tx_bytes = " << tx_bytes; |
| 239 DataPlan *active_plan = DataPlan::GetActivePlan(data_plans_); |
| 240 if (active_plan == NULL) { |
| 241 DLOG(WARNING) << path_ << ": OnByteCounterUpdate: no active plan"; |
| 242 return; |
| 243 } |
| 244 Bytes local_bytes_used = rx_bytes + tx_bytes; |
| 245 DLOG(INFO) << path_ << ": OnByteCounterUpdate: local_bytes_used = " |
| 246 << local_bytes_used; |
| 247 // try to detect two error conditions: |
| 248 // (1) overflow of the unsigned addition above prior to the assignment |
| 249 // (2) no overflow, but result has high order bit set and so is interpreted as |
| 250 // a negative number when assigned to |local_bytes_used| |
| 251 if (local_bytes_used < 0 || |
| 252 static_cast<uint64>(local_bytes_used) < rx_bytes || |
| 253 static_cast<uint64>(local_bytes_used) < tx_bytes) { |
| 254 LOG(WARNING) << path_ << ": OnByteCounterUpdate: overflow detected"; |
| 255 return; |
| 256 } |
| 257 active_plan->SetLocalBytesUsed(local_bytes_used); |
| 258 MaybeEmitDataPlansUpdate(); |
| 259 } |
| 260 |
| 223 // DataPlanProviderDelegate methods | 261 // DataPlanProviderDelegate methods |
| 224 | 262 |
| 225 void Service::OnRequestComplete(const DataPlanProvider *provider, | 263 void Service::OnRequestComplete(const DataPlanProvider *provider, |
| 226 bool successful, | 264 bool successful, |
| 227 const Value *parsed_usage_update) { | 265 const Value *parsed_usage_update) { |
| 228 DCHECK(provider != NULL); | 266 DCHECK(provider != NULL); |
| 229 DCHECK(!successful || parsed_usage_update != NULL); | 267 DCHECK(!successful || parsed_usage_update != NULL); |
| 230 if (provider != provider_) { | 268 if (provider != provider_) { |
| 231 DLOG(WARNING) << path_ << ": OnRequestComplete: wrong provider"; | 269 DLOG(WARNING) << path_ << ": OnRequestComplete: wrong provider"; |
| 232 return; | 270 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 313 } |
| 276 if (status != kCrosUsageStatusOk) { | 314 if (status != kCrosUsageStatusOk) { |
| 277 LOG(WARNING) << path_ << ": OnRequestComplete: status: " << status; | 315 LOG(WARNING) << path_ << ": OnRequestComplete: status: " << status; |
| 278 OnCrosUsageErrorResult(status); | 316 OnCrosUsageErrorResult(status); |
| 279 return; | 317 return; |
| 280 } | 318 } |
| 281 | 319 |
| 282 bool restricted = false; | 320 bool restricted = false; |
| 283 if (root->GetBoolean(kCrosUsageRestrictedProperty, &restricted)) { | 321 if (root->GetBoolean(kCrosUsageRestrictedProperty, &restricted)) { |
| 284 DLOG(INFO) << path_ << ": OnRequestComplete: restricted = " << restricted; | 322 DLOG(INFO) << path_ << ": OnRequestComplete: restricted = " << restricted; |
| 323 // TODO(vlaviano): this should probably take precedence over our |
| 324 // Cellular.RestrictedPool property |
| 285 } else { | 325 } else { |
| 286 DLOG(INFO) << path_ << ": OnRequestComplete: no restricted property"; | 326 DLOG(INFO) << path_ << ": OnRequestComplete: no restricted property"; |
| 287 // restricted property is optional | 327 // restricted property is optional |
| 288 } | 328 } |
| 289 | 329 |
| 290 ListValue *plans = NULL; // list to which this points is owned by dictionary | 330 ListValue *plans = NULL; // list to which this points is owned by dictionary |
| 291 if (!root->GetList(kCrosUsagePlansProperty, &plans)) { | 331 if (!root->GetList(kCrosUsagePlansProperty, &plans)) { |
| 292 LOG(WARNING) << path_ << ": OnRequestComplete: no plans property"; | 332 LOG(WARNING) << path_ << ": OnRequestComplete: no plans property"; |
| 293 return; | 333 return; |
| 294 } | 334 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 315 } | 355 } |
| 316 DLOG(INFO) << path_ << ": OnRequestComplete: converted plan[" << i << "]"; | 356 DLOG(INFO) << path_ << ": OnRequestComplete: converted plan[" << i << "]"; |
| 317 new_plans.push_back(plan); | 357 new_plans.push_back(plan); |
| 318 } | 358 } |
| 319 | 359 |
| 320 // store new info, causing it to be used for subsequent updates to clients | 360 // store new info, causing it to be used for subsequent updates to clients |
| 321 DataPlanList old_plans = data_plans_; | 361 DataPlanList old_plans = data_plans_; |
| 322 data_plans_ = new_plans; | 362 data_plans_ = new_plans; |
| 323 LOG(INFO) << path_ << ": OnRequestComplete: updated data plans"; | 363 LOG(INFO) << path_ << ": OnRequestComplete: updated data plans"; |
| 324 | 364 |
| 325 // consult policy to determine if we should send an unsolicited update | 365 MaybeEmitDataPlansUpdate(); |
| 326 if (policy_->ShouldEmitDataPlansUpdate(old_plans, new_plans)) { | |
| 327 DLOG(INFO) << path_ << ": OnRequestComplete: sending update"; | |
| 328 parent_->EmitDataPlansUpdate(*this); | |
| 329 } else { | |
| 330 DLOG(INFO) << path_ << ": OnRequestComplete: not sending update"; | |
| 331 } | |
| 332 | 366 |
| 333 DLOG(INFO) << path_ << ": OnRequestComplete: deleting old data plans"; | 367 DLOG(INFO) << path_ << ": OnRequestComplete: deleting old data plans"; |
| 334 DeleteDataPlans(&old_plans); | 368 DeleteDataPlans(&old_plans); |
| 369 |
| 370 // start local byte counter so that we can stop hitting usage API |
| 371 // we'll stop the counter when we disconnect |
| 372 // we don't bother if carrier told us that there are no active data plans |
| 373 DataPlan *active_plan = DataPlan::GetActivePlan(data_plans_); |
| 374 if (active_plan == NULL) { |
| 375 DLOG(INFO) << path_ |
| 376 << ": OnRequestComplete: no active plans, not starting byte counter"; |
| 377 return; |
| 378 } |
| 379 DCHECK(device_ != NULL); |
| 380 DCHECK(!device_->ByteCounterRunning()); |
| 381 if (!device_->StartByteCounter()) { |
| 382 LOG(WARNING) << path_ |
| 383 << ": OnRequestComplete: could not start byte counter"; |
| 384 // we'll keep the update timer running and try again later |
| 385 } |
| 386 DLOG(INFO) << path_ << ": OnRequestComplete: started byte counter"; |
| 387 ReconsiderSendingUsageRequests(); |
| 335 } | 388 } |
| 336 | 389 |
| 337 // Service Manager methods | 390 // Service Manager methods |
| 338 | 391 |
| 339 void Service::OnDefaultServiceUpdate(bool is_default_service) { | 392 void Service::OnDefaultServiceUpdate(bool is_default_service) { |
| 340 DCHECK(is_default_service_ == !is_default_service); | 393 DCHECK(is_default_service_ == !is_default_service); |
| 341 DLOG(INFO) << path_ << ": OnDefaultServiceUpdate: is_default_service = " | 394 DLOG(INFO) << path_ << ": OnDefaultServiceUpdate: is_default_service = " |
| 342 << is_default_service; | 395 << is_default_service; |
| 343 is_default_service_ = is_default_service; | 396 is_default_service_ = is_default_service; |
| 344 if (is_default_service_) { | 397 if (is_default_service_) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 517 } |
| 465 usage_url_ = usage_url; | 518 usage_url_ = usage_url; |
| 466 if (provider_ != NULL) { | 519 if (provider_ != NULL) { |
| 467 DCHECK(usage_url_ != provider_->GetUsageUrl()); | 520 DCHECK(usage_url_ != provider_->GetUsageUrl()); |
| 468 StopSendingUsageRequests(); | 521 StopSendingUsageRequests(); |
| 469 provider_->SetUsageUrl(usage_url_); | 522 provider_->SetUsageUrl(usage_url_); |
| 470 ReconsiderSendingUsageRequests(); | 523 ReconsiderSendingUsageRequests(); |
| 471 } | 524 } |
| 472 } | 525 } |
| 473 | 526 |
| 527 void Service::OnRestrictedPoolUpdate(bool restricted_pool) { |
| 528 DLOG(INFO) << path_ << ": OnRestrictedPoolUpdate: restricted_pool = " |
| 529 << restricted_pool; |
| 530 if (restricted_pool == restricted_pool_) { |
| 531 return; |
| 532 } |
| 533 ReconsiderSendingUsageRequests(); |
| 534 } |
| 535 |
| 474 // static | 536 // static |
| 475 gboolean Service::StaticGetServicePropertiesCallback(gpointer data) { | 537 gboolean Service::StaticGetServicePropertiesCallback(gpointer data) { |
| 476 Service *service = reinterpret_cast<Service*>(data); | 538 Service *service = reinterpret_cast<Service*>(data); |
| 477 CHECK_NOTNULL(service); | 539 CHECK_NOTNULL(service); |
| 478 DCHECK_NE(service->GetGetPropertiesSourceId(), 0); | 540 DCHECK_NE(service->GetGetPropertiesSourceId(), 0); |
| 479 if (!service->GetServiceProperties()) { | 541 if (!service->GetServiceProperties()) { |
| 480 // call failed, so try again later | 542 // call failed, so try again later |
| 481 DLOG(WARNING) << service->GetPath() | 543 DLOG(WARNING) << service->GetPath() |
| 482 << ": StaticGetServicePropertiesCallback: " | 544 << ": StaticGetServicePropertiesCallback: " |
| 483 << "GetServiceProperties failed, will retry in " | 545 << "GetServiceProperties failed, will retry in " |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 return true; | 619 return true; |
| 558 } | 620 } |
| 559 it = properties.find(kFlimflamServiceUsageUrlProperty); | 621 it = properties.find(kFlimflamServiceUsageUrlProperty); |
| 560 if (it != properties.end()) { | 622 if (it != properties.end()) { |
| 561 const DBus::Variant& value = static_cast<DBus::Variant>(it->second); | 623 const DBus::Variant& value = static_cast<DBus::Variant>(it->second); |
| 562 OnUsageUrlUpdate(value.reader().get_string()); | 624 OnUsageUrlUpdate(value.reader().get_string()); |
| 563 } else { | 625 } else { |
| 564 DLOG(WARNING) << path_ | 626 DLOG(WARNING) << path_ |
| 565 << ": GetServiceProperties: no Cellular.UsageUrl property"; | 627 << ": GetServiceProperties: no Cellular.UsageUrl property"; |
| 566 } | 628 } |
| 629 it = properties.find(kFlimflamServiceRestrictedPoolProperty); |
| 630 if (it != properties.end()) { |
| 631 const DBus::Variant& value = static_cast<DBus::Variant>(it->second); |
| 632 OnRestrictedPoolUpdate(value.reader().get_bool()); |
| 633 } else { |
| 634 DLOG(WARNING) << path_ |
| 635 << ": GetServiceProperties: no Cellular.RestrictedPool property"; |
| 636 } |
| 567 return true; | 637 return true; |
| 568 } | 638 } |
| 569 | 639 |
| 570 void Service::DeleteDataPlans(DataPlanList *data_plans) { | 640 void Service::DeleteDataPlans(DataPlanList *data_plans) { |
| 571 DCHECK(data_plans != NULL); | 641 DCHECK(data_plans != NULL); |
| 572 while (!data_plans->empty()) { | 642 while (!data_plans->empty()) { |
| 573 DataPlan *plan = *data_plans->begin(); | 643 DataPlan *plan = *data_plans->begin(); |
| 574 DCHECK(plan != NULL); | 644 DCHECK(plan != NULL); |
| 575 DLOG(INFO) << path_ << ": DeleteDataPlans: deleting plan: " | 645 DLOG(INFO) << path_ << ": DeleteDataPlans: deleting plan: " |
| 576 << plan->GetName(); | 646 << plan->GetName(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 785 |
| 716 void Service::OnConnected() { | 786 void Service::OnConnected() { |
| 717 DLOG(INFO) << path_ << ": OnConnected"; | 787 DLOG(INFO) << path_ << ": OnConnected"; |
| 718 DCHECK(IsConnected()); | 788 DCHECK(IsConnected()); |
| 719 ReconsiderSendingUsageRequests(); | 789 ReconsiderSendingUsageRequests(); |
| 720 } | 790 } |
| 721 | 791 |
| 722 void Service::OnDisconnected() { | 792 void Service::OnDisconnected() { |
| 723 DLOG(INFO) << path_ << ": OnDisconnected"; | 793 DLOG(INFO) << path_ << ": OnDisconnected"; |
| 724 DCHECK(!IsConnected()); | 794 DCHECK(!IsConnected()); |
| 795 // stop byte counter |
| 796 // we'll issue a new usage API request when we reconnect |
| 797 if (device_ != NULL) { |
| 798 device_->StopByteCounter(); |
| 799 } |
| 725 ReconsiderSendingUsageRequests(); | 800 ReconsiderSendingUsageRequests(); |
| 726 } | 801 } |
| 727 | 802 |
| 728 bool Service::IsSendingUsageRequests() const { | 803 bool Service::IsSendingUsageRequests() const { |
| 729 return request_in_progress_ || update_timeout_source_ != NULL; | 804 return request_in_progress_ || update_timeout_source_ != NULL; |
| 730 } | 805 } |
| 731 | 806 |
| 732 // NOTE: we centralize our decisionmaking here to avoid insanity and just call | 807 // NOTE: we centralize our decisionmaking here to avoid insanity and just call |
| 733 // ReconsiderSendingUsageRequests when anything changes | 808 // ReconsiderSendingUsageRequests when anything changes |
| 734 bool Service::ShouldSendUsageRequests() const { | 809 bool Service::ShouldSendUsageRequests() const { |
| 735 if (provider_ == NULL) { | 810 if (provider_ == NULL) { |
| 736 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: no provider"; | 811 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: no provider"; |
| 737 DCHECK(policy_ == NULL); | 812 DCHECK(policy_ == NULL); |
| 738 return false; | 813 return false; |
| 739 } | 814 } |
| 740 DCHECK(device_ == NULL || device_->GetCarrier() != Device::kCarrierUnknown); | 815 DCHECK(device_ != NULL); |
| 816 DCHECK(!device_->GetCarrier().empty()); |
| 741 DCHECK(policy_ != NULL); | 817 DCHECK(policy_ != NULL); |
| 742 if (usage_url_.empty()) { | 818 if (usage_url_.empty()) { |
| 743 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: no usage url"; | 819 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: no usage url"; |
| 744 return false; | 820 return false; |
| 745 } | 821 } |
| 746 if (ServiceManager::IsOfflineConnectivityState( | 822 if (ServiceManager::IsOfflineConnectivityState( |
| 747 parent_->GetConnectivityState())) { | 823 parent_->GetConnectivityState())) { |
| 748 DLOG(INFO) << path_ | 824 DLOG(INFO) << path_ |
| 749 << ": ShouldSendUsageRequests: no: flimflam is offline"; | 825 << ": ShouldSendUsageRequests: no: flimflam is offline"; |
| 750 return false; | 826 return false; |
| 751 } | 827 } |
| 752 if (policy_->UsageRequestsMustBeSentOTA()) { | 828 if (!IsConnected()) { |
| 753 if (!IsConnected()) { | 829 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: not connected"; |
| 754 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: " | 830 return false; |
| 755 << "ota-only policy and not connected"; | 831 } |
| 756 return false; | 832 if (!IsDefaultService()) { |
| 757 } | 833 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: not default service"; |
| 758 if (!IsDefaultService()) { | 834 return false; |
| 759 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: no: " | 835 } |
| 760 << "ota-only policy and not default service"; | 836 if (device_->ByteCounterRunning()) { |
| 761 return false; | 837 DLOG(INFO) << path_ |
| 762 } | 838 << ": ShouldSendUsageRequests: no: local byte counter is running"; |
| 839 return false; |
| 763 } | 840 } |
| 764 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: yes"; | 841 DLOG(INFO) << path_ << ": ShouldSendUsageRequests: yes"; |
| 765 return true; | 842 return true; |
| 766 } | 843 } |
| 767 | 844 |
| 768 void Service::StopSendingUsageRequests() { | 845 void Service::StopSendingUsageRequests() { |
| 769 DLOG(INFO) << path_ << ": StopSendingUsageRequests"; | 846 DLOG(INFO) << path_ << ": StopSendingUsageRequests"; |
| 770 DestroyUpdateTimer(); | 847 DestroyUpdateTimer(); |
| 771 CancelPendingRequests(); | 848 CancelPendingRequests(); |
| 772 } | 849 } |
| 773 | 850 |
| 774 void Service::StartSendingUsageRequests() { | 851 void Service::StartSendingUsageRequests() { |
| 775 DLOG(INFO) << path_ << ": StartSendingUsageRequests"; | 852 DLOG(INFO) << path_ << ": StartSendingUsageRequests"; |
| 776 DCHECK(!IsSendingUsageRequests()); | 853 DCHECK(!IsSendingUsageRequests()); |
| 777 RequestUsageUpdate(); | 854 RequestUsageUpdate(); |
| 778 CreateUpdateTimer(); | 855 CreateUpdateTimer(); |
| 779 } | 856 } |
| 780 | 857 |
| 781 void Service::ReconsiderSendingUsageRequests() { | 858 void Service::ReconsiderSendingUsageRequests() { |
| 782 DLOG(INFO) << path_ << ": ReconsiderSendingUsageRequests"; | 859 DLOG(INFO) << path_ << ": ReconsiderSendingUsageRequests"; |
| 783 if (!IsSendingUsageRequests() && ShouldSendUsageRequests()) { | 860 if (!IsSendingUsageRequests() && ShouldSendUsageRequests()) { |
| 784 StartSendingUsageRequests(); | 861 StartSendingUsageRequests(); |
| 785 } else if (IsSendingUsageRequests() && !ShouldSendUsageRequests()) { | 862 } else if (IsSendingUsageRequests() && !ShouldSendUsageRequests()) { |
| 786 StopSendingUsageRequests(); | 863 StopSendingUsageRequests(); |
| 787 } | 864 } |
| 788 } | 865 } |
| 789 | 866 |
| 867 void Service::MaybeEmitDataPlansUpdate() { |
| 868 DCHECK(policy_ != NULL); |
| 869 if (policy_->ShouldEmitDataPlansUpdate(data_plans_)) { |
| 870 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: sending update"; |
| 871 parent_->EmitDataPlansUpdate(*this); |
| 872 } else { |
| 873 DLOG(INFO) << path_ << ": MaybeEmitDataPlansUpdate: not sending update"; |
| 874 } |
| 875 } |
| 876 |
| 790 } // namespace cashew | 877 } // namespace cashew |
| OLD | NEW |