blob: 92976183de6273e0e133a8a0aaf350791baeb84a [file] [log] [blame]
Arman Uguray2717a102013-01-29 23:36:06 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chan19f83972012-10-03 23:25:56 -07005#ifndef SHILL_SERVICE_H_
6#define SHILL_SERVICE_H_
Paul Stewart75897df2011-04-27 09:05:53 -07007
mukesh agrawal568b5c62012-02-28 14:44:47 -08008#include <time.h>
9
Darin Petkov385b9bc2012-12-03 15:25:05 +010010#include <deque>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070011#include <map>
Paul Stewartcb59fed2012-03-21 21:14:46 -070012#include <set>
Darin Petkov385b9bc2012-12-03 15:25:05 +010013#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070014#include <vector>
Chris Masone9be4a9d2011-05-16 15:44:09 -070015
Christopher Wiley0801d192012-09-24 11:57:15 -070016#include <base/cancelable_callback.h>
Chris Masone9be4a9d2011-05-16 15:44:09 -070017#include <base/memory/ref_counted.h>
Paul Stewartba41b992011-05-26 07:02:46 -070018#include <base/memory/scoped_ptr.h>
Christopher Wiley0801d192012-09-24 11:57:15 -070019#include <base/memory/weak_ptr.h>
Darin Petkovba40dd32011-07-11 20:06:39 -070020#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewart75897df2011-04-27 09:05:53 -070021
Eric Shienbrood9a245532012-03-07 14:20:39 -050022#include "shill/adaptor_interfaces.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070023#include "shill/accessor_interface.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050024#include "shill/callbacks.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070025#include "shill/property_store.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070026#include "shill/refptr_types.h"
Darin Petkov0c65bdd2012-12-05 13:42:41 +010027#include "shill/shill_time.h"
Paul Stewart1062d9d2012-04-27 10:42:27 -070028#include "shill/static_ip_parameters.h"
Paul Stewart22aa71b2011-09-16 12:15:11 -070029#include "shill/technology.h"
Chris Masonec1e50412011-06-07 13:04:53 -070030
Thieu Leb84ba342012-03-02 15:15:19 -080031namespace chromeos_metrics {
32class Timer;
33}
34
Paul Stewart75897df2011-04-27 09:05:53 -070035namespace shill {
36
Chris Masone9be4a9d2011-05-16 15:44:09 -070037class ControlInterface;
Darin Petkov385b9bc2012-12-03 15:25:05 +010038class DiagnosticsReporter;
Paul Stewartc43cbbe2013-04-11 06:29:30 -070039class EapCredentials;
Paul Stewart75897df2011-04-27 09:05:53 -070040class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070041class Error;
Chris Masone9be4a9d2011-05-16 15:44:09 -070042class EventDispatcher;
Paul Stewartbe5f5b32011-12-07 17:11:11 -080043class HTTPProxy;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070044class KeyValueStore;
Chris Masone6791a432011-07-12 13:23:19 -070045class Manager;
Thieu Le48e6d6d2011-12-06 00:40:27 +000046class Metrics;
mukesh agrawalbebf1b82013-04-23 15:06:33 -070047class MockManager;
Chris Masone9be4a9d2011-05-16 15:44:09 -070048class ServiceAdaptorInterface;
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070049class ServiceMockAdaptor;
Darin Petkov5eb05422012-05-11 15:45:25 +020050class Sockets;
Darin Petkovba40dd32011-07-11 20:06:39 -070051class StoreInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070052
Chris Masone7aa5f902011-07-11 11:13:35 -070053// A Service is a uniquely named entity, which the system can
54// connect in order to begin sending and receiving network traffic.
55// All Services are bound to an Entry, which represents the persistable
56// state of the Service. If the Entry is populated at the time of Service
57// creation, that information is used to prime the Service. If not, the Entry
58// becomes populated over time.
Chris Masone27c4aa52011-07-02 13:10:14 -070059class Service : public base::RefCounted<Service> {
Paul Stewart75897df2011-04-27 09:05:53 -070060 public:
Darin Petkovba40dd32011-07-11 20:06:39 -070061 static const char kCheckPortalAuto[];
62 static const char kCheckPortalFalse[];
63 static const char kCheckPortalTrue[];
64
Darin Petkovaba89322013-03-11 14:48:22 +010065 static const char kErrorDetailsNone[];
66
Paul Stewart0756db92012-01-27 08:34:47 -080067 // TODO(pstew): Storage constants shouldn't need to be public
68 // crosbug.com/25813
69 static const char kStorageAutoConnect[];
70 static const char kStorageCheckPortal[];
Paul Stewart0756db92012-01-27 08:34:47 -080071 static const char kStorageError[];
72 static const char kStorageFavorite[];
73 static const char kStorageGUID[];
mukesh agrawalcf24a242012-05-21 16:46:11 -070074 static const char kStorageHasEverConnected[];
Paul Stewart0756db92012-01-27 08:34:47 -080075 static const char kStorageName[];
76 static const char kStoragePriority[];
77 static const char kStorageProxyConfig[];
78 static const char kStorageSaveCredentials[];
79 static const char kStorageType[];
80 static const char kStorageUIData[];
81
mukesh agrawal8f3f7752012-02-17 19:42:09 -080082 static const uint8 kStrengthMax;
83 static const uint8 kStrengthMin;
84
Paul Stewart75897df2011-04-27 09:05:53 -070085 enum ConnectFailure {
Paul Stewart03dba0b2011-08-22 16:32:45 -070086 kFailureUnknown,
Paul Stewartf2d60912012-07-15 08:37:30 -070087 kFailureAAA,
Darin Petkov1c049c72013-03-21 13:15:45 +010088 kFailureActivation,
89 kFailureBadPassphrase,
Paul Stewartf2d60912012-07-15 08:37:30 -070090 kFailureBadWEPKey,
91 kFailureConnect,
Darin Petkov1c049c72013-03-21 13:15:45 +010092 kFailureDHCP,
Paul Stewartf2d60912012-07-15 08:37:30 -070093 kFailureDNSLookup,
Paul Stewartdb0f9172012-11-30 16:48:09 -080094 kFailureEAPAuthentication,
95 kFailureEAPLocalTLS,
96 kFailureEAPRemoteTLS,
Darin Petkov1c049c72013-03-21 13:15:45 +010097 kFailureHTTPGet,
98 kFailureIPSecCertAuth,
99 kFailureIPSecPSKAuth,
100 kFailureInternal,
101 kFailureNeedEVDO,
102 kFailureNeedHomeNetwork,
103 kFailureOTASP,
104 kFailureOutOfRange,
105 kFailurePPPAuth,
106 kFailurePinMissing,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000107 kFailureMax
Paul Stewart75897df2011-04-27 09:05:53 -0700108 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700109 enum ConnectState {
Paul Stewart03dba0b2011-08-22 16:32:45 -0700110 kStateUnknown,
111 kStateIdle,
112 kStateAssociating,
113 kStateConfiguring,
114 kStateConnected,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000115 kStatePortal,
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800116 kStateFailure,
117 kStateOnline
Chris Masone9be4a9d2011-05-16 15:44:09 -0700118 };
mukesh agrawal43970a22013-02-15 16:00:07 -0800119 enum CryptoAlgorithm {
120 kCryptoNone,
121 kCryptoRc4,
122 kCryptoAes
123 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700124
Paul Stewartac4ac002011-08-26 12:04:26 -0700125 static const int kPriorityNone;
126
Chris Masone9be4a9d2011-05-16 15:44:09 -0700127 // A constructor for the Service object
128 Service(ControlInterface *control_interface,
129 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -0800130 Metrics *metrics,
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700131 Manager *manager,
Gaurav Shah435de2c2011-11-17 19:01:07 -0800132 Technology::Identifier technology);
Darin Petkovba40dd32011-07-11 20:06:39 -0700133
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000134 // AutoConnect MAY choose to ignore the connection request in some
135 // cases. For example, if the corresponding Device only supports one
136 // concurrent connection, and another Service is already connected
137 // or connecting.
138 //
139 // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT
140 // be called from a D-Bus signal handler context.
141 virtual void AutoConnect();
mukesh agrawaldc7b8442012-09-27 13:48:14 -0700142 // Queue up a connection attempt. Derived classes SHOULD call the
143 // base class implementation before beginning a connect. The base
144 // class will log the connection attempt, and update base-class
145 // state.
146 virtual void Connect(Error *error, const char *reason);
Christopher Wileyabd3b502012-09-26 13:08:52 -0700147 // Disconnect this service. Override this method to add your service specific
148 // disconnect logic, but call the super class's Disconnect() first.
mukesh agrawaladb68482012-01-17 16:31:51 -0800149 virtual void Disconnect(Error *error);
Christopher Wileyabd3b502012-09-26 13:08:52 -0700150 // Disconnects this service via Disconnect(). Marks the service as having
151 // failed with |failure|. Do not override this method.
152 virtual void DisconnectWithFailure(ConnectFailure failure, Error *error);
153 // Disconnects this service via Disconnect(). The service will not be eligible
154 // for auto-connect until a subsequent call to Connect, or Load. Do not
155 // override this method.
156 virtual void UserInitiatedDisconnect(Error *error);
Chris Masonea82b7112011-05-25 15:16:29 -0700157
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500158 // The default implementation returns the error kInvalidArguments.
159 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500160 Error *error,
161 const ResultCallback &callback);
Ben Chan5d924542013-02-14 17:49:08 -0800162 // The default implementation returns the error kNotSupported.
163 virtual void CompleteCellularActivation(Error *error);
Darin Petkovc408e692011-08-17 13:47:15 -0700164
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800165 virtual bool IsActive(Error *error);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700166
Paul Stewart7fb09382012-07-18 17:32:27 -0700167 // Returns whether services of this type should be auto-connect by default.
168 virtual bool IsAutoConnectByDefault() const { return false; }
169
Paul Stewart03dba0b2011-08-22 16:32:45 -0700170 virtual ConnectState state() const { return state_; }
171 // Updates the state of the Service and alerts the manager. Also
172 // clears |failure_| if the new state isn't a failure.
173 virtual void SetState(ConnectState state);
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200174 std::string GetStateString() const;
Paul Stewart03dba0b2011-08-22 16:32:45 -0700175
Paul Stewart22aa71b2011-09-16 12:15:11 -0700176 // State utility functions
Darin Petkovc8d91e52013-01-21 11:43:47 +0100177 static bool IsConnectedState(ConnectState state);
178 static bool IsConnectingState(ConnectState state);
179
180 virtual bool IsConnected() const;
181 virtual bool IsConnecting() const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000182 virtual bool IsFailed() const {
mukesh agrawal568b5c62012-02-28 14:44:47 -0800183 // We sometimes lie about the failure state, to keep Chrome happy
184 // (see comment in WiFi::HandleDisconnect). Hence, we check both
185 // state and |failed_time_|.
186 return state() == kStateFailure || failed_time_ > 0;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000187 }
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800188
189 // Returns true if the connection for |this| depends on service |b|.
190 virtual bool IsDependentOn(const ServiceRefPtr &b) const;
191
Paul Stewarta121c442012-06-09 14:12:58 -0700192 virtual bool IsPortalled() const {
193 return state() == kStatePortal;
194 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700195
Paul Stewart03dba0b2011-08-22 16:32:45 -0700196 virtual ConnectFailure failure() const { return failure_; }
mukesh agrawal568b5c62012-02-28 14:44:47 -0800197 // Records the failure mode and time. Sets the Service state to "Failure".
Paul Stewart03dba0b2011-08-22 16:32:45 -0700198 virtual void SetFailure(ConnectFailure failure);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800199 // Records the failure mode and time. Sets the Service state to "Idle".
200 // Avoids showing a failure mole in the UI.
201 virtual void SetFailureSilent(ConnectFailure failure);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700202
Darin Petkovba40dd32011-07-11 20:06:39 -0700203 // Returns a string that is guaranteed to uniquely identify this Service
204 // instance.
Darin Petkov457728b2013-01-09 09:49:08 +0100205 const std::string &unique_name() const { return unique_name_; }
Darin Petkovafa6fc42011-06-21 16:21:08 -0700206
Chris Masone6791a432011-07-12 13:23:19 -0700207 virtual std::string GetRpcIdentifier() const;
Chris Masone3c3f6a12011-07-01 10:01:41 -0700208
Darin Petkovba40dd32011-07-11 20:06:39 -0700209 // Returns the unique persistent storage identifier for the service.
Chris Masone6515aab2011-10-12 16:19:09 -0700210 virtual std::string GetStorageIdentifier() const = 0;
Darin Petkovba40dd32011-07-11 20:06:39 -0700211
Paul Stewarte7de2942013-04-25 17:07:31 -0700212 // Returns the identifier within |storage| from which configuration for
213 // this service can be loaded. Returns an empty string if no entry in
214 // |storage| can be used.
215 virtual std::string GetLoadableStorageIdentifier(
216 const StoreInterface &storage) const;
217
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700218 // Returns whether the service configuration can be loaded from |storage|.
Paul Stewarte7de2942013-04-25 17:07:31 -0700219 virtual bool IsLoadableFrom(const StoreInterface &storage) const;
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700220
Paul Stewart81426132012-05-16 10:05:10 -0700221 // Returns true if the service uses 802.1x for key management.
Paul Stewartbe9abfd2013-04-22 12:18:48 -0700222 virtual bool Is8021x() const { return false; }
Paul Stewart81426132012-05-16 10:05:10 -0700223
Darin Petkovba40dd32011-07-11 20:06:39 -0700224 // Loads the service from persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700225 virtual bool Load(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700226
Paul Stewarta41e38d2011-11-11 07:47:29 -0800227 // Indicate to service that it is no longer persisted to storage. It
Paul Stewart65512e12012-03-26 18:01:08 -0700228 // should purge any stored profile state (e.g., credentials). Returns
229 // true to indicate that this service should also be unregistered from
230 // the manager, false otherwise.
231 virtual bool Unload();
Paul Stewarta41e38d2011-11-11 07:47:29 -0800232
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800233 // Attempt to remove the service. On failure, no changes in state will occur.
234 virtual void Remove(Error *error);
235
Darin Petkovba40dd32011-07-11 20:06:39 -0700236 // Saves the service to persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700237 virtual bool Save(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700238
Thieu Led4e9e552012-02-16 16:26:07 -0800239 // Saves the service to the current profile.
Gary Moraind93615e2012-04-27 11:50:03 -0700240 virtual void SaveToCurrentProfile();
Thieu Led4e9e552012-02-16 16:26:07 -0800241
Paul Stewartcb59fed2012-03-21 21:14:46 -0700242 // Applies all the properties in |args| to this service object's mutable
243 // store, except for those in parameters_ignored_for_configure_.
244 // Returns an error in |error| if one or more parameter set attempts
245 // fails, but will only return the first error.
246 virtual void Configure(const KeyValueStore &args, Error *error);
247
Paul Stewart7a20aa42013-01-17 12:21:41 -0800248 // Iterate over all the properties in |args| and test for an identical
249 // value in this service object's store. Returns false if one or more
250 // keys in |args| do not exist or have different values, true otherwise.
251 virtual bool DoPropertiesMatch(const KeyValueStore &args) const;
252
Paul Stewartd215af62012-04-24 23:25:50 -0700253 // Returns whether portal detection is explicitly disabled on this service
254 // via a property set on it.
255 virtual bool IsPortalDetectionDisabled() const;
256
257 // Returns whether portal detection is set to follow the default setting
258 // of this service's technology via a property set on it.
259 virtual bool IsPortalDetectionAuto() const;
260
Paul Stewart10ccbb32012-04-26 15:59:30 -0700261 // Returns true if the service is persisted to a non-ephemeral profile.
262 virtual bool IsRemembered() const;
263
Paul Stewarta41e38d2011-11-11 07:47:29 -0800264 // Returns true if the service RPC identifier should be part of the
265 // manager's advertised services list, false otherwise.
266 virtual bool IsVisible() const { return true; }
267
Paul Stewart20088d82012-02-16 06:58:55 -0800268 // Returns true if there is a proxy configuration set on this service.
269 virtual bool HasProxyConfig() const { return !proxy_config_.empty(); }
270
Paul Stewarta47c3c62012-12-18 12:14:29 -0800271 // Returns whether this service has had recent connection issues.
272 virtual bool HasRecentConnectionIssues();
273
mukesh agrawal00917ce2011-11-22 23:56:55 +0000274 virtual void MakeFavorite();
275
Darin Petkov5eb05422012-05-11 15:45:25 +0200276 // Set the connection for this service. If the connection is non-NULL, create
277 // an HTTP Proxy that will utilize this service's connection to serve
278 // requests.
279 virtual void SetConnection(const ConnectionRefPtr &connection);
280 virtual const ConnectionRefPtr &connection() const { return connection_; }
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800281
Gaurav Shah10109f22011-11-11 20:16:22 -0800282 // Examines the EAP credentials for the service and returns true if a
283 // connection attempt can be made.
Paul Stewart9413bcc2013-04-04 16:12:43 -0700284 virtual bool Is8021xConnectable() const;
Gaurav Shah10109f22011-11-11 20:16:22 -0800285
Paul Stewartbc6e7392012-05-24 07:07:48 -0700286 // Add an EAP certification id |name| at position |depth| in the stack.
287 // Returns true if entry was added, false otherwise.
288 virtual bool AddEAPCertification(const std::string &name, size_t depth);
289 // Clear all EAP certification elements.
Paul Stewart9413bcc2013-04-04 16:12:43 -0700290 virtual void ClearEAPCertification();
Paul Stewartbc6e7392012-05-24 07:07:48 -0700291
Thieu Le48e6d6d2011-12-06 00:40:27 +0000292 // The inherited class should register any custom metrics in this method.
293 virtual void InitializeCustomMetrics() const {}
294
295 // The inherited class that needs to send metrics after the service has
Thieu Leb84ba342012-03-02 15:15:19 -0800296 // transitioned to the ready state should override this method.
297 // |time_resume_to_ready_milliseconds| holds the elapsed time from when
298 // the system was resumed until when the service transitioned to the
299 // connected state. This value is non-zero for the first service transition
300 // to the connected state after a resume.
301 virtual void SendPostReadyStateMetrics(
302 int64 /*time_resume_to_ready_milliseconds*/) const {}
Thieu Le48e6d6d2011-12-06 00:40:27 +0000303
Darin Petkovafa6fc42011-06-21 16:21:08 -0700304 bool auto_connect() const { return auto_connect_; }
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700305 void SetAutoConnect(bool connect);
Paul Stewart75897df2011-04-27 09:05:53 -0700306
Gaurav Shah435de2c2011-11-17 19:01:07 -0800307 bool connectable() const { return connectable_; }
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700308 // Sets the connectable property of the service, and broadcast the
309 // new value. Does not update the manager.
310 // TODO(petkov): Remove this method in favor of SetConnectableFull.
Darin Petkovb2ba39f2012-06-06 10:33:43 +0200311 void SetConnectable(bool connectable);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700312 // Sets the connectable property of the service, broadcasts the new
313 // value, and alerts the manager if necessary.
314 void SetConnectableFull(bool connectable);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800315
Thieu Le67370f62012-02-14 23:01:42 +0000316 virtual bool explicitly_disconnected() const {
317 return explicitly_disconnected_;
318 }
319
Paul Stewart22aa71b2011-09-16 12:15:11 -0700320 bool favorite() const { return favorite_; }
mukesh agrawal00917ce2011-11-22 23:56:55 +0000321 // Setter is deliberately omitted; use MakeFavorite.
Paul Stewart22aa71b2011-09-16 12:15:11 -0700322
Darin Petkov7f060332012-03-14 11:46:47 +0100323 void set_friendly_name(const std::string &n) { friendly_name_ = n; }
Darin Petkov9c6e9812013-03-26 13:49:07 +0100324 const std::string &friendly_name() const { return friendly_name_; }
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700325 // Sets the flimflam::kNameProperty and broadcasts the change.
326 void SetFriendlyName(const std::string &friendly_name);
mukesh agrawal15908392011-11-16 18:29:25 +0000327
Paul Stewart4c561612012-03-21 12:49:01 -0700328 const std::string &guid() const { return guid_; }
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700329 bool SetGuid(const std::string &guid, Error *error);
Paul Stewart4c561612012-03-21 12:49:01 -0700330
mukesh agrawalcf24a242012-05-21 16:46:11 -0700331 bool has_ever_connected() const { return has_ever_connected_; }
332
Paul Stewart22aa71b2011-09-16 12:15:11 -0700333 int32 priority() const { return priority_; }
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700334 bool SetPriority(const int32 &priority, Error *error);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700335
mukesh agrawal43970a22013-02-15 16:00:07 -0800336 size_t crypto_algorithm() const { return crypto_algorithm_; }
337 bool key_rotation() const { return key_rotation_; }
338 bool endpoint_auth() const { return endpoint_auth_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700339
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100340 void SetStrength(uint8 strength);
mukesh agrawale1d90e92012-02-15 17:36:08 -0800341
342 // uint8 streams out as a char. Coerce to a larger type, so that
343 // it prints as a number.
344 uint16 strength() const { return strength_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700345
Gaurav Shah435de2c2011-11-17 19:01:07 -0800346 virtual Technology::Identifier technology() const { return technology_; }
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200347 std::string GetTechnologyString() const;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800348
Paul Stewart35eff132013-04-12 12:08:40 -0700349 virtual const EapCredentials *eap() const { return eap_.get(); }
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700350 void SetEapCredentials(EapCredentials *eap);
Gaurav Shah10109f22011-11-11 20:16:22 -0800351
Darin Petkovcb715292012-04-25 13:04:37 +0200352 bool save_credentials() const { return save_credentials_; }
353 void set_save_credentials(bool save) { save_credentials_ = save; }
354
Darin Petkov51489002011-08-18 13:13:20 -0700355 const std::string &error() const { return error_; }
356 void set_error(const std::string &error) { error_ = error; }
357
Darin Petkovaba89322013-03-11 14:48:22 +0100358 const std::string &error_details() const { return error_details_; }
359 void SetErrorDetails(const std::string &details);
360
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800361 static const char *ConnectFailureToString(const ConnectFailure &state);
362 static const char *ConnectStateToString(const ConnectState &state);
363
Paul Stewart39db5ca2013-03-18 14:15:17 -0700364 // Compare two services. Returns true if Service |a| should be displayed
365 // above |b|. If |compare_connectivity_state| is true, the connectivity
366 // state of the service (service->state()) is used as the most significant
367 // criteria for comparsion, otherwise the service state is ignored. Use
368 // |tech_order| to rank services if more decisive criteria do not yield a
369 // difference. |reason| is populated with the exact criteria used for the
370 // ultimate comparison.
Paul Stewart22aa71b2011-09-16 12:15:11 -0700371 static bool Compare(ServiceRefPtr a,
372 ServiceRefPtr b,
Paul Stewart39db5ca2013-03-18 14:15:17 -0700373 bool compare_connectivity_state,
mukesh agrawalddc378f2012-02-17 18:26:20 -0800374 const std::vector<Technology::Identifier> &tech_order,
375 const char **reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700376
Chris Masone34af2182011-08-22 11:59:36 -0700377 // These are defined in service.cc so that we don't have to include profile.h
Chris Masone9d779932011-08-25 16:33:41 -0700378 // TODO(cmasone): right now, these are here only so that we can get the
379 // profile name as a property. Can we store just the name, and then handle
380 // setting the profile for this service via |manager_|?
Chris Masone6791a432011-07-12 13:23:19 -0700381 const ProfileRefPtr &profile() const;
Philipp Neubeck79173602012-11-13 21:10:09 +0100382
383 // Sets the profile property of this service. Broadcasts the new value if it's
384 // not NULL. If the new value is NULL, the service will either be set to
385 // another profile afterwards or it will not be visible and not monitored
386 // anymore.
387 void SetProfile(const ProfileRefPtr &p);
388
389 // This is called from tests and shouldn't be called otherwise. Use SetProfile
390 // instead.
Chris Masone6791a432011-07-12 13:23:19 -0700391 void set_profile(const ProfileRefPtr &p);
392
Paul Stewart4357f4e2012-04-26 17:39:26 -0700393 // Notification that occurs when a service now has profile data saved
394 // on its behalf. Some service types like WiFi can choose to register
395 // themselves at this point.
396 virtual void OnProfileConfigured() {}
397
Paul Stewartff14b022012-04-24 20:06:23 -0700398 // Notification that occurs when a single property has been changed via
399 // the RPC adaptor.
Paul Stewart81426132012-05-16 10:05:10 -0700400 virtual void OnPropertyChanged(const std::string &property);
Paul Stewartff14b022012-04-24 20:06:23 -0700401
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700402 // Notification that occurs when an EAP credential property has been
403 // changed. Some service subclasses can choose to respond to this
404 // event.
405 virtual void OnEapCredentialsChanged() {}
406
Christopher Wiley0801d192012-09-24 11:57:15 -0700407 // Called by the manager once after a resume.
408 virtual void OnAfterResume();
409
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700410 EapCredentials *mutable_eap() { return eap_.get(); }
411
mukesh agrawalde29fa82011-09-16 16:16:36 -0700412 PropertyStore *mutable_store() { return &store_; }
413 const PropertyStore &store() const { return store_; }
Paul Stewartdef189e2012-08-02 20:12:09 -0700414 StaticIPParameters *mutable_static_ip_parameters() {
415 return &static_ip_parameters_;
416 }
Paul Stewart1062d9d2012-04-27 10:42:27 -0700417 const StaticIPParameters &static_ip_parameters() const {
418 return static_ip_parameters_;
419 }
Chris Masone27c4aa52011-07-02 13:10:14 -0700420
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700421 // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is
422 // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the
423 // value is encrypted.
424 static void SaveString(StoreInterface *storage,
425 const std::string &id,
426 const std::string &key,
427 const std::string &value,
428 bool crypted,
429 bool save);
430
Paul Stewart967eaeb2013-04-25 19:53:07 -0700431 // Called via RPC to get a dict containing profile-to-entry_name mappings
432 // of all the profile entires which contain configuration applicable to
433 // this service.
434 std::map<std::string, std::string> GetLoadableProfileEntries();
435
mukesh agrawalb54601c2011-06-07 17:39:22 -0700436 protected:
Darin Petkov5eb05422012-05-11 15:45:25 +0200437 friend class base::RefCounted<Service>;
438
mukesh agrawal03c15ce2012-11-29 17:36:21 -0800439 static const char kAutoConnBusy[];
440
Darin Petkov5eb05422012-05-11 15:45:25 +0200441 virtual ~Service();
442
Chris Masone34af2182011-08-22 11:59:36 -0700443 // Returns true if a character is allowed to be in a service storage id.
444 static bool LegalChar(char a) { return isalnum(a) || a == '_'; }
445
Darin Petkov31332412012-01-28 01:50:02 +0100446 // Returns true if a character is disallowed to be in a service storage id.
447 static bool IllegalChar(char a) { return !LegalChar(a); }
448
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800449 virtual std::string CalculateState(Error *error);
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200450 std::string CalculateTechnology(Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700451
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000452 // Returns whether this service is in a state conducive to auto-connect.
453 // This should include any tests used for computing connectable(),
454 // as well as other critera such as whether the device associated with
455 // this service is busy with another connection.
mukesh agrawalbf14e942012-03-02 14:36:34 -0800456 //
457 // If the service is not auto-connectable, |*reason| will be set to
458 // point to C-string explaining why the service is not auto-connectable.
459 virtual bool IsAutoConnectable(const char **reason) const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000460
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800461 // HelpRegisterDerived*: Expose a property over RPC, with the name |name|.
462 //
463 // Reads of the property will be handled by invoking |get|.
464 // Writes to the property will be handled by invoking |set|.
465 // Clearing the property will be handled by PropertyStore.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700466 void HelpRegisterDerivedBool(
467 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800468 bool(Service::*get)(Error *error),
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700469 bool(Service::*set)(const bool &value, Error *error));
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700470 void HelpRegisterDerivedInt32(
471 const std::string &name,
472 int32(Service::*get)(Error *error),
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700473 bool(Service::*set)(const int32 &value, Error *error));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700474 void HelpRegisterDerivedString(
475 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800476 std::string(Service::*get)(Error *error),
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700477 bool(Service::*set)(const std::string &value, Error *error));
478 void HelpRegisterConstDerivedUint16(
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800479 const std::string &name,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700480 uint16(Service::*get)(Error *error));
481 void HelpRegisterConstDerivedRpcIdentifier(
Jason Glasgowacdc11f2012-03-30 14:12:22 -0400482 const std::string &name,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700483 std::string(Service::*get)(Error *));
Darin Petkov0c65bdd2012-12-05 13:42:41 +0100484 void HelpRegisterConstDerivedStrings(
485 const std::string &name, Strings(Service::*get)(Error *error));
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800486 // Expose a property over RPC, with the name |name|.
487 //
488 // Reads of the property will be handled by invoking |get|.
489 // Writes to the property will be handled by invoking |set|.
490 //
491 // Clearing the property will be handled by invoking |clear|, or
492 // calling |set| with |default_value| (whichever is non-NULL). It
493 // is an error to call this method with both |clear| and
494 // |default_value| non-NULL.
495 void HelpRegisterWriteOnlyDerivedString(
496 const std::string &name,
497 void(Service::*set)(const std::string &value, Error *error),
498 void(Service::*clear)(Error *error),
499 const std::string *default_value);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700500
Darin Petkovb72cf402011-11-22 14:51:39 +0100501 ServiceAdaptorInterface *adaptor() const { return adaptor_.get(); }
502
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800503 void UnloadEapCredentials();
Darin Petkovba40dd32011-07-11 20:06:39 -0700504
Paul Stewartcb59fed2012-03-21 21:14:46 -0700505 // Ignore |parameter| when performing a Configure() operation.
506 void IgnoreParameterForConfigure(const std::string &parameter);
507
Paul Stewartf2d60912012-07-15 08:37:30 -0700508 // Update the service's string-based "Error" RPC property based on the
509 // failure_ enum.
510 void UpdateErrorProperty();
511
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700512 // RPC setter for the the "AutoConnect" property. Updates the |manager_|.
513 // (cf. SetAutoConnect, which does not update the manager.)
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700514 virtual bool SetAutoConnectFull(const bool &connect, Error *error);
Paul Stewartcf199de2012-08-16 07:50:41 -0700515
Paul Stewartac4ac002011-08-26 12:04:26 -0700516 // Property accessors reserved for subclasses
517 EventDispatcher *dispatcher() const { return dispatcher_; }
518 const std::string &GetEAPKeyManagement() const;
mukesh agrawal43970a22013-02-15 16:00:07 -0800519 virtual void SetEAPKeyManagement(const std::string &key_management);
Paul Stewart65512e12012-03-26 18:01:08 -0700520 Manager *manager() const { return manager_; }
Thieu Le48e6d6d2011-12-06 00:40:27 +0000521 Metrics *metrics() const { return metrics_; }
mukesh agrawalb54601c2011-06-07 17:39:22 -0700522
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700523 // Mark the serivce as a favorite, without affecting its auto_connect
524 // property. (cf. MakeFavorite)
525 void MarkAsFavorite();
mukesh agrawal43970a22013-02-15 16:00:07 -0800526 // Inform base class of the security properties for the service.
527 //
528 // NB: When adding a call to this function from a subclass, please check
529 // that the semantics of SecurityLevel() are appropriate for the subclass.
530 void SetSecurity(CryptoAlgorithm crypt, bool rotation, bool endpoint_auth);
Darin Petkov1d0080a2012-04-30 17:10:36 +0200531
Paul Stewart75897df2011-04-27 09:05:53 -0700532 private:
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700533 friend class EthernetEapServiceTest;
Paul Stewartcf199de2012-08-16 07:50:41 -0700534 friend class EthernetServiceTest;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000535 friend class MetricsTest;
Paul Stewart9dd253e2013-04-22 08:32:59 -0700536 friend class ManagerTest;
Paul Stewart0756db92012-01-27 08:34:47 -0800537 friend class ServiceAdaptorInterface;
Darin Petkov385b9bc2012-12-03 15:25:05 +0100538 friend class ServiceTest;
Darin Petkov457728b2013-01-09 09:49:08 +0100539 friend class VPNProviderTest;
Darin Petkov5eb05422012-05-11 15:45:25 +0200540 friend class VPNServiceTest;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800541 friend class WiFiServiceTest;
Darin Petkov457728b2013-01-09 09:49:08 +0100542 friend class WiMaxProviderTest;
Darin Petkov6b9b2e12012-07-10 15:51:42 +0200543 friend class WiMaxServiceTest;
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700544 friend void TestCommonPropertyChanges(ServiceRefPtr, ServiceMockAdaptor *);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700545 friend void TestCustomSetterNoopChange(ServiceRefPtr, MockManager *);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700546 friend void TestNamePropertyChange(ServiceRefPtr, ServiceMockAdaptor *);
Christopher Wiley0801d192012-09-24 11:57:15 -0700547 FRIEND_TEST(AllMockServiceTest, AutoConnectWithFailures);
Darin Petkov457728b2013-01-09 09:49:08 +0100548 FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier);
Liam McLoughlin0fec81c2013-02-28 10:31:47 -0500549 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier);
Ben Chan19f83972012-10-03 23:25:56 -0700550 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700551 FRIEND_TEST(DeviceTest, IPConfigUpdatedFailureWithStatic);
Paul Stewart39db5ca2013-03-18 14:15:17 -0700552 FRIEND_TEST(ManagerTest, ConnectToBestServices);
mukesh agrawal43970a22013-02-15 16:00:07 -0800553 // TODO(quiche): The SortServices test should probably move into
554 // service_unittest.cc. Then the following line should be removed.
555 // (crosbug.com/23370)
556 FRIEND_TEST(ManagerTest, SortServices);
mukesh agrawal03c15ce2012-11-29 17:36:21 -0800557 FRIEND_TEST(ServiceTest, AutoConnectLogging);
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200558 FRIEND_TEST(ServiceTest, CalculateState);
559 FRIEND_TEST(ServiceTest, CalculateTechnology);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700560 FRIEND_TEST(ServiceTest, Certification);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700561 FRIEND_TEST(ServiceTest, ConfigureEapStringProperty);
Paul Stewartcb59fed2012-03-21 21:14:46 -0700562 FRIEND_TEST(ServiceTest, ConfigureIgnoredProperty);
Darin Petkovba40dd32011-07-11 20:06:39 -0700563 FRIEND_TEST(ServiceTest, Constructor);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700564 FRIEND_TEST(ServiceTest, CustomSetterNoopChange);
Paul Stewart10241e32012-04-23 18:15:06 -0700565 FRIEND_TEST(ServiceTest, GetIPConfigRpcIdentifier);
Thieu Le284fe792012-01-31 17:53:19 -0800566 FRIEND_TEST(ServiceTest, GetProperties);
mukesh agrawal76d13882012-01-12 15:23:11 -0800567 FRIEND_TEST(ServiceTest, IsAutoConnectable);
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800568 FRIEND_TEST(ServiceTest, IsDependentOn);
Paul Stewartd215af62012-04-24 23:25:50 -0700569 FRIEND_TEST(ServiceTest, RecheckPortal);
Darin Petkovba40dd32011-07-11 20:06:39 -0700570 FRIEND_TEST(ServiceTest, Save);
571 FRIEND_TEST(ServiceTest, SaveString);
572 FRIEND_TEST(ServiceTest, SaveStringCrypted);
573 FRIEND_TEST(ServiceTest, SaveStringDontSave);
574 FRIEND_TEST(ServiceTest, SaveStringEmpty);
mukesh agrawal43970a22013-02-15 16:00:07 -0800575 FRIEND_TEST(ServiceTest, SecurityLevel);
Paul Stewartd215af62012-04-24 23:25:50 -0700576 FRIEND_TEST(ServiceTest, SetCheckPortal);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700577 FRIEND_TEST(ServiceTest, SetConnectableFull);
Arman Uguray2717a102013-01-29 23:36:06 -0800578 FRIEND_TEST(ServiceTest, SetFriendlyName);
579 FRIEND_TEST(ServiceTest, SetProperty);
mukesh agrawal568b5c62012-02-28 14:44:47 -0800580 FRIEND_TEST(ServiceTest, State);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800581 FRIEND_TEST(ServiceTest, Unload);
Paul Stewart1369c2b2013-01-11 05:41:26 -0800582 FRIEND_TEST(WiFiMainTest, SuspectCredentialsEAPInProgress);
mukesh agrawalcf24a242012-05-21 16:46:11 -0700583 FRIEND_TEST(WiFiMainTest, SuspectCredentialsWPAPreviouslyConnected);
Christopher Wiley0801d192012-09-24 11:57:15 -0700584 FRIEND_TEST(WiFiTimerTest, ReconnectTimer);
Darin Petkovba40dd32011-07-11 20:06:39 -0700585
mukesh agrawalbf14e942012-03-02 14:36:34 -0800586 static const char kAutoConnConnected[];
587 static const char kAutoConnConnecting[];
588 static const char kAutoConnExplicitDisconnect[];
589 static const char kAutoConnNotConnectable[];
Darin Petkov4cbff5b2013-01-29 16:29:05 +0100590 static const char kAutoConnOffline[];
Christopher Wiley0801d192012-09-24 11:57:15 -0700591 static const char kAutoConnThrottled[];
mukesh agrawalbf14e942012-03-02 14:36:34 -0800592
Paul Stewartbc6e7392012-05-24 07:07:48 -0700593 static const size_t kEAPMaxCertificationElements;
594
Darin Petkov2f903b32012-04-18 12:56:43 +0200595 static const char kServiceSortAutoConnect[];
596 static const char kServiceSortConnectable[];
597 static const char kServiceSortFavorite[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800598 static const char kServiceSortIsConnected[];
Paul Stewartdf3c0a82012-11-09 15:54:33 -0800599 static const char kServiceSortDependency[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800600 static const char kServiceSortIsConnecting[];
601 static const char kServiceSortIsFailed[];
Paul Stewarta121c442012-06-09 14:12:58 -0700602 static const char kServiceSortIsPortalled[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200603 static const char kServiceSortPriority[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800604 static const char kServiceSortSecurityEtc[];
Darin Petkov2f903b32012-04-18 12:56:43 +0200605 static const char kServiceSortTechnology[];
mukesh agrawalddc378f2012-02-17 18:26:20 -0800606 static const char kServiceSortUniqueName[];
607
Christopher Wiley0801d192012-09-24 11:57:15 -0700608 static const uint64 kMaxAutoConnectCooldownTimeMilliseconds;
609 static const uint64 kMinAutoConnectCooldownTimeMilliseconds;
610 static const uint64 kAutoConnectCooldownBackoffFactor;
611
Darin Petkov385b9bc2012-12-03 15:25:05 +0100612 static const int kDisconnectsMonitorSeconds;
613 static const int kMisconnectsMonitorSeconds;
614 static const int kReportDisconnectsThreshold;
615 static const int kReportMisconnectsThreshold;
616 static const int kMaxDisconnectEventHistory;
617
Thieu Le284fe792012-01-31 17:53:19 -0800618 bool GetAutoConnect(Error *error);
Thieu Le284fe792012-01-31 17:53:19 -0800619
Paul Stewartd215af62012-04-24 23:25:50 -0700620 std::string GetCheckPortal(Error *error);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700621 bool SetCheckPortal(const std::string &check_portal, Error *error);
Paul Stewartd215af62012-04-24 23:25:50 -0700622
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700623 std::string GetGuid(Error *error);
624
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800625 virtual std::string GetDeviceRpcId(Error *error) = 0;
Chris Masone95207da2011-06-29 16:50:49 -0700626
Paul Stewart10241e32012-04-23 18:15:06 -0700627 std::string GetIPConfigRpcIdentifier(Error *error);
628
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700629 std::string GetNameProperty(Error *error);
Darin Petkov9c6e9812013-03-26 13:49:07 +0100630 // The base implementation asserts that |name| matches the current Name
631 // property value.
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700632 virtual bool SetNameProperty(const std::string &name, Error *error);
mukesh agrawalcbfb34e2013-04-17 19:33:25 -0700633
634 int32 GetPriority(Error *error);
Paul Stewart0c438332012-04-11 07:55:27 -0700635
Paul Stewart1b1a7f22012-01-06 16:24:06 -0800636 std::string GetProfileRpcId(Error *error);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700637 bool SetProfileRpcId(const std::string &profile, Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700638
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800639 // Returns TCP port of service's HTTP proxy in host order.
640 uint16 GetHTTPProxyPort(Error *error);
641
Philipp Neubeck79173602012-11-13 21:10:09 +0100642 std::string GetProxyConfig(Error *error);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700643 bool SetProxyConfig(const std::string &proxy_config, Error *error);
Philipp Neubeck79173602012-11-13 21:10:09 +0100644
Darin Petkov0c65bdd2012-12-05 13:42:41 +0100645 static Strings ExtractWallClockToStrings(
646 const std::deque<Timestamp> &timestamps);
647 Strings GetDisconnectsProperty(Error *error);
648 Strings GetMisconnectsProperty(Error *error);
649
Christopher Wiley0801d192012-09-24 11:57:15 -0700650 void ReEnableAutoConnectTask();
651 // Disables autoconnect and posts a task to re-enable it after a cooldown.
652 // Note that autoconnect could be disabled for other reasons as well.
653 void ThrottleFutureAutoConnects();
654
mukesh agrawalcf24a242012-05-21 16:46:11 -0700655 // Saves settings to profile, if we have one. Unlike
656 // SaveServiceToProfile, SaveToProfile never assigns this service
657 // into a profile.
658 void SaveToProfile();
659
Paul Stewart483e4722012-12-18 10:23:17 -0800660 // Start at the head of |events| and remove all entries that occurred
661 // more than |seconds_ago| prior to |now|. Also, the size of |events|
662 // is unconditionally trimmed below kMaxDisconnectEventHistory.
663 static void ExpireEventsBefore(
664 int seconds_ago, const Timestamp &now, std::deque<Timestamp> *events);
665
666 // Qualify the conditions under which the most recent disconnect occurred.
667 // Make note ot the fact that there was a problem connecting / staying
668 // connected if the disconnection did not occur as a clear result of user
669 // action.
Darin Petkov385b9bc2012-12-03 15:25:05 +0100670 void NoteDisconnectEvent();
671
Paul Stewart22aa71b2011-09-16 12:15:11 -0700672 // Utility function that returns true if a is different from b. When they
673 // are, "decision" is populated with the boolean value of "a > b".
674 static bool DecideBetween(int a, int b, bool *decision);
675
mukesh agrawal43970a22013-02-15 16:00:07 -0800676 // Linearize security parameters (crypto algorithm, key rotation, endpoint
677 // authentication) for comparison.
678 uint16 SecurityLevel();
679
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700680 // WeakPtrFactory comes first, so that other fields can use it.
681 base::WeakPtrFactory<Service> weak_ptr_factory_;
682
Paul Stewartac4ac002011-08-26 12:04:26 -0700683 ConnectState state_;
Darin Petkovc8d91e52013-01-21 11:43:47 +0100684 ConnectState previous_state_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700685 ConnectFailure failure_;
686 bool auto_connect_;
687 std::string check_portal_;
688 bool connectable_;
689 std::string error_;
Darin Petkovaba89322013-03-11 14:48:22 +0100690 std::string error_details_;
mukesh agrawaladb68482012-01-17 16:31:51 -0800691 bool explicitly_disconnected_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700692 bool favorite_;
693 int32 priority_;
mukesh agrawal43970a22013-02-15 16:00:07 -0800694 uint8 crypto_algorithm_;
695 bool key_rotation_;
696 bool endpoint_auth_;
697
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100698 uint8 strength_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700699 std::string proxy_config_;
Paul Stewart987e71e2011-12-05 09:45:06 -0800700 std::string ui_data_;
Paul Stewart4c561612012-03-21 12:49:01 -0700701 std::string guid_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700702 bool save_credentials_;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700703 scoped_ptr<EapCredentials> eap_;
Gaurav Shah435de2c2011-11-17 19:01:07 -0800704 Technology::Identifier technology_;
mukesh agrawal568b5c62012-02-28 14:44:47 -0800705 // The time of the most recent failure. Value is 0 if the service is
706 // not currently failed.
707 time_t failed_time_;
mukesh agrawalcf24a242012-05-21 16:46:11 -0700708 // Whether or not this service has ever reached kStateConnected.
709 bool has_ever_connected_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700710
Darin Petkov0c65bdd2012-12-05 13:42:41 +0100711 std::deque<Timestamp> disconnects_; // Connection drops.
712 std::deque<Timestamp> misconnects_; // Failures to connect.
Darin Petkov385b9bc2012-12-03 15:25:05 +0100713
Christopher Wiley0801d192012-09-24 11:57:15 -0700714 base::CancelableClosure reenable_auto_connect_task_;
715 uint64 auto_connect_cooldown_milliseconds_ ;
716
Paul Stewartac4ac002011-08-26 12:04:26 -0700717 ProfileRefPtr profile_;
718 PropertyStore store_;
Paul Stewartcb59fed2012-03-21 21:14:46 -0700719 std::set<std::string> parameters_ignored_for_configure_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700720
721 EventDispatcher *dispatcher_;
mukesh agrawal51a7e932011-07-27 16:18:26 -0700722 static unsigned int serial_number_;
mukesh agrawald835b202011-10-07 15:26:47 -0700723 std::string unique_name_; // MUST be unique amongst service instances
Darin Petkov457728b2013-01-09 09:49:08 +0100724
725 // Service's friendly name is presented through the UI. By default it's the
726 // same as |unique_name_| but normally Service subclasses override
727 // it. WARNING: Don't log the friendly name at the default logging level due
728 // to PII concerns.
729 std::string friendly_name_;
730
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700731 // List of subject names reported by remote entity during TLS setup.
732 std::vector<std::string> remote_certification_;
733
Paul Stewartba41b992011-05-26 07:02:46 -0700734 scoped_ptr<ServiceAdaptorInterface> adaptor_;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800735 scoped_ptr<HTTPProxy> http_proxy_;
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800736 ConnectionRefPtr connection_;
Paul Stewart1062d9d2012-04-27 10:42:27 -0700737 StaticIPParameters static_ip_parameters_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800738 Metrics *metrics_;
Chris Masone6791a432011-07-12 13:23:19 -0700739 Manager *manager_;
Darin Petkov5eb05422012-05-11 15:45:25 +0200740 scoped_ptr<Sockets> sockets_;
Darin Petkov385b9bc2012-12-03 15:25:05 +0100741 Time *time_;
742 DiagnosticsReporter *diagnostics_reporter_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700743
mukesh agrawalb54601c2011-06-07 17:39:22 -0700744 DISALLOW_COPY_AND_ASSIGN(Service);
Paul Stewart75897df2011-04-27 09:05:53 -0700745};
746
747} // namespace shill
748
Ben Chan19f83972012-10-03 23:25:56 -0700749#endif // SHILL_SERVICE_H_