mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 5 | #include "shill/manager.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <time.h> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 9 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 10 | #include <algorithm> |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 11 | #include <set> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 12 | #include <string> |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 13 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 14 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 15 | #include <base/bind.h> |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 16 | #include <base/file_util.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 17 | #include <base/memory/ref_counted.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 18 | #include <base/stringprintf.h> |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 19 | #include <base/string_split.h> |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 20 | #include <base/string_util.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 21 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 22 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 23 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 24 | #include "shill/connection.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 25 | #include "shill/control_interface.h" |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 26 | #include "shill/dbus_adaptor.h" |
Darin Petkov | 002c58e | 2012-06-19 02:56:05 +0200 | [diff] [blame] | 27 | #include "shill/dbus_manager.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 28 | #include "shill/default_profile.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 29 | #include "shill/device.h" |
| 30 | #include "shill/device_info.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 31 | #include "shill/ephemeral_profile.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 32 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 33 | #include "shill/event_dispatcher.h" |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 34 | #include "shill/geolocation_info.h" |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 35 | #include "shill/hook_table.h" |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 36 | #include "shill/key_file_store.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 37 | #include "shill/logging.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 38 | #include "shill/profile.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 39 | #include "shill/property_accessor.h" |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 40 | #include "shill/proxy_factory.h" |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 41 | #include "shill/resolver.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 42 | #include "shill/service.h" |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 43 | #include "shill/service_sorter.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 44 | #include "shill/vpn_service.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 45 | #include "shill/wifi.h" |
| 46 | #include "shill/wifi_service.h" |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 47 | #include "shill/wimax_service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 48 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 49 | using base::Bind; |
| 50 | using base::StringPrintf; |
| 51 | using base::Unretained; |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 52 | using std::map; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 53 | using std::set; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 54 | using std::string; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 55 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 56 | |
| 57 | namespace shill { |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 58 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 59 | // statics |
| 60 | const char Manager::kErrorNoDevice[] = "no wifi devices available"; |
| 61 | const char Manager::kErrorTypeRequired[] = "must specify service type"; |
| 62 | const char Manager::kErrorUnsupportedServiceType[] = |
| 63 | "service type is unsupported"; |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 64 | // This timeout should be less than the upstart job timeout, otherwise |
| 65 | // stats for termination actions might be lost. |
| 66 | const int Manager::kTerminationActionsTimeoutMilliseconds = 4500; |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 67 | const char Manager::kPowerManagerKey[] = "manager"; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 68 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 69 | Manager::Manager(ControlInterface *control_interface, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 70 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 71 | Metrics *metrics, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 72 | GLib *glib, |
| 73 | const string &run_directory, |
| 74 | const string &storage_directory, |
| 75 | const string &user_storage_format) |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 76 | : dispatcher_(dispatcher), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 77 | run_path_(FilePath(run_directory)), |
| 78 | storage_path_(FilePath(storage_directory)), |
| 79 | user_storage_format_(user_storage_format), |
| 80 | adaptor_(control_interface->CreateManagerAdaptor(this)), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 81 | device_info_(control_interface, dispatcher, metrics, this), |
| 82 | modem_info_(control_interface, dispatcher, metrics, this, glib), |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 83 | vpn_provider_(control_interface, dispatcher, metrics, this), |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 84 | wimax_provider_(control_interface, dispatcher, metrics, this), |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 85 | resolver_(Resolver::GetInstance()), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 86 | running_(false), |
| 87 | connect_profiles_to_rpc_(true), |
| 88 | ephemeral_profile_(new EphemeralProfile(control_interface, this)), |
| 89 | control_interface_(control_interface), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 90 | metrics_(metrics), |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 91 | glib_(glib), |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 92 | use_startup_portal_list_(false), |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 93 | termination_actions_(dispatcher), |
| 94 | default_service_callback_tag_(0) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 95 | HelpRegisterDerivedString(flimflam::kActiveProfileProperty, |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 96 | &Manager::GetActiveProfileRpcIdentifier, |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 97 | NULL); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 98 | store_.RegisterBool(flimflam::kArpGatewayProperty, &props_.arp_gateway); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 99 | HelpRegisterDerivedStrings(flimflam::kAvailableTechnologiesProperty, |
| 100 | &Manager::AvailableTechnologies, |
| 101 | NULL); |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 102 | HelpRegisterDerivedString(flimflam::kCheckPortalListProperty, |
| 103 | &Manager::GetCheckPortalList, |
| 104 | &Manager::SetCheckPortalList); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 105 | HelpRegisterDerivedStrings(flimflam::kConnectedTechnologiesProperty, |
| 106 | &Manager::ConnectedTechnologies, |
| 107 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 108 | store_.RegisterString(flimflam::kCountryProperty, &props_.country); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 109 | HelpRegisterDerivedString(flimflam::kDefaultTechnologyProperty, |
| 110 | &Manager::DefaultTechnology, |
| 111 | NULL); |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 112 | HelpRegisterConstDerivedRpcIdentifier( |
| 113 | shill::kDefaultServiceProperty, |
| 114 | &Manager::GetDefaultServiceRpcIdentifier); |
Paul Stewart | cb3eb89 | 2012-06-07 14:24:46 -0700 | [diff] [blame] | 115 | HelpRegisterConstDerivedRpcIdentifiers(flimflam::kDevicesProperty, |
| 116 | &Manager::EnumerateDevices); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 117 | HelpRegisterDerivedStrings(flimflam::kEnabledTechnologiesProperty, |
| 118 | &Manager::EnabledTechnologies, |
| 119 | NULL); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 120 | HelpRegisterDerivedString(shill::kIgnoredDNSSearchPathsProperty, |
| 121 | &Manager::GetIgnoredDNSSearchPaths, |
| 122 | &Manager::SetIgnoredDNSSearchPaths); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 123 | store_.RegisterString(shill::kLinkMonitorTechnologiesProperty, |
| 124 | &props_.link_monitor_technologies); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 125 | store_.RegisterBool(flimflam::kOfflineModeProperty, &props_.offline_mode); |
| 126 | store_.RegisterString(flimflam::kPortalURLProperty, &props_.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 127 | store_.RegisterInt32(kPortalCheckIntervalProperty, |
| 128 | &props_.portal_check_interval_seconds); |
Paul Stewart | cb3eb89 | 2012-06-07 14:24:46 -0700 | [diff] [blame] | 129 | HelpRegisterConstDerivedRpcIdentifiers(flimflam::kProfilesProperty, |
| 130 | &Manager::EnumerateProfiles); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 131 | store_.RegisterString(kHostNameProperty, &props_.host_name); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 132 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 133 | &Manager::CalculateState, |
| 134 | NULL); |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 135 | HelpRegisterConstDerivedRpcIdentifiers(flimflam::kServicesProperty, |
| 136 | &Manager::EnumerateAvailableServices); |
Paul Stewart | cb3eb89 | 2012-06-07 14:24:46 -0700 | [diff] [blame] | 137 | HelpRegisterConstDerivedRpcIdentifiers(flimflam::kServiceWatchListProperty, |
| 138 | &Manager::EnumerateWatchedServices); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 139 | store_.RegisterString(shill::kShortDNSTimeoutTechnologiesProperty, |
| 140 | &props_.short_dns_timeout_technologies); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 141 | |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 142 | // Set default technology order "by hand", to avoid invoking side |
| 143 | // effects of SetTechnologyOrder. |
| 144 | technology_order_.push_back( |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 145 | Technology::IdentifierFromName(flimflam::kTypeVPN)); |
| 146 | technology_order_.push_back( |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 147 | Technology::IdentifierFromName(flimflam::kTypeEthernet)); |
| 148 | technology_order_.push_back( |
| 149 | Technology::IdentifierFromName(flimflam::kTypeWifi)); |
| 150 | technology_order_.push_back( |
Ben Chan | 3cafe38 | 2012-11-13 07:51:10 -0800 | [diff] [blame] | 151 | Technology::IdentifierFromName(flimflam::kTypeWimax)); |
| 152 | technology_order_.push_back( |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 153 | Technology::IdentifierFromName(flimflam::kTypeCellular)); |
| 154 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 155 | SLOG(Manager, 2) << "Manager initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 158 | Manager::~Manager() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 159 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 160 | void Manager::AddDeviceToBlackList(const string &device_name) { |
| 161 | device_info_.AddDeviceToBlackList(device_name); |
| 162 | } |
| 163 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 164 | void Manager::Start() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 165 | LOG(INFO) << "Manager started."; |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 166 | |
Darin Petkov | 002c58e | 2012-06-19 02:56:05 +0200 | [diff] [blame] | 167 | dbus_manager_.reset(new DBusManager()); |
| 168 | dbus_manager_->Start(); |
| 169 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 170 | power_manager_.reset( |
| 171 | new PowerManager(dispatcher_, ProxyFactory::GetInstance())); |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 172 | power_manager_->AddStateChangeCallback( |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 173 | kPowerManagerKey, |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 174 | Bind(&Manager::OnPowerStateChanged, AsWeakPtr())); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 175 | // TODO(ers): weak ptr for metrics_? |
| 176 | PowerManager::PowerStateCallback cb = |
| 177 | Bind(&Metrics::NotifyPowerStateChange, Unretained(metrics_)); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 178 | power_manager_->AddStateChangeCallback(Metrics::kMetricPowerManagerKey, cb); |
| 179 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 180 | CHECK(file_util::CreateDirectory(run_path_)) << run_path_.value(); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 181 | resolver_->set_path(run_path_.Append("resolv.conf")); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 182 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 183 | InitializeProfiles(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 184 | running_ = true; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 185 | adaptor_->UpdateRunning(); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 186 | device_info_.Start(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 187 | modem_info_.Start(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 188 | vpn_provider_.Start(); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 189 | wimax_provider_.Start(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void Manager::Stop() { |
| 193 | running_ = false; |
Paul Stewart | 212d60f | 2012-07-12 10:59:13 -0700 | [diff] [blame] | 194 | // Persist device information to disk; |
| 195 | vector<DeviceRefPtr>::iterator devices_it; |
| 196 | for (devices_it = devices_.begin(); devices_it != devices_.end(); |
| 197 | ++devices_it) { |
| 198 | UpdateDevice(*devices_it); |
| 199 | } |
| 200 | |
| 201 | // Persist profile, service information to disk. |
| 202 | vector<ProfileRefPtr>::iterator profiles_it; |
| 203 | for (profiles_it = profiles_.begin(); profiles_it != profiles_.end(); |
| 204 | ++profiles_it) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 205 | // Since this happens in a loop, the current manager state is stored to |
| 206 | // all default profiles in the stack. This is acceptable because the |
| 207 | // only time multiple default profiles are loaded are during autotests. |
Paul Stewart | 212d60f | 2012-07-12 10:59:13 -0700 | [diff] [blame] | 208 | (*profiles_it)->Save(); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 209 | } |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 210 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 211 | vector<ServiceRefPtr>::iterator services_it; |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 212 | Error e; |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 213 | for (services_it = services_.begin(); services_it != services_.end(); |
| 214 | ++services_it) { |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 215 | (*services_it)->Disconnect(&e); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 218 | adaptor_->UpdateRunning(); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 219 | wimax_provider_.Stop(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 220 | vpn_provider_.Stop(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 221 | modem_info_.Stop(); |
| 222 | device_info_.Stop(); |
Paul Stewart | dfa4605 | 2012-06-26 09:44:14 -0700 | [diff] [blame] | 223 | sort_services_task_.Cancel(); |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 224 | power_manager_.reset(); |
Darin Petkov | 002c58e | 2012-06-19 02:56:05 +0200 | [diff] [blame] | 225 | dbus_manager_.reset(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 228 | void Manager::InitializeProfiles() { |
| 229 | DCHECK(profiles_.empty()); |
| 230 | // The default profile must go first on the stack. |
| 231 | CHECK(file_util::CreateDirectory(storage_path_)) << storage_path_.value(); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 232 | scoped_refptr<DefaultProfile> |
| 233 | default_profile(new DefaultProfile(control_interface_, |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 234 | this, |
| 235 | storage_path_, |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 236 | DefaultProfile::kDefaultId, |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 237 | props_)); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 238 | CHECK(default_profile->InitStorage(glib_, Profile::kCreateOrOpenExisting, |
| 239 | NULL)); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 240 | CHECK(LoadProperties(default_profile)); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 241 | profiles_.push_back(default_profile.release()); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 242 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 243 | string path; |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 244 | for (vector<string>::iterator it = startup_profiles_.begin(); |
| 245 | it != startup_profiles_.end(); ++it) |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 246 | PushProfile(*it, &path, &error); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 249 | void Manager::CreateProfile(const string &name, string *path, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 250 | SLOG(Manager, 2) << __func__ << " " << name; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 251 | Profile::Identifier ident; |
| 252 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 253 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 254 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 255 | return; |
| 256 | } |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 257 | |
Paul Stewart | fc9a1da | 2012-06-27 15:54:52 -0700 | [diff] [blame] | 258 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 259 | it != profiles_.end(); |
| 260 | ++it) { |
| 261 | if ((*it)->MatchesIdentifier(ident)) { |
| 262 | Error::PopulateAndLog(error, Error::kAlreadyExists, |
| 263 | "Profile name " + name + " is already on stack"); |
| 264 | *path = (*it)->GetRpcIdentifier(); |
| 265 | return; |
| 266 | } |
| 267 | } |
| 268 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 269 | ProfileRefPtr profile; |
| 270 | if (ident.user.empty()) { |
| 271 | profile = new DefaultProfile(control_interface_, |
| 272 | this, |
| 273 | storage_path_, |
| 274 | ident.identifier, |
| 275 | props_); |
| 276 | } else { |
| 277 | profile = new Profile(control_interface_, |
| 278 | this, |
| 279 | ident, |
| 280 | user_storage_format_, |
Gary Morain | b672d35 | 2012-04-25 09:19:06 -0700 | [diff] [blame] | 281 | true); |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 284 | if (!profile->InitStorage(glib_, Profile::kCreateNew, error)) { |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 285 | // |error| will have been populated by InitStorage(). |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 286 | return; |
| 287 | } |
| 288 | |
| 289 | // Save profile data out, and then let the scoped pointer fall out of scope. |
| 290 | if (!profile->Save()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 291 | Error::PopulateAndLog(error, Error::kInternalError, |
| 292 | "Profile name " + name + " could not be saved"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 293 | return; |
| 294 | } |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 295 | |
| 296 | *path = profile->GetRpcIdentifier(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 299 | void Manager::PushProfile(const string &name, string *path, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 300 | SLOG(Manager, 2) << __func__ << " " << name; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 301 | Profile::Identifier ident; |
| 302 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 303 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 304 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 309 | it != profiles_.end(); |
| 310 | ++it) { |
| 311 | if ((*it)->MatchesIdentifier(ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 312 | Error::PopulateAndLog(error, Error::kAlreadyExists, |
| 313 | "Profile name " + name + " is already on stack"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 314 | return; |
| 315 | } |
| 316 | } |
| 317 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 318 | ProfileRefPtr profile; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 319 | if (ident.user.empty()) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 320 | // Allow a machine-wide-profile to be pushed on the stack only if the |
| 321 | // profile stack is empty, or if the topmost profile on the stack is |
| 322 | // also a machine-wide (non-user) profile. |
| 323 | if (!profiles_.empty() && !profiles_.back()->GetUser().empty()) { |
| 324 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 325 | "Cannot load non-default global profile " + name + |
| 326 | " on top of a user profile"); |
| 327 | return; |
| 328 | } |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 329 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 330 | scoped_refptr<DefaultProfile> |
| 331 | default_profile(new DefaultProfile(control_interface_, |
| 332 | this, |
| 333 | storage_path_, |
| 334 | ident.identifier, |
| 335 | props_)); |
| 336 | if (!default_profile->InitStorage(glib_, Profile::kOpenExisting, error)) { |
| 337 | // |error| will have been populated by InitStorage(). |
| 338 | return; |
| 339 | } |
| 340 | |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 341 | if (!LoadProperties(default_profile)) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 342 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 343 | "Could not load Manager properties from profile " + |
| 344 | name); |
| 345 | return; |
| 346 | } |
| 347 | profile = default_profile; |
| 348 | } else { |
| 349 | profile = new Profile(control_interface_, |
| 350 | this, |
| 351 | ident, |
| 352 | user_storage_format_, |
| 353 | connect_profiles_to_rpc_); |
| 354 | if (!profile->InitStorage(glib_, Profile::kOpenExisting, error)) { |
| 355 | // |error| will have been populated by InitStorage(). |
| 356 | return; |
| 357 | } |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 360 | profiles_.push_back(profile); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 361 | |
| 362 | // Offer each registered Service the opportunity to join this new Profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 363 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 364 | it != services_.end(); ++it) { |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 365 | profile->ConfigureService(*it); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 368 | // Shop the Profile contents around to Devices which can create |
| 369 | // non-visible services. |
| 370 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 371 | it != devices_.end(); ++it) { |
| 372 | profile->ConfigureDevice(*it); |
| 373 | } |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 374 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 375 | // Offer the Profile contents to the service/device providers which will |
| 376 | // create new services if necessary. |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 377 | vpn_provider_.CreateServicesFromProfile(profile); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 378 | wimax_provider_.CreateServicesFromProfile(profile); |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 379 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 380 | *path = profile->GetRpcIdentifier(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 381 | SortServices(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void Manager::PopProfileInternal() { |
| 385 | CHECK(!profiles_.empty()); |
| 386 | ProfileRefPtr active_profile = profiles_.back(); |
| 387 | profiles_.pop_back(); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 388 | vector<ServiceRefPtr>::iterator it; |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 389 | for (it = services_.begin(); it != services_.end();) { |
| 390 | if ((*it)->profile().get() != active_profile.get() || |
| 391 | MatchProfileWithService(*it) || |
| 392 | !UnloadService(&it)) { |
| 393 | LOG(ERROR) << "Skipping unload of service"; |
| 394 | ++it; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 397 | SortServices(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 400 | void Manager::PopProfile(const string &name, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 401 | SLOG(Manager, 2) << __func__ << " " << name; |
Christopher Wiley | 3e7635e | 2012-08-15 09:46:17 -0700 | [diff] [blame] | 402 | // This signal is sent when a user logs out of a session. Regardless of |
| 403 | // whether we find their profile to remove, lets clear the network related |
| 404 | // logs. |
| 405 | MemoryLog::GetInstance()->Clear(); |
| 406 | LOG(INFO) << "Cleared the memory log on logout event."; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 407 | Profile::Identifier ident; |
| 408 | if (profiles_.empty()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 409 | Error::PopulateAndLog(error, Error::kNotFound, "Profile stack is empty"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | ProfileRefPtr active_profile = profiles_.back(); |
| 413 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 414 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 415 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | if (!active_profile->MatchesIdentifier(ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 419 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 420 | name + " is not the active profile"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | PopProfileInternal(); |
| 424 | } |
| 425 | |
| 426 | void Manager::PopAnyProfile(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 427 | SLOG(Manager, 2) << __func__; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 428 | Profile::Identifier ident; |
| 429 | if (profiles_.empty()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 430 | Error::PopulateAndLog(error, Error::kNotFound, "Profile stack is empty"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | PopProfileInternal(); |
| 434 | } |
| 435 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 436 | void Manager::RemoveProfile(const string &name, Error *error) { |
| 437 | Profile::Identifier ident; |
| 438 | if (!Profile::ParseIdentifier(name, &ident)) { |
| 439 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 440 | "Invalid profile name " + name); |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 445 | it != profiles_.end(); |
| 446 | ++it) { |
| 447 | if ((*it)->MatchesIdentifier(ident)) { |
| 448 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 449 | "Cannot remove profile name " + name + |
| 450 | " since it is on stack"); |
| 451 | return; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | ProfileRefPtr profile; |
| 456 | if (ident.user.empty()) { |
| 457 | profile = new DefaultProfile(control_interface_, |
| 458 | this, |
| 459 | storage_path_, |
| 460 | ident.identifier, |
| 461 | props_); |
| 462 | } else { |
| 463 | profile = new Profile(control_interface_, |
| 464 | this, |
| 465 | ident, |
| 466 | user_storage_format_, |
| 467 | false); |
| 468 | } |
| 469 | |
| 470 | |
| 471 | // |error| will have been populated if RemoveStorage fails. |
| 472 | profile->RemoveStorage(glib_, error); |
| 473 | |
| 474 | return; |
| 475 | } |
| 476 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 477 | bool Manager::HandleProfileEntryDeletion(const ProfileRefPtr &profile, |
| 478 | const std::string &entry_name) { |
| 479 | bool moved_services = false; |
| 480 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 481 | it != services_.end();) { |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 482 | if ((*it)->profile().get() == profile.get() && |
| 483 | (*it)->GetStorageIdentifier() == entry_name) { |
| 484 | profile->AbandonService(*it); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 485 | if (MatchProfileWithService(*it) || |
| 486 | !UnloadService(&it)) { |
| 487 | ++it; |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 488 | } |
| 489 | moved_services = true; |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 490 | } else { |
| 491 | ++it; |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | return moved_services; |
| 495 | } |
| 496 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 497 | ServiceRefPtr Manager::GetServiceWithStorageIdentifier( |
| 498 | const ProfileRefPtr &profile, const std::string &entry_name, Error *error) { |
| 499 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 500 | it != services_.end(); ++it) { |
| 501 | if ((*it)->profile().get() == profile.get() && |
| 502 | (*it)->GetStorageIdentifier() == entry_name) { |
| 503 | return *it; |
| 504 | } |
| 505 | } |
| 506 | |
Paul Stewart | 76a89cb | 2012-09-14 06:06:48 -0700 | [diff] [blame] | 507 | string error_string( |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 508 | StringPrintf("Entry %s is not registered in the manager", |
| 509 | entry_name.c_str())); |
Paul Stewart | 76a89cb | 2012-09-14 06:06:48 -0700 | [diff] [blame] | 510 | if (error) { |
| 511 | error->Populate(Error::kNotFound, error_string); |
| 512 | } |
| 513 | SLOG(Manager, 2) << error_string; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 514 | return NULL; |
| 515 | } |
| 516 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 517 | ServiceRefPtr Manager::GetServiceWithGUID( |
| 518 | const std::string &guid, Error *error) { |
| 519 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 520 | it != services_.end(); ++it) { |
| 521 | if ((*it)->guid() == guid) { |
| 522 | return *it; |
| 523 | } |
| 524 | } |
| 525 | |
Paul Stewart | 76a89cb | 2012-09-14 06:06:48 -0700 | [diff] [blame] | 526 | string error_string( |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 527 | StringPrintf("Service wth GUID %s is not registered in the manager", |
| 528 | guid.c_str())); |
Paul Stewart | 76a89cb | 2012-09-14 06:06:48 -0700 | [diff] [blame] | 529 | if (error) { |
| 530 | error->Populate(Error::kNotFound, error_string); |
| 531 | } |
| 532 | SLOG(Manager, 2) << error_string; |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 533 | return NULL; |
| 534 | } |
| 535 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 536 | ServiceRefPtr Manager::GetDefaultService() const { |
| 537 | if (services_.empty() || !services_[0]->connection().get()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 538 | SLOG(Manager, 2) << "In " << __func__ << ": No default connection exists."; |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 539 | return NULL; |
| 540 | } |
| 541 | return services_[0]; |
| 542 | } |
| 543 | |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 544 | RpcIdentifier Manager::GetDefaultServiceRpcIdentifier(Error */*error*/) { |
| 545 | ServiceRefPtr default_service = GetDefaultService(); |
| 546 | return default_service ? default_service->GetRpcIdentifier() : "/"; |
| 547 | } |
| 548 | |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 549 | bool Manager::IsTechnologyInList(const string &technology_list, |
| 550 | Technology::Identifier tech) const { |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 551 | Error error; |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 552 | vector<Technology::Identifier> technologies; |
| 553 | return Technology::GetTechnologyVectorFromString(technology_list, |
| 554 | &technologies, |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 555 | &error) && |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 556 | std::find(technologies.begin(), technologies.end(), tech) != |
| 557 | technologies.end(); |
| 558 | } |
| 559 | |
| 560 | bool Manager::IsPortalDetectionEnabled(Technology::Identifier tech) { |
| 561 | return IsTechnologyInList(GetCheckPortalList(NULL), tech); |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 564 | void Manager::SetStartupPortalList(const string &portal_list) { |
| 565 | startup_portal_list_ = portal_list; |
| 566 | use_startup_portal_list_ = true; |
| 567 | } |
| 568 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 569 | bool Manager::IsServiceEphemeral(const ServiceConstRefPtr &service) const { |
| 570 | return service->profile() == ephemeral_profile_; |
| 571 | } |
| 572 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 573 | bool Manager::IsTechnologyShortDNSTimeoutEnabled( |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 574 | Technology::Identifier technology) const { |
| 575 | return IsTechnologyInList(props_.short_dns_timeout_technologies, technology); |
| 576 | } |
| 577 | |
| 578 | bool Manager::IsTechnologyLinkMonitorEnabled( |
| 579 | Technology::Identifier technology) const { |
| 580 | return IsTechnologyInList(props_.link_monitor_technologies, technology); |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 583 | const ProfileRefPtr &Manager::ActiveProfile() const { |
Eric Shienbrood | c74cf9c | 2012-03-02 15:00:35 -0500 | [diff] [blame] | 584 | DCHECK_NE(profiles_.size(), 0U); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 585 | return profiles_.back(); |
| 586 | } |
| 587 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 588 | bool Manager::IsActiveProfile(const ProfileRefPtr &profile) const { |
| 589 | return (profiles_.size() > 0 && |
| 590 | ActiveProfile().get() == profile.get()); |
| 591 | } |
| 592 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 593 | bool Manager::MoveServiceToProfile(const ServiceRefPtr &to_move, |
| 594 | const ProfileRefPtr &destination) { |
| 595 | const ProfileRefPtr from = to_move->profile(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 596 | SLOG(Manager, 2) << "Moving service " |
| 597 | << to_move->UniqueName() |
| 598 | << " to profile " |
| 599 | << destination->GetFriendlyName() |
| 600 | << " from " |
| 601 | << from->GetFriendlyName(); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 602 | return destination->AdoptService(to_move) && |
| 603 | from->AbandonService(to_move); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 606 | ProfileRefPtr Manager::LookupProfileByRpcIdentifier( |
| 607 | const string &profile_rpcid) { |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 608 | for (vector<ProfileRefPtr>::iterator it = profiles_.begin(); |
| 609 | it != profiles_.end(); |
| 610 | ++it) { |
| 611 | if (profile_rpcid == (*it)->GetRpcIdentifier()) { |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 612 | return *it; |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 613 | } |
| 614 | } |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 615 | return NULL; |
| 616 | } |
| 617 | |
| 618 | void Manager::SetProfileForService(const ServiceRefPtr &to_set, |
| 619 | const string &profile_rpcid, |
| 620 | Error *error) { |
| 621 | ProfileRefPtr profile = LookupProfileByRpcIdentifier(profile_rpcid); |
| 622 | if (!profile) { |
| 623 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 624 | StringPrintf("Unknown Profile %s requested for " |
| 625 | "Service", profile_rpcid.c_str())); |
| 626 | return; |
| 627 | } |
| 628 | |
Paul Stewart | 649f3a4 | 2012-04-24 23:22:16 -0700 | [diff] [blame] | 629 | if (!to_set->profile()) { |
| 630 | // We are being asked to set the profile property of a service that |
| 631 | // has never been registered. Now is a good time to register it. |
| 632 | RegisterService(to_set); |
| 633 | } |
| 634 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 635 | if (to_set->profile().get() == profile.get()) { |
| 636 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 637 | "Service is already connected to this profile"); |
| 638 | } else if (!MoveServiceToProfile(to_set, profile)) { |
| 639 | Error::PopulateAndLog(error, Error::kInternalError, |
| 640 | "Unable to move service to profile"); |
| 641 | } |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 644 | void Manager::EnableTechnology(const std::string &technology_name, |
| 645 | Error *error, |
| 646 | const ResultCallback &callback) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 647 | CHECK(error != NULL); |
| 648 | DCHECK(error->IsOngoing()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 649 | Technology::Identifier id = Technology::IdentifierFromName(technology_name); |
| 650 | if (id == Technology::kUnknown) { |
| 651 | error->Populate(Error::kInvalidArguments, "Unknown technology"); |
| 652 | return; |
| 653 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 654 | bool deferred = false; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 655 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 656 | it != devices_.end(); ++it) { |
| 657 | DeviceRefPtr device = *it; |
Joshua Kroll | da79862 | 2012-06-05 12:30:48 -0700 | [diff] [blame] | 658 | if (device->technology() == id && !device->enabled()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 659 | device->SetEnabledPersistent(true, error, callback); |
| 660 | // Continue with other devices even if one fails |
| 661 | // TODO(ers): Decide whether an error should be returned |
| 662 | // for the overall EnableTechnology operation if some |
| 663 | // devices succeed and some fail. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 664 | if (error->IsOngoing()) |
| 665 | deferred = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 666 | } |
| 667 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 668 | // If no device has deferred work, then clear the error to |
| 669 | // communicate to the caller that all work is done. |
| 670 | if (!deferred) |
| 671 | error->Reset(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void Manager::DisableTechnology(const std::string &technology_name, |
| 675 | Error *error, |
| 676 | const ResultCallback &callback) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 677 | CHECK(error != NULL); |
| 678 | DCHECK(error->IsOngoing()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 679 | Technology::Identifier id = Technology::IdentifierFromName(technology_name); |
| 680 | if (id == Technology::kUnknown) { |
| 681 | error->Populate(Error::kInvalidArguments, "Unknown technology"); |
| 682 | return; |
| 683 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 684 | bool deferred = false; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 685 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 686 | it != devices_.end(); ++it) { |
| 687 | DeviceRefPtr device = *it; |
Joshua Kroll | da79862 | 2012-06-05 12:30:48 -0700 | [diff] [blame] | 688 | if (device->technology() == id && device->enabled()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 689 | device->SetEnabledPersistent(false, error, callback); |
| 690 | // Continue with other devices even if one fails |
| 691 | // TODO(ers): Decide whether an error should be returned |
| 692 | // for the overall DisableTechnology operation if some |
| 693 | // devices succeed and some fail. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 694 | if (error->IsOngoing()) |
| 695 | deferred = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 696 | } |
| 697 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 698 | // If no device has deferred work, then clear the error to |
| 699 | // communicate to the caller that all work is done. |
| 700 | if (!deferred) |
| 701 | error->Reset(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | void Manager::UpdateEnabledTechnologies() { |
| 705 | Error error; |
| 706 | adaptor_->EmitStringsChanged(flimflam::kEnabledTechnologiesProperty, |
| 707 | EnabledTechnologies(&error)); |
| 708 | } |
| 709 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 710 | void Manager::RegisterDevice(const DeviceRefPtr &to_manage) { |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 711 | LOG(INFO) << "Device " << to_manage->FriendlyName() << " registered."; |
| 712 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 713 | it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 714 | if (to_manage.get() == it->get()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 715 | return; |
| 716 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 717 | devices_.push_back(to_manage); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 718 | |
Paul Stewart | 87a4ae8 | 2012-10-26 15:49:32 -0700 | [diff] [blame] | 719 | LoadDeviceFromProfiles(to_manage); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 720 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 721 | // If |to_manage| is new, it needs to be persisted. |
| 722 | UpdateDevice(to_manage); |
| 723 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 724 | // In normal usage, running_ will always be true when we are here, however |
| 725 | // unit tests sometimes do things in otherwise invalid states. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 726 | if (running_ && (to_manage->enabled_persistent() || |
| 727 | to_manage->IsUnderlyingDeviceEnabled())) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 728 | to_manage->SetEnabled(true); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 729 | |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 730 | EmitDeviceProperties(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 731 | } |
| 732 | |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 733 | void Manager::DeregisterDevice(const DeviceRefPtr &to_forget) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 734 | SLOG(Manager, 2) << __func__ << "(" << to_forget->FriendlyName() << ")"; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 735 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 736 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 737 | if (to_forget.get() == it->get()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 738 | SLOG(Manager, 2) << "Deregistered device: " << to_forget->UniqueName(); |
Paul Stewart | 212d60f | 2012-07-12 10:59:13 -0700 | [diff] [blame] | 739 | UpdateDevice(to_forget); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 740 | to_forget->SetEnabled(false); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 741 | devices_.erase(it); |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 742 | EmitDeviceProperties(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 743 | return; |
| 744 | } |
| 745 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 746 | SLOG(Manager, 2) << __func__ << " unknown device: " |
| 747 | << to_forget->UniqueName(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Paul Stewart | 87a4ae8 | 2012-10-26 15:49:32 -0700 | [diff] [blame] | 750 | void Manager::LoadDeviceFromProfiles(const DeviceRefPtr &device) { |
| 751 | // We are applying device properties from the DefaultProfile, and adding the |
| 752 | // union of hidden services in all loaded profiles to the device. |
| 753 | for (vector<ProfileRefPtr>::iterator it = profiles_.begin(); |
| 754 | it != profiles_.end(); ++it) { |
| 755 | // Load device configuration, if any exists, as well as hidden services. |
| 756 | (*it)->ConfigureDevice(device); |
| 757 | } |
| 758 | } |
| 759 | |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 760 | void Manager::EmitDeviceProperties() { |
| 761 | vector<DeviceRefPtr>::iterator it; |
| 762 | vector<string> device_paths; |
| 763 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 764 | device_paths.push_back((*it)->GetRpcIdentifier()); |
| 765 | } |
| 766 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kDevicesProperty, |
| 767 | device_paths); |
| 768 | Error error; |
| 769 | adaptor_->EmitStringsChanged(flimflam::kAvailableTechnologiesProperty, |
| 770 | AvailableTechnologies(&error)); |
| 771 | adaptor_->EmitStringsChanged(flimflam::kEnabledTechnologiesProperty, |
| 772 | EnabledTechnologies(&error)); |
| 773 | } |
| 774 | |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 775 | bool Manager::HasService(const ServiceRefPtr &service) { |
| 776 | vector<ServiceRefPtr>::iterator it; |
| 777 | for (it = services_.begin(); it != services_.end(); ++it) { |
| 778 | if ((*it)->UniqueName() == service->UniqueName()) |
| 779 | return true; |
| 780 | } |
| 781 | return false; |
| 782 | } |
| 783 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 784 | void Manager::RegisterService(const ServiceRefPtr &to_manage) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 785 | SLOG(Manager, 2) << "In " << __func__ << "(): Registering service " |
| 786 | << to_manage->UniqueName(); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 787 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 788 | MatchProfileWithService(to_manage); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 789 | |
| 790 | // Now add to OUR list. |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 791 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 792 | for (it = services_.begin(); it != services_.end(); ++it) { |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 793 | CHECK(to_manage->UniqueName() != (*it)->UniqueName()); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 794 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 795 | services_.push_back(to_manage); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 796 | SortServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 799 | void Manager::DeregisterService(const ServiceRefPtr &to_forget) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 800 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 801 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 802 | if (to_forget->UniqueName() == (*it)->UniqueName()) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 803 | DCHECK(!(*it)->connection()); |
Paul Stewart | fc9a1da | 2012-06-27 15:54:52 -0700 | [diff] [blame] | 804 | (*it)->Unload(); |
| 805 | (*it)->set_profile(NULL); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 806 | services_.erase(it); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 807 | SortServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 813 | bool Manager::UnloadService(vector<ServiceRefPtr>::iterator *service_iterator) { |
| 814 | if (!(**service_iterator)->Unload()) { |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | DCHECK(!(**service_iterator)->connection()); |
Paul Stewart | fc9a1da | 2012-06-27 15:54:52 -0700 | [diff] [blame] | 819 | (**service_iterator)->set_profile(NULL); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 820 | *service_iterator = services_.erase(*service_iterator); |
| 821 | |
| 822 | return true; |
| 823 | } |
| 824 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 825 | void Manager::UpdateService(const ServiceRefPtr &to_update) { |
| 826 | CHECK(to_update); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 827 | LOG(INFO) << "Service " << to_update->UniqueName() << " updated;" |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 828 | << " state: " << Service::ConnectStateToString(to_update->state()) |
| 829 | << " failure: " |
| 830 | << Service::ConnectFailureToString(to_update->failure()); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 831 | SLOG(Manager, 2) << "IsConnected(): " << to_update->IsConnected(); |
| 832 | SLOG(Manager, 2) << "IsConnecting(): " << to_update->IsConnecting(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 833 | if (to_update->IsConnected()) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 834 | to_update->MakeFavorite(); |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 835 | // Persists the updated favorite setting in the profile. |
| 836 | SaveServiceToProfile(to_update); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 837 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 838 | SortServices(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 841 | void Manager::UpdateDevice(const DeviceRefPtr &to_update) { |
| 842 | LOG(INFO) << "Device " << to_update->link_name() << " updated: " |
| 843 | << (to_update->enabled_persistent() ? "enabled" : "disabled"); |
| 844 | // Saves the device to the topmost profile that accepts it. Normally, this |
| 845 | // would be the only DefaultProfile at the bottom of the stack except in |
| 846 | // autotests that push a second test-only DefaultProfile. |
| 847 | for (vector<ProfileRefPtr>::reverse_iterator rit = profiles_.rbegin(); |
| 848 | rit != profiles_.rend(); ++rit) { |
| 849 | if ((*rit)->UpdateDevice(to_update)) { |
| 850 | return; |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 855 | void Manager::SaveServiceToProfile(const ServiceRefPtr &to_update) { |
| 856 | if (IsServiceEphemeral(to_update)) { |
| 857 | if (profiles_.empty()) { |
| 858 | LOG(ERROR) << "Cannot assign profile to service: no profiles exist!"; |
| 859 | } else { |
| 860 | MoveServiceToProfile(to_update, profiles_.back()); |
| 861 | } |
| 862 | } else { |
| 863 | to_update->profile()->UpdateService(to_update); |
| 864 | } |
| 865 | } |
| 866 | |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 867 | bool Manager::LoadProperties(const scoped_refptr<DefaultProfile> &profile) { |
| 868 | if (!profile->LoadManagerProperties(&props_)) { |
| 869 | return false; |
| 870 | } |
| 871 | SetIgnoredDNSSearchPaths(props_.ignored_dns_search_paths, NULL); |
| 872 | return true; |
| 873 | } |
| 874 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 875 | void Manager::AddTerminationAction(const string &name, |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 876 | const base::Closure &start) { |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 877 | if (termination_actions_.IsEmpty() && power_manager_.get()) { |
| 878 | power_manager_->AddSuspendDelayCallback( |
| 879 | kPowerManagerKey, |
| 880 | Bind(&Manager::OnSuspendDelay, AsWeakPtr())); |
| 881 | power_manager_->RegisterSuspendDelay( |
| 882 | kTerminationActionsTimeoutMilliseconds); |
| 883 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 884 | termination_actions_.Add(name, start); |
| 885 | } |
| 886 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 887 | void Manager::TerminationActionComplete(const string &name) { |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 888 | termination_actions_.ActionComplete(name); |
| 889 | } |
| 890 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 891 | void Manager::RemoveTerminationAction(const string &name) { |
| 892 | if (termination_actions_.IsEmpty()) { |
| 893 | return; |
| 894 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 895 | termination_actions_.Remove(name); |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 896 | if (termination_actions_.IsEmpty() && power_manager_.get()) { |
| 897 | power_manager_->UnregisterSuspendDelay(); |
| 898 | power_manager_->RemoveSuspendDelayCallback(kPowerManagerKey); |
| 899 | } |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void Manager::RunTerminationActions( |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 903 | const base::Callback<void(const Error &)> &done) { |
| 904 | LOG(INFO) << "Running termination actions."; |
| 905 | termination_actions_.Run(kTerminationActionsTimeoutMilliseconds, done); |
Gary Morain | a9fb325 | 2012-05-31 12:05:31 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 908 | bool Manager::RunTerminationActionsAndNotifyMetrics( |
| 909 | const base::Callback<void(const Error &)> &done, |
| 910 | Metrics::TerminationActionReason reason) { |
| 911 | if (termination_actions_.IsEmpty()) |
| 912 | return false; |
| 913 | |
| 914 | metrics_->NotifyTerminationActionsStarted(reason); |
| 915 | RunTerminationActions(done); |
| 916 | return true; |
| 917 | } |
| 918 | |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 919 | int Manager::RegisterDefaultServiceCallback(const ServiceCallback &callback) { |
| 920 | default_service_callbacks_[++default_service_callback_tag_] = callback; |
| 921 | return default_service_callback_tag_; |
| 922 | } |
| 923 | |
| 924 | void Manager::DeregisterDefaultServiceCallback(int tag) { |
| 925 | default_service_callbacks_.erase(tag); |
| 926 | } |
| 927 | |
| 928 | void Manager::NotifyDefaultServiceChanged(const ServiceRefPtr &service) { |
| 929 | for (map<int, ServiceCallback>::const_iterator it = |
| 930 | default_service_callbacks_.begin(); |
| 931 | it != default_service_callbacks_.end(); ++it) { |
| 932 | it->second.Run(service); |
| 933 | } |
| 934 | metrics_->NotifyDefaultServiceChanged(service); |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 935 | EmitDefaultService(); |
| 936 | } |
| 937 | |
| 938 | void Manager::EmitDefaultService() { |
| 939 | RpcIdentifier rpc_identifier = GetDefaultServiceRpcIdentifier(NULL); |
| 940 | if (rpc_identifier != default_service_rpc_identifier_) { |
| 941 | adaptor_->EmitRpcIdentifierChanged(shill::kDefaultServiceProperty, |
| 942 | rpc_identifier); |
| 943 | default_service_rpc_identifier_ = rpc_identifier; |
| 944 | } |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 945 | } |
| 946 | |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 947 | void Manager::OnPowerStateChanged( |
| 948 | PowerManagerProxyDelegate::SuspendState power_state) { |
| 949 | if (power_state == PowerManagerProxyDelegate::kOn) { |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 950 | vector<ServiceRefPtr>::iterator sit; |
| 951 | for (sit = services_.begin(); sit != services_.end(); ++sit) { |
| 952 | (*sit)->OnAfterResume(); |
| 953 | } |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 954 | SortServices(); |
mukesh agrawal | 784566d | 2012-08-08 18:32:58 -0700 | [diff] [blame] | 955 | vector<DeviceRefPtr>::iterator it; |
| 956 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 957 | (*it)->OnAfterResume(); |
| 958 | } |
| 959 | } else if (power_state == PowerManagerProxyDelegate::kMem) { |
| 960 | vector<DeviceRefPtr>::iterator it; |
| 961 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 962 | (*it)->OnBeforeSuspend(); |
| 963 | } |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 967 | void Manager::OnSuspendDelay(uint32 sequence_number) { |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 968 | if (!RunTerminationActionsAndNotifyMetrics( |
| 969 | Bind(&Manager::OnSuspendActionsComplete, AsWeakPtr(), sequence_number), |
| 970 | Metrics::kTerminationActionReasonSuspend)) { |
| 971 | LOG(INFO) << "No suspend actions were run."; |
| 972 | power_manager_->SuspendReady(sequence_number); |
| 973 | } |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | void Manager::OnSuspendActionsComplete(uint32 sequence_number, |
| 977 | const Error &error) { |
| 978 | LOG(INFO) << "Finished suspend actions. Result: " << error; |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 979 | metrics_->NotifyTerminationActionsCompleted( |
| 980 | Metrics::kTerminationActionReasonSuspend, error.IsSuccess()); |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 981 | power_manager_->SuspendReady(sequence_number); |
| 982 | } |
| 983 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 984 | void Manager::FilterByTechnology(Technology::Identifier tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 985 | vector<DeviceRefPtr> *found) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 986 | CHECK(found); |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 987 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 988 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Joshua Kroll | da79862 | 2012-06-05 12:30:48 -0700 | [diff] [blame] | 989 | if ((*it)->technology() == tech) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 990 | found->push_back(*it); |
| 991 | } |
| 992 | } |
| 993 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 994 | ServiceRefPtr Manager::FindService(const string& name) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 995 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 996 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 997 | if (name == (*it)->UniqueName()) |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 998 | return *it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 999 | } |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 1000 | return NULL; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Paul Stewart | 49739c0 | 2012-08-08 17:24:03 -0700 | [diff] [blame] | 1003 | void Manager::HelpRegisterConstDerivedRpcIdentifier( |
| 1004 | const string &name, |
| 1005 | RpcIdentifier(Manager::*get)(Error *error)) { |
| 1006 | store_.RegisterDerivedRpcIdentifier( |
| 1007 | name, |
| 1008 | RpcIdentifierAccessor( |
| 1009 | new CustomAccessor<Manager, RpcIdentifier>(this, get, NULL))); |
| 1010 | } |
| 1011 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 1012 | void Manager::HelpRegisterConstDerivedRpcIdentifiers( |
| 1013 | const string &name, |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 1014 | RpcIdentifiers(Manager::*get)(Error *error)) { |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 1015 | store_.RegisterDerivedRpcIdentifiers( |
| 1016 | name, |
| 1017 | RpcIdentifiersAccessor( |
| 1018 | new CustomAccessor<Manager, RpcIdentifiers>(this, get, NULL))); |
| 1019 | } |
| 1020 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1021 | void Manager::HelpRegisterDerivedString( |
| 1022 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1023 | string(Manager::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1024 | void(Manager::*set)(const string&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 1025 | store_.RegisterDerivedString( |
| 1026 | name, |
| 1027 | StringAccessor(new CustomAccessor<Manager, string>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1030 | void Manager::HelpRegisterDerivedStrings( |
| 1031 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1032 | Strings(Manager::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1033 | void(Manager::*set)(const Strings &, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 1034 | store_.RegisterDerivedStrings( |
| 1035 | name, |
| 1036 | StringsAccessor(new CustomAccessor<Manager, Strings>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1039 | void Manager::SortServices() { |
Paul Stewart | dfa4605 | 2012-06-26 09:44:14 -0700 | [diff] [blame] | 1040 | // We might be called in the middle of a series of events that |
| 1041 | // may result in multiple calls to Manager::SortServices, or within |
| 1042 | // an outer loop that may also be traversing the services_ list. |
| 1043 | // Defer this work to the event loop. |
| 1044 | if (sort_services_task_.IsCancelled()) { |
| 1045 | sort_services_task_.Reset(Bind(&Manager::SortServicesTask, AsWeakPtr())); |
| 1046 | dispatcher_->PostTask(sort_services_task_.callback()); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void Manager::SortServicesTask() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1051 | SLOG(Manager, 4) << "In " << __func__; |
Paul Stewart | dfa4605 | 2012-06-26 09:44:14 -0700 | [diff] [blame] | 1052 | sort_services_task_.Cancel(); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1053 | ServiceRefPtr default_service; |
| 1054 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1055 | if (!services_.empty()) { |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1056 | // Keep track of the service that is the candidate for the default |
| 1057 | // service. We have not yet tested to see if this service has a |
| 1058 | // connection. |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1059 | default_service = services_[0]; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1060 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1061 | sort(services_.begin(), services_.end(), ServiceSorter(technology_order_)); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1062 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1063 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kServicesProperty, |
Paul Stewart | bfb8255 | 2012-10-24 16:48:48 -0700 | [diff] [blame] | 1064 | EnumerateAvailableServices(NULL)); |
| 1065 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kServiceWatchListProperty, |
| 1066 | EnumerateWatchedServices(NULL)); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1067 | |
| 1068 | Error error; |
| 1069 | adaptor_->EmitStringsChanged(flimflam::kConnectedTechnologiesProperty, |
| 1070 | ConnectedTechnologies(&error)); |
| 1071 | adaptor_->EmitStringChanged(flimflam::kDefaultTechnologyProperty, |
| 1072 | DefaultTechnology(&error)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1073 | |
| 1074 | if (!services_.empty()) { |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1075 | ConnectionRefPtr default_connection = default_service->connection(); |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 1076 | if (default_connection && |
| 1077 | services_[0]->connection() != default_connection) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1078 | default_connection->SetIsDefault(false); |
| 1079 | } |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 1080 | if (services_[0]->connection()) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1081 | services_[0]->connection()->SetIsDefault(true); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 1082 | default_service = services_[0]; |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 1083 | } else { |
| 1084 | default_service = NULL; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 1085 | } |
| 1086 | } |
Darin Petkov | a5e07ef | 2012-07-09 14:27:57 +0200 | [diff] [blame] | 1087 | NotifyDefaultServiceChanged(default_service); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1088 | AutoConnect(); |
| 1089 | } |
| 1090 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 1091 | bool Manager::MatchProfileWithService(const ServiceRefPtr &service) { |
| 1092 | vector<ProfileRefPtr>::reverse_iterator it; |
| 1093 | for (it = profiles_.rbegin(); it != profiles_.rend(); ++it) { |
| 1094 | if ((*it)->ConfigureService(service)) { |
| 1095 | break; |
| 1096 | } |
| 1097 | } |
| 1098 | if (it == profiles_.rend()) { |
| 1099 | ephemeral_profile_->AdoptService(service); |
| 1100 | return false; |
| 1101 | } |
| 1102 | return true; |
| 1103 | } |
| 1104 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1105 | void Manager::AutoConnect() { |
Paul Stewart | 63864b6 | 2012-11-07 15:10:55 -0800 | [diff] [blame] | 1106 | if (!running_) { |
| 1107 | LOG(INFO) << "Auto-connect suppressed -- not running."; |
| 1108 | return; |
| 1109 | } |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 1110 | if (power_manager_.get() && |
| 1111 | power_manager_->power_state() != PowerManagerProxyDelegate::kOn && |
| 1112 | power_manager_->power_state() != PowerManagerProxyDelegate::kUnknown) { |
| 1113 | LOG(INFO) << "Auto-connect suppressed -- power state is not 'on'."; |
| 1114 | return; |
| 1115 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1116 | if (services_.empty()) { |
Darin Petkov | ca62154 | 2012-07-25 14:25:56 +0200 | [diff] [blame] | 1117 | LOG(INFO) << "Auto-connect suppressed -- no services."; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1118 | return; |
| 1119 | } |
| 1120 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1121 | if (SLOG_IS_ON(Manager, 4)) { |
| 1122 | SLOG(Manager, 4) << "Sorted service list: "; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1123 | for (size_t i = 0; i < services_.size(); ++i) { |
| 1124 | ServiceRefPtr service = services_[i]; |
| 1125 | const char *compare_reason = NULL; |
| 1126 | if (i + 1 < services_.size()) { |
| 1127 | Service::Compare( |
| 1128 | service, services_[i+1], technology_order_, &compare_reason); |
| 1129 | } else { |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1130 | compare_reason = "last"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1131 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1132 | SLOG(Manager, 4) << "Service " << service->friendly_name() |
| 1133 | << " IsConnected: " << service->IsConnected() |
| 1134 | << " IsConnecting: " << service->IsConnecting() |
| 1135 | << " IsFailed: " << service->IsFailed() |
| 1136 | << " connectable: " << service->connectable() |
| 1137 | << " auto_connect: " << service->auto_connect() |
| 1138 | << " favorite: " << service->favorite() |
| 1139 | << " priority: " << service->priority() |
| 1140 | << " security_level: " << service->security_level() |
| 1141 | << " strength: " << service->strength() |
| 1142 | << " UniqueName: " << service->UniqueName() |
| 1143 | << " sorted: " << compare_reason; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1147 | // Perform auto-connect. |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1148 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 1149 | it != services_.end(); ++it) { |
| 1150 | if ((*it)->auto_connect()) { |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1151 | (*it)->AutoConnect(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 1152 | } |
| 1153 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1156 | string Manager::CalculateState(Error */*error*/) { |
Gary Morain | 028545d | 2012-04-07 14:55:52 -0700 | [diff] [blame] | 1157 | // |services_| is sorted such that connected services are first. |
| 1158 | if (!services_.empty() && |
| 1159 | services_.front()->IsConnected()) { |
| 1160 | return flimflam::kStateOnline; |
| 1161 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1162 | return flimflam::kStateOffline; |
| 1163 | } |
| 1164 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1165 | vector<string> Manager::AvailableTechnologies(Error */*error*/) { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1166 | set<string> unique_technologies; |
| 1167 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1168 | it != devices_.end(); ++it) { |
| 1169 | unique_technologies.insert( |
| 1170 | Technology::NameFromIdentifier((*it)->technology())); |
| 1171 | } |
| 1172 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1175 | vector<string> Manager::ConnectedTechnologies(Error */*error*/) { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1176 | set<string> unique_technologies; |
| 1177 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1178 | it != devices_.end(); ++it) { |
| 1179 | if ((*it)->IsConnected()) |
| 1180 | unique_technologies.insert( |
| 1181 | Technology::NameFromIdentifier((*it)->technology())); |
| 1182 | } |
| 1183 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 1186 | string Manager::DefaultTechnology(Error */*error*/) { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 1187 | return (!services_.empty() && services_[0]->IsConnected()) ? |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 1188 | services_[0]->GetTechnologyString() : ""; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 1191 | vector<string> Manager::EnabledTechnologies(Error */*error*/) { |
| 1192 | set<string> unique_technologies; |
| 1193 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1194 | it != devices_.end(); ++it) { |
| 1195 | if ((*it)->enabled()) |
| 1196 | unique_technologies.insert( |
| 1197 | Technology::NameFromIdentifier((*it)->technology())); |
| 1198 | } |
| 1199 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Paul Stewart | cb3eb89 | 2012-06-07 14:24:46 -0700 | [diff] [blame] | 1202 | RpcIdentifiers Manager::EnumerateDevices(Error */*error*/) { |
| 1203 | RpcIdentifiers device_rpc_ids; |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 1204 | for (vector<DeviceRefPtr>::const_iterator it = devices_.begin(); |
| 1205 | it != devices_.end(); |
| 1206 | ++it) { |
| 1207 | device_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 1208 | } |
| 1209 | return device_rpc_ids; |
| 1210 | } |
| 1211 | |
Paul Stewart | cb3eb89 | 2012-06-07 14:24:46 -0700 | [diff] [blame] | 1212 | RpcIdentifiers Manager::EnumerateProfiles(Error */*error*/) { |
| 1213 | RpcIdentifiers profile_rpc_ids; |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1214 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 1215 | it != profiles_.end(); |
| 1216 | ++it) { |
| 1217 | profile_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 1218 | } |
| 1219 | return profile_rpc_ids; |
| 1220 | } |
| 1221 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1222 | vector<string> Manager::EnumerateAvailableServices(Error */*error*/) { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 1223 | vector<string> service_rpc_ids; |
| 1224 | for (vector<ServiceRefPtr>::const_iterator it = services_.begin(); |
| 1225 | it != services_.end(); |
| 1226 | ++it) { |
Paul Stewart | bfb8255 | 2012-10-24 16:48:48 -0700 | [diff] [blame] | 1227 | if ((*it)->IsVisible()) { |
| 1228 | service_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 1229 | } |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 1230 | } |
| 1231 | return service_rpc_ids; |
| 1232 | } |
| 1233 | |
Paul Stewart | bfb8255 | 2012-10-24 16:48:48 -0700 | [diff] [blame] | 1234 | RpcIdentifiers Manager::EnumerateWatchedServices(Error */*error*/) { |
| 1235 | vector<string> service_rpc_ids; |
| 1236 | for (vector<ServiceRefPtr>::const_iterator it = services_.begin(); |
| 1237 | it != services_.end(); |
| 1238 | ++it) { |
| 1239 | if ((*it)->IsVisible() && (*it)->IsActive(NULL)) { |
| 1240 | service_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 1241 | } |
| 1242 | } |
| 1243 | return service_rpc_ids; |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1246 | string Manager::GetActiveProfileRpcIdentifier(Error */*error*/) { |
| 1247 | return ActiveProfile()->GetRpcIdentifier(); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 1250 | string Manager::GetCheckPortalList(Error */*error*/) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 1251 | return use_startup_portal_list_ ? startup_portal_list_ : |
| 1252 | props_.check_portal_list; |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | void Manager::SetCheckPortalList(const string &portal_list, Error *error) { |
| 1256 | props_.check_portal_list = portal_list; |
| 1257 | use_startup_portal_list_ = false; |
| 1258 | } |
| 1259 | |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 1260 | string Manager::GetIgnoredDNSSearchPaths(Error */*error*/) { |
| 1261 | return props_.ignored_dns_search_paths; |
| 1262 | } |
| 1263 | |
| 1264 | void Manager::SetIgnoredDNSSearchPaths(const string &ignored_paths, |
| 1265 | Error */*error*/) { |
| 1266 | props_.ignored_dns_search_paths = ignored_paths; |
| 1267 | vector<string> ignored_path_list; |
| 1268 | if (!ignored_paths.empty()) { |
| 1269 | base::SplitString(ignored_paths, ',', &ignored_path_list); |
| 1270 | } |
| 1271 | resolver_->set_ignored_search_list(ignored_path_list); |
| 1272 | } |
| 1273 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1274 | // called via RPC (e.g., from ManagerDBusAdaptor) |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1275 | ServiceRefPtr Manager::GetService(const KeyValueStore &args, Error *error) { |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1276 | if (args.ContainsString(flimflam::kTypeProperty) && |
| 1277 | args.GetString(flimflam::kTypeProperty) == flimflam::kTypeVPN) { |
| 1278 | // GetService on a VPN service should actually perform ConfigureService. |
| 1279 | // TODO(pstew): Remove this hack and change Chrome to use ConfigureService |
| 1280 | // instead, when we no longer need to support flimflam. crosbug.com/31523 |
| 1281 | return ConfigureService(args, error); |
| 1282 | } |
| 1283 | return GetServiceInner(args, error); |
| 1284 | } |
| 1285 | |
| 1286 | ServiceRefPtr Manager::GetServiceInner(const KeyValueStore &args, |
| 1287 | Error *error) { |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1288 | if (args.ContainsString(flimflam::kGuidProperty)) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1289 | SLOG(Manager, 2) << __func__ << ": searching by GUID"; |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1290 | ServiceRefPtr service = |
| 1291 | GetServiceWithGUID(args.GetString(flimflam::kGuidProperty), NULL); |
| 1292 | if (service) { |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1293 | service->Configure(args, error); |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1294 | return service; |
| 1295 | } |
| 1296 | } |
| 1297 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1298 | if (!args.ContainsString(flimflam::kTypeProperty)) { |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1299 | Error::PopulateAndLog(error, Error::kInvalidArguments, kErrorTypeRequired); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1300 | return NULL; |
| 1301 | } |
| 1302 | |
| 1303 | string type = args.GetString(flimflam::kTypeProperty); |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 1304 | if (type == flimflam::kTypeVPN) { |
| 1305 | SLOG(Manager, 2) << __func__ << ": getting VPN Service"; |
| 1306 | return vpn_provider_.GetService(args, error); |
| 1307 | } |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1308 | if (type == flimflam::kTypeWifi) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1309 | SLOG(Manager, 2) << __func__ << ": getting WiFi Service"; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1310 | return GetWifiService(args, error); |
| 1311 | } |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 1312 | if (type == flimflam::kTypeWimax) { |
| 1313 | SLOG(Manager, 2) << __func__ << ": getting WiMAX Service"; |
| 1314 | return wimax_provider_.GetService(args, error); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1315 | } |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1316 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 1317 | kErrorUnsupportedServiceType); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1318 | return NULL; |
| 1319 | } |
| 1320 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1321 | WiFiServiceRefPtr Manager::GetWifiService(const KeyValueStore &args, |
| 1322 | Error *error) { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1323 | vector<DeviceRefPtr> wifi_devices; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1324 | FilterByTechnology(Technology::kWifi, &wifi_devices); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1325 | if (wifi_devices.empty()) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1326 | Error::PopulateAndLog(error, Error::kInvalidArguments, kErrorNoDevice); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1327 | return NULL; |
| 1328 | } else { |
| 1329 | WiFi *wifi = dynamic_cast<WiFi *>(wifi_devices.front().get()); |
| 1330 | CHECK(wifi); |
| 1331 | return wifi->GetService(args, error); |
| 1332 | } |
| 1333 | } |
| 1334 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1335 | // called via RPC (e.g., from ManagerDBusAdaptor) |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1336 | ServiceRefPtr Manager::ConfigureService(const KeyValueStore &args, |
| 1337 | Error *error) { |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1338 | ProfileRefPtr profile = ActiveProfile(); |
| 1339 | bool profile_specified = args.ContainsString(flimflam::kProfileProperty); |
| 1340 | if (profile_specified) { |
| 1341 | string profile_rpcid = args.GetString(flimflam::kProfileProperty); |
| 1342 | profile = LookupProfileByRpcIdentifier(profile_rpcid); |
| 1343 | if (!profile) { |
| 1344 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 1345 | "Invalid profile name " + profile_rpcid); |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1346 | return NULL; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1350 | ServiceRefPtr service = GetServiceInner(args, error); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1351 | if (error->IsFailure() || !service) { |
| 1352 | LOG(ERROR) << "GetService failed; returning upstream error."; |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1353 | return NULL; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1356 | // Overwrite the profile data with the resulting configured service. |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1357 | if (!profile->UpdateService(service)) { |
| 1358 | Error::PopulateAndLog(error, Error::kInternalError, |
| 1359 | "Unable to save service to profile"); |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1360 | return NULL; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | if (HasService(service)) { |
| 1364 | // If the service has been registered (it may not be -- as is the case |
| 1365 | // with invisible WiFi networks), we can now transfer the service between |
| 1366 | // profiles. |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1367 | if (IsServiceEphemeral(service) || |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1368 | (profile_specified && service->profile() != profile)) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1369 | SLOG(Manager, 2) << "Moving service to profile " |
| 1370 | << profile->GetFriendlyName(); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1371 | if (!MoveServiceToProfile(service, profile)) { |
| 1372 | Error::PopulateAndLog(error, Error::kInternalError, |
| 1373 | "Unable to move service to profile"); |
| 1374 | } |
| 1375 | } |
| 1376 | } |
Paul Stewart | 4357f4e | 2012-04-26 17:39:26 -0700 | [diff] [blame] | 1377 | |
| 1378 | // Notify the service that a profile has been configured for it. |
| 1379 | service->OnProfileConfigured(); |
Paul Stewart | 7f5ad57 | 2012-06-04 15:18:54 -0700 | [diff] [blame] | 1380 | |
| 1381 | return service; |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Gaurav Shah | b790aa2 | 2012-10-23 12:51:12 -0700 | [diff] [blame] | 1384 | map<string, GeolocationInfos> Manager::GetNetworksForGeolocation() { |
| 1385 | map<string, GeolocationInfos> networks; |
| 1386 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1387 | it != devices_.end(); ++it) { |
| 1388 | switch((*it)->technology()) { |
| 1389 | // TODO(gauravsh): crosbug.com/35736 Need a strategy for combining |
| 1390 | // geolocation objects from multiple devices of the same technolgy. |
| 1391 | // Currently, we just pick the geolocation objects from the first found |
| 1392 | // device of each supported technology type. |
| 1393 | case Technology::kWifi: |
| 1394 | if (!ContainsKey(networks, kGeoWifiAccessPointsProperty)) |
| 1395 | networks[kGeoWifiAccessPointsProperty] = |
| 1396 | (*it)->GetGeolocationObjects(); |
| 1397 | break; |
| 1398 | case Technology::kCellular: |
| 1399 | if (!ContainsKey(networks, kGeoCellTowersProperty)) |
| 1400 | networks[kGeoCellTowersProperty] = (*it)->GetGeolocationObjects(); |
| 1401 | break; |
| 1402 | default: |
| 1403 | // Ignore other technologies. |
| 1404 | break; |
| 1405 | }; |
| 1406 | } |
| 1407 | return networks; |
| 1408 | }; |
| 1409 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 1410 | void Manager::RecheckPortal(Error */*error*/) { |
| 1411 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1412 | it != devices_.end(); ++it) { |
| 1413 | if ((*it)->RequestPortalDetection()) { |
| 1414 | // Only start Portal Detection on the device with the default connection. |
| 1415 | // We will get a "true" return value when we've found that device, and |
| 1416 | // can end our loop early as a result. |
| 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1422 | void Manager::RecheckPortalOnService(const ServiceRefPtr &service) { |
| 1423 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1424 | it != devices_.end(); ++it) { |
| 1425 | if ((*it)->IsConnectedToService(service)) { |
| 1426 | // As opposed to RecheckPortal() above, we explicitly stop and then |
| 1427 | // restart portal detection, since the service to recheck was explicitly |
| 1428 | // specified. |
| 1429 | (*it)->RestartPortalDetection(); |
| 1430 | break; |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1435 | // called via RPC (e.g., from ManagerDBusAdaptor) |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1436 | void Manager::RequestScan(const string &technology, Error *error) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1437 | if (technology == flimflam::kTypeWifi || technology == "") { |
| 1438 | vector<DeviceRefPtr> wifi_devices; |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 1439 | FilterByTechnology(Technology::kWifi, &wifi_devices); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1440 | |
| 1441 | for (vector<DeviceRefPtr>::iterator it = wifi_devices.begin(); |
| 1442 | it != wifi_devices.end(); |
| 1443 | ++it) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 1444 | (*it)->Scan(error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } else { |
| 1447 | // TODO(quiche): support scanning for other technologies? |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 1448 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 1449 | "Unrecognized technology " + technology); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1453 | string Manager::GetTechnologyOrder() { |
| 1454 | vector<string> technology_names; |
| 1455 | for (vector<Technology::Identifier>::iterator it = technology_order_.begin(); |
| 1456 | it != technology_order_.end(); |
| 1457 | ++it) { |
| 1458 | technology_names.push_back(Technology::NameFromIdentifier(*it)); |
| 1459 | } |
| 1460 | |
| 1461 | return JoinString(technology_names, ','); |
| 1462 | } |
| 1463 | |
| 1464 | void Manager::SetTechnologyOrder(const string &order, Error *error) { |
| 1465 | vector<Technology::Identifier> new_order; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1466 | SLOG(Manager, 2) << "Setting technology order to " << order; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 1467 | if (!Technology::GetTechnologyVectorFromString(order, &new_order, error)) { |
| 1468 | return; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | technology_order_ = new_order; |
| 1472 | SortServices(); |
| 1473 | } |
| 1474 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1475 | } // namespace shill |