Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 1 | // 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 Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 6 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 7 | #include <string> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 8 | |
| 9 | #include <base/logging.h> |
| 10 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 11 | #include "update_engine/marshal.glibmarshal.h" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 12 | #include "update_engine/omaha_request_params.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 13 | #include "update_engine/utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 14 | |
| 15 | using std::string; |
| 16 | |
| 17 | G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT) |
| 18 | |
| 19 | static void update_engine_service_finalize(GObject* object) { |
| 20 | G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object); |
| 21 | } |
| 22 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 23 | static guint status_update_signal = 0; |
| 24 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 25 | static 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 Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 29 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 30 | 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 Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void update_engine_service_init(UpdateEngineService* object) { |
| 48 | } |
| 49 | |
| 50 | UpdateEngineService* update_engine_service_new(void) { |
| 51 | return reinterpret_cast<UpdateEngineService*>( |
| 52 | g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
| 53 | } |
| 54 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 55 | gboolean update_engine_service_attempt_update(UpdateEngineService* self, |
| 56 | gchar* app_version, |
| 57 | gchar* omaha_url, |
| 58 | GError **error) { |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 59 | 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 Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 71 | LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" " |
| 72 | << "omaha_url=\"" << update_omaha_url << "\""; |
Darin Petkov | ba3fb17 | 2010-10-20 14:35:01 -0700 | [diff] [blame] | 73 | self->update_attempter_->CheckForUpdate(update_app_version, update_omaha_url); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 74 | return TRUE; |
| 75 | } |
| 76 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 77 | gboolean 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 Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 86 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 87 | CHECK(self->update_attempter_->GetStatus(last_checked_time, |
| 88 | progress, |
| 89 | ¤t_op, |
| 90 | &new_version_str, |
| 91 | new_size)); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 92 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 93 | *current_operation = strdup(current_op.c_str()); |
| 94 | *new_version = strdup(new_version_str.c_str()); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 95 | if (!(*current_operation && *new_version)) { |
| 96 | *error = NULL; |
| 97 | return FALSE; |
| 98 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 99 | return TRUE; |
| 100 | } |
| 101 | |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame^] | 102 | gboolean update_engine_service_get_track(UpdateEngineService* self, |
| 103 | gchar** track, |
| 104 | GError **error) { |
| 105 | string track_str = |
| 106 | chromeos_update_engine::OmahaRequestDeviceParams::GetDeviceTrack(); |
| 107 | *track = strdup(track_str.c_str()); |
| 108 | return TRUE; |
| 109 | } |
| 110 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 111 | gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 112 | GError **error) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 113 | if (!self->update_attempter_->RebootIfNeeded()) { |
| 114 | *error = NULL; |
| 115 | return FALSE; |
| 116 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 117 | return TRUE; |
| 118 | } |
| 119 | |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 120 | gboolean update_engine_service_set_track(UpdateEngineService* self, |
| 121 | gchar* track, |
| 122 | GError **error) { |
| 123 | if (track) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 124 | LOG(INFO) << "Setting track to: " << track; |
| 125 | if (!chromeos_update_engine::OmahaRequestDeviceParams::SetDeviceTrack( |
| 126 | track)) { |
| 127 | *error = NULL; |
| 128 | return FALSE; |
| 129 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 130 | } |
| 131 | return TRUE; |
| 132 | } |
| 133 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 134 | gboolean 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 | } |