blob: 63fbf501da1f2c841d4166e63c3211ef782be261 [file] [log] [blame]
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/dbus_service.h"
Darin Petkova07586b2010-10-20 13:41:15 -07006
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07007#include <string>
Darin Petkova07586b2010-10-20 13:41:15 -07008
9#include <base/logging.h>
10
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070011#include "update_engine/marshal.glibmarshal.h"
Darin Petkova07586b2010-10-20 13:41:15 -070012#include "update_engine/utils.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070013
14using std::string;
15
16G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
17
18static void update_engine_service_finalize(GObject* object) {
19 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
20}
21
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070022static guint status_update_signal = 0;
23
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070024static void update_engine_service_class_init(UpdateEngineServiceClass* klass) {
25 GObjectClass *object_class;
26 object_class = G_OBJECT_CLASS(klass);
27 object_class->finalize = update_engine_service_finalize;
Darin Petkov5a7f5652010-07-22 21:40:09 -070028
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070029 status_update_signal = g_signal_new(
30 "status_update",
31 G_OBJECT_CLASS_TYPE(klass),
32 G_SIGNAL_RUN_LAST,
33 0, // 0 == no class method associated
34 NULL, // Accumulator
35 NULL, // Accumulator data
36 update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64,
37 G_TYPE_NONE, // Return type
38 5, // param count:
39 G_TYPE_INT64,
40 G_TYPE_DOUBLE,
41 G_TYPE_STRING,
42 G_TYPE_STRING,
43 G_TYPE_INT64);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070044}
45
46static void update_engine_service_init(UpdateEngineService* object) {
47}
48
49UpdateEngineService* update_engine_service_new(void) {
50 return reinterpret_cast<UpdateEngineService*>(
51 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
52}
53
Darin Petkov296889c2010-07-23 16:20:54 -070054gboolean update_engine_service_attempt_update(UpdateEngineService* self,
55 gchar* app_version,
56 gchar* omaha_url,
57 GError **error) {
Darin Petkova07586b2010-10-20 13:41:15 -070058 string update_app_version;
59 string update_omaha_url;
60 // Only non-official (e.g., dev and test) builds can override the current
61 // version and update server URL over D-Bus.
62 if (!chromeos_update_engine::utils::IsOfficialBuild()) {
63 if (app_version) {
64 update_app_version = app_version;
65 }
66 if (omaha_url) {
67 update_omaha_url = omaha_url;
68 }
69 }
Darin Petkov296889c2010-07-23 16:20:54 -070070 LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
71 << "omaha_url=\"" << update_omaha_url << "\"";
72 self->update_attempter_->CheckForUpdate(app_version, omaha_url);
73 return TRUE;
74}
75
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070076gboolean update_engine_service_get_status(UpdateEngineService* self,
77 int64_t* last_checked_time,
78 double* progress,
79 gchar** current_operation,
80 gchar** new_version,
81 int64_t* new_size,
82 GError **error) {
83 string current_op;
84 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -070085
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070086 CHECK(self->update_attempter_->GetStatus(last_checked_time,
87 progress,
88 &current_op,
89 &new_version_str,
90 new_size));
Darin Petkov5a7f5652010-07-22 21:40:09 -070091
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070092 *current_operation = strdup(current_op.c_str());
93 *new_version = strdup(new_version_str.c_str());
Chris Masonec6c57a52010-09-23 13:06:14 -070094 if (!(*current_operation && *new_version)) {
95 *error = NULL;
96 return FALSE;
97 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070098 return TRUE;
99}
100
Darin Petkov296889c2010-07-23 16:20:54 -0700101gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700102 GError **error) {
Darin Petkov296889c2010-07-23 16:20:54 -0700103 if (!self->update_attempter_->RebootIfNeeded()) {
104 *error = NULL;
105 return FALSE;
106 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700107 return TRUE;
108}
109
110gboolean update_engine_service_emit_status_update(
111 UpdateEngineService* self,
112 gint64 last_checked_time,
113 gdouble progress,
114 const gchar* current_operation,
115 const gchar* new_version,
116 gint64 new_size) {
117 g_signal_emit(self,
118 status_update_signal,
119 0,
120 last_checked_time,
121 progress,
122 current_operation,
123 new_version,
124 new_size);
125 return TRUE;
126}