| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <tr1/memory> | 6 #include <tr1/memory> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include <gflags/gflags.h> | 9 #include <gflags/gflags.h> |
| 10 #include <glib.h> | 10 #include <glib.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "chromeos/obsolete_logging.h" | 13 #include "chromeos/obsolete_logging.h" |
| 14 #include "metrics/metrics_library.h" | 14 #include "metrics/metrics_library.h" |
| 15 #include "update_engine/dbus_constants.h" | 15 #include "update_engine/dbus_constants.h" |
| 16 #include "update_engine/dbus_service.h" | 16 #include "update_engine/dbus_service.h" |
| 17 #include "update_engine/prefs.h" | 17 #include "update_engine/prefs.h" |
| 18 #include "update_engine/update_attempter.h" | 18 #include "update_engine/update_attempter.h" |
| 19 #include "update_engine/utils.h" |
| 19 | 20 |
| 20 extern "C" { | 21 extern "C" { |
| 21 #include "update_engine/update_engine.dbusserver.h" | 22 #include "update_engine/update_engine.dbusserver.h" |
| 22 } | 23 } |
| 23 | 24 |
| 24 DEFINE_bool(logtostderr, false, | 25 DEFINE_bool(logtostderr, false, |
| 25 "Write logs to stderr instead of to a file in log_dir."); | 26 "Write logs to stderr instead of to a file in log_dir."); |
| 26 DEFINE_bool(foreground, false, | 27 DEFINE_bool(foreground, false, |
| 27 "Don't daemon()ize; run in foreground."); | 28 "Don't daemon()ize; run in foreground."); |
| 28 | 29 |
| 29 using std::string; | 30 using std::string; |
| 30 using std::tr1::shared_ptr; | 31 using std::tr1::shared_ptr; |
| 31 using std::vector; | 32 using std::vector; |
| 32 | 33 |
| 33 namespace chromeos_update_engine { | 34 namespace chromeos_update_engine { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 struct PeriodicallyUpdateArgs { | 38 gboolean UpdateOnce(void* arg) { |
| 38 UpdateAttempter* update_attempter; | 39 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); |
| 39 gboolean should_repeat; | 40 update_attempter->Update("", ""); |
| 40 }; | 41 return FALSE; |
| 42 } |
| 41 | 43 |
| 42 gboolean PeriodicallyUpdate(void* arg) { | 44 gboolean UpdatePeriodically(void* arg) { |
| 43 PeriodicallyUpdateArgs* args = reinterpret_cast<PeriodicallyUpdateArgs*>(arg); | 45 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); |
| 44 args->update_attempter->Update("", ""); | 46 update_attempter->Update("", ""); |
| 45 return args->should_repeat; | 47 return TRUE; |
| 48 } |
| 49 |
| 50 void SchedulePeriodicUpdateChecks(UpdateAttempter* update_attempter) { |
| 51 if (!utils::IsOfficialBuild()) { |
| 52 LOG(WARNING) << "No periodic update checks on non-official builds."; |
| 53 return; |
| 54 } |
| 55 |
| 56 // Kick off periodic updating. First, update after 2 minutes. Also, update |
| 57 // every 30 minutes. |
| 58 g_timeout_add(2 * 60 * 1000, &UpdateOnce, update_attempter); |
| 59 g_timeout_add(30 * 60 * 1000, &UpdatePeriodically, update_attempter); |
| 46 } | 60 } |
| 47 | 61 |
| 48 void SetupDbusService(UpdateEngineService* service) { | 62 void SetupDbusService(UpdateEngineService* service) { |
| 49 DBusGConnection *bus; | 63 DBusGConnection *bus; |
| 50 DBusGProxy *proxy; | 64 DBusGProxy *proxy; |
| 51 GError *error = NULL; | 65 GError *error = NULL; |
| 52 | 66 |
| 53 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 67 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
| 54 if (!bus) { | 68 if (!bus) { |
| 55 LOG(FATAL) << "Failed to get bus"; | 69 LOG(FATAL) << "Failed to get bus"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 133 |
| 120 // Create the dbus service object: | 134 // Create the dbus service object: |
| 121 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, | 135 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, |
| 122 &dbus_glib_update_engine_service_object_info); | 136 &dbus_glib_update_engine_service_object_info); |
| 123 UpdateEngineService* service = | 137 UpdateEngineService* service = |
| 124 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); | 138 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
| 125 service->update_attempter_ = &update_attempter; | 139 service->update_attempter_ = &update_attempter; |
| 126 update_attempter.set_dbus_service(service); | 140 update_attempter.set_dbus_service(service); |
| 127 chromeos_update_engine::SetupDbusService(service); | 141 chromeos_update_engine::SetupDbusService(service); |
| 128 | 142 |
| 129 // Kick off periodic updating. First, update after 2 minutes. Also, update | 143 chromeos_update_engine::SchedulePeriodicUpdateChecks(&update_attempter); |
| 130 // every 30 minutes. | |
| 131 chromeos_update_engine::PeriodicallyUpdateArgs two_min_args = | |
| 132 {&update_attempter, FALSE}; | |
| 133 g_timeout_add(2 * 60 * 1000, | |
| 134 &chromeos_update_engine::PeriodicallyUpdate, | |
| 135 &two_min_args); | |
| 136 | |
| 137 chromeos_update_engine::PeriodicallyUpdateArgs thirty_min_args = | |
| 138 {&update_attempter, TRUE}; | |
| 139 g_timeout_add(30 * 60 * 1000, | |
| 140 &chromeos_update_engine::PeriodicallyUpdate, | |
| 141 &thirty_min_args); | |
| 142 | 144 |
| 143 // Run the main loop until exit time: | 145 // Run the main loop until exit time: |
| 144 g_main_loop_run(loop); | 146 g_main_loop_run(loop); |
| 145 | 147 |
| 146 // Cleanup: | 148 // Cleanup: |
| 147 g_main_loop_unref(loop); | 149 g_main_loop_unref(loop); |
| 148 update_attempter.set_dbus_service(NULL); | 150 update_attempter.set_dbus_service(NULL); |
| 149 g_object_unref(G_OBJECT(service)); | 151 g_object_unref(G_OBJECT(service)); |
| 150 | 152 |
| 151 LOG(INFO) << "Chrome OS Update Engine terminating"; | 153 LOG(INFO) << "Chrome OS Update Engine terminating"; |
| 152 return 0; | 154 return 0; |
| 153 } | 155 } |
| OLD | NEW |