Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: main.cc

Issue 3167039: AU: Simplify the automatic update check code a little. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Rename to avoid confusion. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | update_attempter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 28 matching lines...) Expand all
39 gboolean UpdateBootFlags(void* arg) { 39 gboolean UpdateBootFlags(void* arg) {
40 // This purely best effort. Failures should be logged by Subprocess. 40 // This purely best effort. Failures should be logged by Subprocess.
41 int unused = 0; 41 int unused = 0;
42 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel"); 42 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel");
43 Subprocess::SynchronousExec(cmd, &unused); 43 Subprocess::SynchronousExec(cmd, &unused);
44 return FALSE; // Don't call this callback again 44 return FALSE; // Don't call this callback again
45 } 45 }
46 46
47 namespace { 47 namespace {
48 48
49 const int kTimeoutOnce = 7 * 60; // at 7 minutes
50 const int kTimeoutPeriodic = 45 * 60; // every 45 minutes
51 const int kTimeoutFuzz = 10 * 60; // +/- 5 minutes
52
53 // Schedules an update check |seconds| from now, while adding some fuzz.
54 void ScheduleUpdateCheck(int seconds,
55 GSourceFunc update_function,
56 UpdateAttempter* update_attempter) {
57 seconds = utils::FuzzInt(seconds, kTimeoutFuzz);
58 g_timeout_add_seconds(seconds, update_function, update_attempter);
59 }
60
61 gboolean UpdateOnce(void* arg) {
62 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg);
63 update_attempter->Update("", "");
64 return FALSE; // Don't run again.
65 }
66
67 gboolean UpdatePeriodically(void* arg) {
68 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg);
69 update_attempter->Update("", "");
70 ScheduleUpdateCheck(kTimeoutPeriodic, &UpdatePeriodically, update_attempter);
71 return FALSE; // Don't run again.
72 }
73
74 void SchedulePeriodicUpdateChecks(UpdateAttempter* update_attempter) {
75 if (!utils::IsOfficialBuild()) {
76 LOG(WARNING) << "Non-official build: periodic update checks disabled.";
77 return;
78 }
79 if (utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice()))) {
80 LOG(WARNING) << "Removable device boot: periodic update checks disabled.";
81 return;
82 }
83 // Kick off periodic updating.
84 ScheduleUpdateCheck(kTimeoutOnce, &UpdateOnce, update_attempter);
85 ScheduleUpdateCheck(kTimeoutPeriodic, &UpdatePeriodically, update_attempter);
86 }
87
88 void SetupDbusService(UpdateEngineService* service) { 49 void SetupDbusService(UpdateEngineService* service) {
89 DBusGConnection *bus; 50 DBusGConnection *bus;
90 DBusGProxy *proxy; 51 DBusGProxy *proxy;
91 GError *error = NULL; 52 GError *error = NULL;
92 53
93 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); 54 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
94 if (!bus) { 55 if (!bus) {
95 LOG(FATAL) << "Failed to get bus"; 56 LOG(FATAL) << "Failed to get bus";
96 } 57 }
97 proxy = dbus_g_proxy_new_for_name(bus, 58 proxy = dbus_g_proxy_new_for_name(bus,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 121
161 // Create the dbus service object: 122 // Create the dbus service object:
162 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, 123 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE,
163 &dbus_glib_update_engine_service_object_info); 124 &dbus_glib_update_engine_service_object_info);
164 UpdateEngineService* service = 125 UpdateEngineService* service =
165 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); 126 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
166 service->update_attempter_ = &update_attempter; 127 service->update_attempter_ = &update_attempter;
167 update_attempter.set_dbus_service(service); 128 update_attempter.set_dbus_service(service);
168 chromeos_update_engine::SetupDbusService(service); 129 chromeos_update_engine::SetupDbusService(service);
169 130
170 chromeos_update_engine::SchedulePeriodicUpdateChecks(&update_attempter); 131 update_attempter.InitiatePeriodicUpdateChecks();
171 132
172 // Update boot flags after 45 seconds 133 // Update boot flags after 45 seconds
173 g_timeout_add_seconds(45, &chromeos_update_engine::UpdateBootFlags, NULL); 134 g_timeout_add_seconds(45, &chromeos_update_engine::UpdateBootFlags, NULL);
174 135
175 // Run the main loop until exit time: 136 // Run the main loop until exit time:
176 g_main_loop_run(loop); 137 g_main_loop_run(loop);
177 138
178 // Cleanup: 139 // Cleanup:
179 g_main_loop_unref(loop); 140 g_main_loop_unref(loop);
180 update_attempter.set_dbus_service(NULL); 141 update_attempter.set_dbus_service(NULL);
181 g_object_unref(G_OBJECT(service)); 142 g_object_unref(G_OBJECT(service));
182 143
183 LOG(INFO) << "Chrome OS Update Engine terminating"; 144 LOG(INFO) << "Chrome OS Update Engine terminating";
184 return 0; 145 return 0;
185 } 146 }
OLDNEW
« no previous file with comments | « no previous file | update_attempter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698