blob: 5a1a1056e3dbd57fb828c9aade3616a7d2320e03 [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 Petkov49d91322010-10-25 16:34:58 -070012#include "update_engine/omaha_request_params.h"
Darin Petkova07586b2010-10-20 13:41:15 -070013#include "update_engine/utils.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070014
15using std::string;
16
17G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
18
19static void update_engine_service_finalize(GObject* object) {
20 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
21}
22
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070023static guint status_update_signal = 0;
24
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070025static void update_engine_service_class_init(UpdateEngineServiceClass* klass) {
26 GObjectClass *object_class;
27 object_class = G_OBJECT_CLASS(klass);
28 object_class->finalize = update_engine_service_finalize;
Darin Petkov5a7f5652010-07-22 21:40:09 -070029
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070030 status_update_signal = g_signal_new(
31 "status_update",
32 G_OBJECT_CLASS_TYPE(klass),
33 G_SIGNAL_RUN_LAST,
34 0, // 0 == no class method associated
35 NULL, // Accumulator
36 NULL, // Accumulator data
37 update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64,
38 G_TYPE_NONE, // Return type
39 5, // param count:
40 G_TYPE_INT64,
41 G_TYPE_DOUBLE,
42 G_TYPE_STRING,
43 G_TYPE_STRING,
44 G_TYPE_INT64);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070045}
46
47static void update_engine_service_init(UpdateEngineService* object) {
48}
49
50UpdateEngineService* update_engine_service_new(void) {
51 return reinterpret_cast<UpdateEngineService*>(
52 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
53}
54
Darin Petkov296889c2010-07-23 16:20:54 -070055gboolean update_engine_service_attempt_update(UpdateEngineService* self,
56 gchar* app_version,
57 gchar* omaha_url,
58 GError **error) {
Darin Petkova07586b2010-10-20 13:41:15 -070059 string update_app_version;
60 string update_omaha_url;
61 // Only non-official (e.g., dev and test) builds can override the current
62 // version and update server URL over D-Bus.
63 if (!chromeos_update_engine::utils::IsOfficialBuild()) {
64 if (app_version) {
65 update_app_version = app_version;
66 }
67 if (omaha_url) {
68 update_omaha_url = omaha_url;
69 }
70 }
Darin Petkov296889c2010-07-23 16:20:54 -070071 LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
72 << "omaha_url=\"" << update_omaha_url << "\"";
Darin Petkovba3fb172010-10-20 14:35:01 -070073 self->update_attempter_->CheckForUpdate(update_app_version, update_omaha_url);
Darin Petkov296889c2010-07-23 16:20:54 -070074 return TRUE;
75}
76
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070077gboolean update_engine_service_get_status(UpdateEngineService* self,
78 int64_t* last_checked_time,
79 double* progress,
80 gchar** current_operation,
81 gchar** new_version,
82 int64_t* new_size,
83 GError **error) {
84 string current_op;
85 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -070086
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070087 CHECK(self->update_attempter_->GetStatus(last_checked_time,
88 progress,
89 &current_op,
90 &new_version_str,
91 new_size));
Darin Petkov5a7f5652010-07-22 21:40:09 -070092
Satoru Takabayashid6982312010-11-29 12:54:12 +090093 *current_operation = g_strdup(current_op.c_str());
94 *new_version = g_strdup(new_version_str.c_str());
Chris Masonec6c57a52010-09-23 13:06:14 -070095 if (!(*current_operation && *new_version)) {
96 *error = NULL;
97 return FALSE;
98 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070099 return TRUE;
100}
101
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900102gboolean update_engine_service_get_track(UpdateEngineService* self,
103 gchar** track,
104 GError **error) {
105 string track_str =
106 chromeos_update_engine::OmahaRequestDeviceParams::GetDeviceTrack();
Satoru Takabayashid6982312010-11-29 12:54:12 +0900107 *track = g_strdup(track_str.c_str());
Satoru Takabayashi583667b2010-10-27 13:09:57 +0900108 return TRUE;
109}
110
Darin Petkov296889c2010-07-23 16:20:54 -0700111gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700112 GError **error) {
Darin Petkov296889c2010-07-23 16:20:54 -0700113 if (!self->update_attempter_->RebootIfNeeded()) {
114 *error = NULL;
115 return FALSE;
116 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700117 return TRUE;
118}
119
Darin Petkov8daa3242010-10-25 13:28:47 -0700120gboolean update_engine_service_set_track(UpdateEngineService* self,
121 gchar* track,
122 GError **error) {
123 if (track) {
Darin Petkov49d91322010-10-25 16:34:58 -0700124 LOG(INFO) << "Setting track to: " << track;
125 if (!chromeos_update_engine::OmahaRequestDeviceParams::SetDeviceTrack(
126 track)) {
127 *error = NULL;
128 return FALSE;
129 }
Darin Petkov8daa3242010-10-25 13:28:47 -0700130 }
131 return TRUE;
132}
133
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700134gboolean update_engine_service_emit_status_update(
135 UpdateEngineService* self,
136 gint64 last_checked_time,
137 gdouble progress,
138 const gchar* current_operation,
139 const gchar* new_version,
140 gint64 new_size) {
141 g_signal_emit(self,
142 status_update_signal,
143 0,
144 last_checked_time,
145 progress,
146 current_operation,
147 new_version,
148 new_size);
149 return TRUE;
150}