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

Side by Side Diff: src/service.cc

Issue 3797006: cashew: support additional usage API error result strings (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: Created 10 years, 2 months 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 | « src/service.h ('k') | no next file » | 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/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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static const char *kCrosUsageRestrictedProperty = "restricted"; 46 static const char *kCrosUsageRestrictedProperty = "restricted";
47 static const char *kCrosUsagePlansProperty = "plans"; 47 static const char *kCrosUsagePlansProperty = "plans";
48 48
49 // Chromium OS Usage API version values 49 // Chromium OS Usage API version values
50 static const int kCrosUsageVersionMinSupported = 1; 50 static const int kCrosUsageVersionMinSupported = 1;
51 static const int kCrosUsageVersionMaxSupported = 1; 51 static const int kCrosUsageVersionMaxSupported = 1;
52 52
53 // Chromium OS Usage API status values 53 // Chromium OS Usage API status values
54 static const char *kCrosUsageStatusOk = "OK"; 54 static const char *kCrosUsageStatusOk = "OK";
55 static const char *kCrosUsageStatusError = "ERROR"; 55 static const char *kCrosUsageStatusError = "ERROR";
56 static const char *kCrosUsageStatusMalformedRequest = "MALFORMED REQUEST";
57 static const char *kCrosUsageStatusInternalError = "INTERNAL ERROR";
58 static const char *kCrosUsageStatusServiceUnavailable = "SERVICE UNAVAILABLE";
59 static const char *kCrosUsageStatusRequestRefused = "REQUEST REFUSED";
60 static const char *kCrosUsageStatusUnknownDevice = "UNKNOWN DEVICE";
Eric Shienbrood 2010/10/15 18:43:18 If you add a new status, you have to modify IsVali
Vince Laviano 2010/10/15 20:25:12 This is a good point. Composing a rambling reply
56 61
57 Service::Service(ServiceManager * const parent, 62 Service::Service(ServiceManager * const parent,
58 DBus::Connection& connection, // NOLINT 63 DBus::Connection& connection, // NOLINT
59 const DBus::Path& path) 64 const DBus::Path& path)
60 : DBus::ObjectProxy(connection, path, kFlimflamServiceName), 65 : DBus::ObjectProxy(connection, path, kFlimflamServiceName),
61 parent_(CHECK_NOTNULL(parent)), connection_(connection), path_(path), 66 parent_(CHECK_NOTNULL(parent)), connection_(connection), path_(path),
62 state_(kStateUnknown), type_(kTypeUnknown), device_(NULL), 67 state_(kStateUnknown), type_(kTypeUnknown), device_(NULL),
63 provider_(NULL), request_in_progress_(false), 68 provider_(NULL), request_in_progress_(false),
64 update_timeout_source_(NULL), policy_(NULL) { 69 update_timeout_source_(NULL), policy_(NULL) {
65 // init our state with a GetProperties() call to our Flimflam service path 70 // init our state with a GetProperties() call to our Flimflam service path
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 << ", " << kCrosUsageVersionMaxSupported << "]"; 215 << ", " << kCrosUsageVersionMaxSupported << "]";
211 return; 216 return;
212 } 217 }
213 218
214 std::string status; 219 std::string status;
215 if (!root->GetString(kCrosUsageStatusProperty, &status)) { 220 if (!root->GetString(kCrosUsageStatusProperty, &status)) {
216 LOG(WARNING) << path_ << ": OnRequestComplete: no status property"; 221 LOG(WARNING) << path_ << ": OnRequestComplete: no status property";
217 return; 222 return;
218 } 223 }
219 DLOG(INFO) << path_ << ": OnRequestComplete: status = " << status; 224 DLOG(INFO) << path_ << ": OnRequestComplete: status = " << status;
220 if (status != kCrosUsageStatusOk && status != kCrosUsageStatusError) { 225 if (!IsValidCrosUsageStatus(status)) {
221 LOG(WARNING) << path_ << ": OnRequestComplete: invalid status: " << status; 226 LOG(WARNING) << path_ << ": OnRequestComplete: invalid status: " << status;
222 return; 227 return;
223 } 228 }
224 if (status == kCrosUsageStatusError) { 229 if (status != kCrosUsageStatusOk) {
225 LOG(WARNING) << path_ << ": OnRequestComplete: status: " << status; 230 LOG(WARNING) << path_ << ": OnRequestComplete: status: " << status;
231 OnCrosUsageErrorResult(status);
226 return; 232 return;
227 } 233 }
228 234
229 bool restricted = false; 235 bool restricted = false;
230 if (root->GetBoolean(kCrosUsageRestrictedProperty, &restricted)) { 236 if (root->GetBoolean(kCrosUsageRestrictedProperty, &restricted)) {
231 DLOG(INFO) << path_ << ": OnRequestComplete: restricted = " << restricted; 237 DLOG(INFO) << path_ << ": OnRequestComplete: restricted = " << restricted;
232 } else { 238 } else {
233 DLOG(INFO) << path_ << ": OnRequestComplete: no restricted property"; 239 DLOG(INFO) << path_ << ": OnRequestComplete: no restricted property";
234 // restricted property is optional 240 // restricted property is optional
235 } 241 }
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 568 }
563 DestroyUpdateTimer(); 569 DestroyUpdateTimer();
564 CancelPendingRequests(); 570 CancelPendingRequests();
565 if (provider_ != NULL) { 571 if (provider_ != NULL) {
566 DLOG(INFO) << path_ << ": DeleteCarrierState: deleting data plan provider"; 572 DLOG(INFO) << path_ << ": DeleteCarrierState: deleting data plan provider";
567 delete provider_; 573 delete provider_;
568 provider_ = NULL; 574 provider_ = NULL;
569 } 575 }
570 } 576 }
571 577
578 bool Service::IsValidCrosUsageStatus(const std::string& status) const {
579 if (status == kCrosUsageStatusOk ||
580 status == kCrosUsageStatusError ||
581 status == kCrosUsageStatusMalformedRequest ||
582 status == kCrosUsageStatusInternalError ||
583 status == kCrosUsageStatusServiceUnavailable ||
584 status == kCrosUsageStatusRequestRefused ||
585 status == kCrosUsageStatusUnknownDevice) {
586 return true;
587 }
588 return false;
589 }
590
591 void Service::OnCrosUsageErrorResult(const std::string& status) {
592 DLOG(WARNING) << path_ << ": OnCrosUsageErrorResult: " << status;
593 // TODO(vlaviano): take action based on which specific error status string
594 // we've received (e.g., we could adjust the update timer interval, or
595 // disable the timer entirely).
596 }
597
572 } // namespace cashew 598 } // namespace cashew
OLDNEW
« no previous file with comments | « src/service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698