shill: Rename MergeService to ConfigureService
Collateral changes: Use ContainsService internally to profile's
ConfigureService. Refrain from using Service::GetStorageIdentifier
directly. I can think of scenarios coming up where it is important
for the Service to determine for itself whether a StorageInterface
contains anything it can use.
BUG=chromium-os:22422
TEST=ReRun Unit Tests
Change-Id: I34c6cb272c1540ab1e8d8d9bed4083b52e20f75e
Reviewed-on: https://gerrit.chromium.org/gerrit/11099
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/manager.cc b/manager.cc
index 4bd3be8..2b21f24 100644
--- a/manager.cc
+++ b/manager.cc
@@ -233,7 +233,7 @@
// Offer each registered Service the opportunity to join this new Profile.
vector<ServiceRefPtr>::iterator it;
for (it = services_.begin(); it != services_.end(); ++it) {
- profile->MergeService(*it);
+ profile->ConfigureService(*it);
}
// TODO(pstew): Now shop the Profile contents around to Devices which
@@ -249,7 +249,7 @@
if ((*s_it)->profile().get() == active_profile.get()) {
vector<ProfileRefPtr>::reverse_iterator p_it;
for (p_it = profiles_.rbegin(); p_it != profiles_.rend(); ++p_it) {
- if ((*p_it)->MergeService(*s_it)) {
+ if ((*p_it)->ConfigureService(*s_it)) {
break;
}
}
@@ -347,15 +347,15 @@
void Manager::RegisterService(const ServiceRefPtr &to_manage) {
VLOG(2) << __func__ << to_manage->UniqueName();
- bool merged = false;
+ bool configured = false;
for (vector<ProfileRefPtr>::iterator it = profiles_.begin();
- !merged && it != profiles_.end();
+ !configured && it != profiles_.end();
++it) {
- merged = (*it)->MergeService(to_manage); // Will merge, if possible.
+ configured = (*it)->ConfigureService(to_manage);
}
// If not found, add it to the ephemeral profile
- if (!merged)
+ if (!configured)
ephemeral_profile_->AdoptService(to_manage);
// Now add to OUR list.
diff --git a/profile.cc b/profile.cc
index 46d979e..d87bbf2 100644
--- a/profile.cc
+++ b/profile.cc
@@ -146,15 +146,15 @@
return service->Save(storage_.get()) && storage_->Flush();
}
-bool Profile::MergeService(const ServiceRefPtr &service) {
- if (!storage_->ContainsGroup(service->GetStorageIdentifier()))
+bool Profile::ConfigureService(const ServiceRefPtr &service) {
+ if (!ContainsService(service))
return false;
service->set_profile(this);
return service->Load(storage_.get());
}
bool Profile::ContainsService(const ServiceConstRefPtr &service) {
- return storage_->ContainsGroup(service->GetStorageIdentifier());
+ return service->IsLoadableFrom(storage_.get());
}
bool Profile::IsValidIdentifierToken(const std::string &token) {
diff --git a/profile.h b/profile.h
index abde66a..b694eef 100644
--- a/profile.h
+++ b/profile.h
@@ -81,10 +81,12 @@
// Returns true if |service| was found and updated, false if not found.
bool UpdateService(const ServiceRefPtr &service);
- // Determine if |service| represents a service that's already in |services_|.
- // If so, merge them smartly and return true. If not, return false.
- bool MergeService(const ServiceRefPtr &service);
+ // Ask |service| if it can configure itself from the profile. If it can,
+ // change the service to point at this profile, ask |service| to perform
+ // the configuration and return true. If not, return false.
+ bool ConfigureService(const ServiceRefPtr &service);
+ // Return whether |service| can configure itself from the profile.
bool ContainsService(const ServiceConstRefPtr &service);
std::vector<std::string> EnumerateAvailableServices();
diff --git a/profile_unittest.cc b/profile_unittest.cc
index 99be2bc..f352671 100644
--- a/profile_unittest.cc
+++ b/profile_unittest.cc
@@ -177,7 +177,7 @@
ASSERT_FALSE(profile_->ContainsService(service2));
}
-TEST_F(ProfileTest, ServiceMerge) {
+TEST_F(ProfileTest, ServiceConfigure) {
ServiceRefPtr service1(new ServiceUnderTest(control_interface(),
dispatcher(),
manager()));
@@ -191,7 +191,7 @@
dispatcher(),
manager()));
bool orig_favorite = service2->favorite();
- ASSERT_TRUE(profile_->MergeService(service2));
+ ASSERT_TRUE(profile_->ConfigureService(service2));
ASSERT_EQ(service1->favorite(), service2->favorite());
ASSERT_NE(orig_favorite, service2->favorite());
diff --git a/service.cc b/service.cc
index bd35971..759563e 100644
--- a/service.cc
+++ b/service.cc
@@ -199,6 +199,10 @@
return adaptor_->GetRpcIdentifier();
}
+bool Service::IsLoadableFrom(StoreInterface *storage) const {
+ return storage->ContainsGroup(GetStorageIdentifier());
+}
+
bool Service::Load(StoreInterface *storage) {
const string id = GetStorageIdentifier();
if (!storage->ContainsGroup(id)) {
diff --git a/service.h b/service.h
index 9738994..b6b8bbe 100644
--- a/service.h
+++ b/service.h
@@ -127,6 +127,9 @@
// Returns the unique persistent storage identifier for the service.
virtual std::string GetStorageIdentifier() const = 0;
+ // Returns whether the service configuration can be loaded from |storage|.
+ virtual bool IsLoadableFrom(StoreInterface *storage) const;
+
// Loads the service from persistent |storage|. Returns true on success.
virtual bool Load(StoreInterface *storage);