Refactor daemon state and service async notification.
There are three supported IPC mechanism in this code: DBus, binder and
weave (over binder); which are mostly supported by all three platforms
Chrome OS, Brillo and Android. The exceptions are that Brillo and
Chrome OS still *require* DBus and support the others, while the new
Android daemon requires and supports only Binder.
This CL introduces two new interfaces: the ServiceObserverInterface and
the DaemonStateInterface.
The first one abstracts a service (or IPC service) into an interfcae
from the point of view of the daemon initialization and async
notifications of status changes. The second interface encapsulates the
state and main functionality of the update_engine daemon while leaving
the shared initialization in the main.cc and daemon.cc classes.
Bug: 25631949
TEST=`mmma system/update_engine` on edison-eng and aosp_arm-eng
TEST=FEATURES=test emerge-link update_engine
Change-Id: Ic15621031a153e14bdc4df8fcedbca1032e82c21
diff --git a/update_attempter.h b/update_attempter.h
index 2401d60..2f53869 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -20,6 +20,7 @@
#include <time.h>
#include <memory>
+#include <set>
#include <string>
#include <utility>
#include <vector>
@@ -28,10 +29,6 @@
#include <base/time/time.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#if USE_BINDER
-#include "update_engine/binder_service.h"
-#endif // USE_BINDER
-
#include "debugd/dbus-proxies.h"
#include "update_engine/chrome_browser_proxy_resolver.h"
#include "update_engine/client_library/include/update_engine/update_status.h"
@@ -42,6 +39,7 @@
#include "update_engine/omaha_response_handler_action.h"
#include "update_engine/payload_consumer/download_action.h"
#include "update_engine/proxy_resolver.h"
+#include "update_engine/service_observer_interface.h"
#include "update_engine/system_state.h"
#include "update_engine/update_manager/policy.h"
#include "update_engine/update_manager/update_manager.h"
@@ -138,16 +136,6 @@
int http_response_code() const { return http_response_code_; }
void set_http_response_code(int code) { http_response_code_ = code; }
- void set_dbus_adaptor(UpdateEngineAdaptor* dbus_adaptor) {
- dbus_adaptor_ = dbus_adaptor;
- }
-
-#if USE_BINDER
- void set_binder_service(BinderUpdateEngineService* service) {
- binder_service_ = service;
- }
-#endif
-
// This is the internal entry point for going through an
// update. If the current status is idle invokes Update.
// This is called by the DBus implementation.
@@ -184,9 +172,12 @@
void DownloadComplete() override;
- // Broadcasts the current status over D-Bus.
+ // Broadcasts the current status to all observers.
void BroadcastStatus();
+ // Broadcasts the current tracking channel to all observers.
+ void BroadcastChannel();
+
// Returns the special flags to be added to ErrorCode values based on the
// parameters used in the current update attempt.
uint32_t GetErrorCodeFlags();
@@ -239,6 +230,17 @@
// 'cros flash' to function properly).
virtual bool IsAnyUpdateSourceAllowed();
+ // Add and remove a service observer.
+ void AddObserver(ServiceObserverInterface* observer) {
+ service_observers_.insert(observer);
+ }
+ void RemoveObserver(ServiceObserverInterface* observer) {
+ service_observers_.erase(observer);
+ }
+
+ // Remove all the observers.
+ void ClearObservers() { service_observers_.clear(); }
+
private:
// Update server URL for automated lab test.
static const char* const kTestUpdateUrl;
@@ -421,15 +423,8 @@
// Pointer to the certificate checker instance to use.
CertificateChecker* cert_checker_;
- // If non-null, this UpdateAttempter will send status updates over this
- // dbus service.
- UpdateEngineAdaptor* dbus_adaptor_ = nullptr;
-
-#if USE_BINDER
- // If non-null, this UpdateAttempter will send status updates over this
- // binder interface.
- BinderUpdateEngineService* binder_service_ = nullptr;
-#endif // USE_BINDER
+ // The list of services observing changes in the updater.
+ std::set<ServiceObserverInterface*> service_observers_;
// Pointer to the OmahaResponseHandlerAction in the actions_ vector.
std::shared_ptr<OmahaResponseHandlerAction> response_handler_action_;