update_engine: Move P2P enabled pref handling into P2PManager.
This makes the P2PManager own the manipulation of the P2P enabled
setting, which positions us better toward moving the decision about
whether P2P is enabled from P2PManager and into the UpdateManager. Also
increases encapsulation and makes it a bit more resilient.
BUG=chromium:425233
TEST=Unit tests.
Change-Id: Ic91872df84920ae80c5ef973aee99cc46cac264c
Reviewed-on: https://chromium-review.googlesource.com/225681
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/dbus_service.cc b/dbus_service.cc
index e7b877d..ccd175f 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -9,6 +9,7 @@
#include <base/logging.h>
#include <base/strings/stringprintf.h>
+#include <chromeos/strings/string_utils.h>
#include <policy/device_policy.h>
#include "update_engine/clock_interface.h"
@@ -21,6 +22,8 @@
#include "update_engine/update_attempter.h"
#include "update_engine/utils.h"
+using base::StringPrintf;
+using chromeos::string_utils::ToString;
using std::set;
using std::string;
using chromeos_update_engine::AttemptUpdateFlags;
@@ -352,25 +355,18 @@
UpdateEngineService* self,
gboolean enabled,
GError **error) {
- chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs();
chromeos_update_engine::P2PManager* p2p_manager =
self->system_state_->p2p_manager();
- bool p2p_was_enabled = p2p_manager && p2p_manager->IsP2PEnabled();
-
- if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) {
+ if (!(p2p_manager &&
+ p2p_manager->SetP2PEnabledPref(enabled))) {
log_and_set_response_error(
error, UPDATE_ENGINE_SERVICE_ERROR_FAILED,
- string("Error setting the update over cellular to ") +
- (enabled ? "true." : "false."));
+ StringPrintf("Error setting the update via p2p permission to %s.",
+ ToString(enabled).c_str()));
return FALSE;
}
- // If P2P is being effectively disabled (IsP2PEnabled() reports the change)
- // then we need to shutdown the service.
- if (p2p_was_enabled && !p2p_manager->IsP2PEnabled())
- p2p_manager->EnsureP2PNotRunning();
-
return TRUE;
}