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

Side by Side Diff: src/data_plan.h

Issue 5180003: cashew: add local byte counters (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Address jglasgow and zelidrag (offline) code review comments 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 | « src/byte_counter.cc ('k') | src/data_plan.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 #ifndef SRC_DATA_PLAN_H_ 5 #ifndef SRC_DATA_PLAN_H_
6 #define SRC_DATA_PLAN_H_ 6 #define SRC_DATA_PLAN_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include <base/basictypes.h> // NOLINT 12 #include <base/basictypes.h> // NOLINT
13 #include <base/time.h> // NOLINT 13 #include <base/time.h> // NOLINT
14 #include <dbus-c++/dbus.h> // NOLINT 14 #include <dbus-c++/dbus.h> // NOLINT
15 15
16 #include "src/values.h" 16 #include "src/values.h"
17 17
18 namespace cashew { 18 namespace cashew {
19 19
20 class DataPlan; 20 class DataPlan;
21 class Policy; 21 class Policy;
22 22
23 // byte count 23 // byte count
24 // TODO(vlaviano): this should be a uint64, but libcros/Chrome expects this 24 // TODO(vlaviano): this should be a uint64, but libcros/Chrome expects this
25 typedef int64 Bytes; 25 typedef int64 Bytes;
26 26
27 // List of DataPlan objects 27 // List of DataPlan objects
28 // TODO(vlaviano): consider promoting this from a typedef to a class
28 typedef std::vector<DataPlan*> DataPlanList; 29 typedef std::vector<DataPlan*> DataPlanList;
29 30
30 // DataPlan object formatted for D-Bus (using DBus::Variants to wrap fields) 31 // DataPlan object formatted for D-Bus (using DBus::Variants to wrap fields)
31 typedef std::map<std::string, DBus::Variant> DBusDataPlan; 32 typedef std::map<std::string, DBus::Variant> DBusDataPlan;
32 33
33 // List of DataPlan objects formatted for D-Bus 34 // List of DataPlan objects formatted for D-Bus
34 typedef std::vector<DBusDataPlan> DBusDataPlanList; 35 typedef std::vector<DBusDataPlan> DBusDataPlanList;
35 36
36 // Represents a data plan associated with a cellular service 37 // Represents a data plan associated with a cellular service
37 class DataPlan { 38 class DataPlan {
38 public: 39 public:
39 // valid type values for this plan 40 // valid type values for this plan
40 typedef enum { 41 typedef enum {
41 kTypeUnlimited = 0, 42 kTypeUnlimited = 0,
42 kTypeMeteredFree, 43 kTypeMeteredFree,
43 kTypeMeteredPaid, 44 kTypeMeteredPaid,
44 } Type; 45 } Type;
45 46
47 // |data_bytes_max| must be set to 0 for unlimited plans
46 DataPlan(const std::string& name, DataPlan::Type type, 48 DataPlan(const std::string& name, DataPlan::Type type,
47 base::Time update_time, base::Time start_time, 49 base::Time update_time, base::Time start_time,
48 base::Time end_time, Bytes data_bytes_max, Bytes data_bytes_used); 50 base::Time end_time, Bytes data_bytes_max, Bytes data_bytes_used);
49 virtual ~DataPlan(); 51 virtual ~DataPlan();
50 52
51 // get plan name 53 // get plan name
52 virtual const std::string& GetName() const; 54 virtual const std::string& GetName() const;
53 55
54 // get plan type 56 // get plan type
55 virtual Type GetType() const; 57 virtual Type GetType() const;
56 58
57 // get last update time 59 // get last update time
58 virtual base::Time GetUpdateTime() const; 60 virtual base::Time GetUpdateTime() const;
59 61
60 // get plan start time 62 // get plan start time
61 virtual base::Time GetStartTime() const; 63 virtual base::Time GetStartTime() const;
62 64
63 // get plan end time 65 // get plan end time
64 virtual base::Time GetEndTime() const; 66 virtual base::Time GetEndTime() const;
65 67
66 // get plan max bytes 68 // get plan max bytes
67 virtual Bytes GetDataBytesMax() const; 69 virtual Bytes GetDataBytesMax() const;
68 70
69 // get plan used bytes 71 // get plan used bytes
70 virtual Bytes GetDataBytesUsed() const; 72 virtual Bytes GetDataBytesUsed() const;
71 73
74 // get local used bytes
75 virtual Bytes GetLocalBytesUsed() const;
76
77 // set local used bytes
78 // must be >= 0
79 virtual void SetLocalBytesUsed(Bytes local_bytes_used);
80
81 // is this an active plan?
82 // we define active to mean that the plan is current and not exhausted
83 virtual bool IsActive() const;
84
72 // return a{sv} representation for D-Bus 85 // return a{sv} representation for D-Bus
73 virtual DBusDataPlan ToDBusFormat() const; 86 virtual DBusDataPlan ToDBusFormat() const;
74 87
75 // construct DataPlan from DictionaryValue 88 // construct DataPlan from DictionaryValue
76 static DataPlan* FromDictionaryValue(const DictionaryValue *value, 89 static DataPlan* FromDictionaryValue(const DictionaryValue *value,
77 const Policy *policy); 90 const Policy *policy);
78 91
79 // convert ISO 8601 time value to base::Time 92 // convert ISO 8601 time value to base::Time
80 // returns true on success and false on failure 93 // returns true on success and false on failure
81 // |time_out| must not be NULL and is set on a successful return 94 // |time_out| must not be NULL and is set on a successful return
82 static bool TimeFromIso8601(const std::string& time_8601, 95 static bool TimeFromIso8601(const std::string& time_8601,
83 base::Time *time_out, 96 base::Time *time_out,
84 bool zoneless_strings_are_local); 97 bool zoneless_strings_are_local);
85 98
99 // returns first active plan in |data_plans|
100 // returns NULL if list is empty or contains no active plans
101 static DataPlan* GetActivePlan(const DataPlanList& data_plans);
102
86 private: 103 private:
87 // human-readable plan name 104 // human-readable plan name
88 const std::string name_; 105 const std::string name_;
89 106
90 // plan type 107 // plan type
91 const Type type_; 108 const Type type_;
92 109
93 // last update time (i.e., how fresh is plan data) 110 // last update time (i.e., how fresh is plan data)
111 // this refers to carrier API data, not local measurements
94 base::Time update_time_; 112 base::Time update_time_;
95 113
96 // plan start time 114 // plan start time
97 const base::Time start_time_; 115 const base::Time start_time_;
98 116
99 // plan end time 117 // plan end time
100 const base::Time end_time_; 118 const base::Time end_time_;
101 119
102 // max bytes available during plan period 120 // max bytes available during plan period
103 // irrelevant for plans of type kTypeUnlimited 121 // irrelevant for plans of type kTypeUnlimited
104 const Bytes data_bytes_max_; 122 const Bytes data_bytes_max_;
105 123
106 // bytes consumed so far during plan period 124 // bytes consumed so far during plan period
125 // this measurement comes from the carrier API
107 Bytes data_bytes_used_; 126 Bytes data_bytes_used_;
108 127
128 // local measurement of bytes used since we received |data_bytes_used_|
129 // baseline from the carrier API
130 Bytes local_bytes_used_;
131
109 // convert plan type enum value to string formatted for libcros 132 // convert plan type enum value to string formatted for libcros
110 const char* TypeToLibcrosString(Type type) const; 133 const char* TypeToLibcrosString(Type type) const;
111 134
112 // convert string formatted for Cros Usage API to plan type enum value 135 // convert string formatted for Cros Usage API to plan type enum value
113 // returns true on success and false on failure 136 // returns true on success and false on failure
114 // |type_out| must not be NULL and is set on a successful return 137 // |type_out| must not be NULL and is set on a successful return
115 static bool CrosUsageStringToType(const std::string& type_string, 138 static bool CrosUsageStringToType(const std::string& type_string,
116 Type *type_out); 139 Type *type_out);
117 140
118 // converts the value associated with |key| in |dict| to an int64 141 // converts the value associated with |key| in |dict| to an int64
119 // returns true on success and false on failure 142 // returns true on success and false on failure
120 // |out_value| must not be NULL and is set on a successful return 143 // |out_value| must not be NULL and is set on a successful return
121 static bool GetInt64FromDictionary(const DictionaryValue& dict, 144 static bool GetInt64FromDictionary(const DictionaryValue& dict,
122 const std::string& key, 145 const std::string& key,
123 int64* out_value); 146 int64* out_value);
124 147
125 DISALLOW_COPY_AND_ASSIGN(DataPlan); 148 DISALLOW_COPY_AND_ASSIGN(DataPlan);
126 }; 149 };
127 150
128 } // namespace cashew 151 } // namespace cashew
129 152
130 #endif // SRC_DATA_PLAN_H_ 153 #endif // SRC_DATA_PLAN_H_
OLDNEW
« no previous file with comments | « src/byte_counter.cc ('k') | src/data_plan.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698