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

Unified Diff: chrome/browser/ui/webui/help/help_handler.cc

Issue 10038034: Implemented a "Last Updated" field for the about page of Chrome OS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed scoped_ptr<Value> to Value* Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/help/help_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/help/help_handler.cc
diff --git a/chrome/browser/ui/webui/help/help_handler.cc b/chrome/browser/ui/webui/help/help_handler.cc
index 6f3a246be2f659665f21efb848e254bb3cae6b65..ae0a65f731ca2c52c30e91ba4b1877cea585f79b 100644
--- a/chrome/browser/ui/webui/help/help_handler.cc
+++ b/chrome/browser/ui/webui/help/help_handler.cc
@@ -10,6 +10,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
+#include "base/file_util_proxy.h"
+#include "base/message_loop_proxy.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -21,6 +23,7 @@
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/content_client.h"
@@ -34,6 +37,8 @@
#include "webkit/glue/webkit_glue.h"
#if defined(OS_CHROMEOS)
+#include "base/i18n/time_formatting.h"
+#include "base/sys_info.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/profiles/profile.h"
@@ -41,6 +46,7 @@
#endif
using base::ListValue;
+using content::BrowserThread;
namespace {
@@ -90,12 +96,18 @@ bool CanChangeReleaseChannel() {
return false;
}
+// Pointer to a |StringValue| holding the date of the last update to Chromium
+// OS. Because this value is obtained by reading a file, it is cached here to
+// prevent the need to read from the file system multiple times unnecessarily.
+Value* g_last_updated_string = NULL;
+
#endif // defined(OS_CHROMEOS)
} // namespace
HelpHandler::HelpHandler()
- : version_updater_(VersionUpdater::Create()) {
+ : version_updater_(VersionUpdater::Create()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
HelpHandler::~HelpHandler() {
@@ -136,6 +148,7 @@ void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
{ "webkit", IDS_WEBKIT },
{ "userAgent", IDS_ABOUT_VERSION_USER_AGENT },
{ "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE },
+ { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED },
#endif
#if defined(OS_MACOSX)
{ "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER },
@@ -235,6 +248,22 @@ void HelpHandler::OnPageLoaded(const ListValue* args) {
base::Value::CreateBooleanValue(CanChangeReleaseChannel()));
web_ui()->CallJavascriptFunction(
"help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value);
+
+ if (g_last_updated_string == NULL) {
Mark Mentovai 2012/04/17 20:26:31 This looks racy. Can’t the application reach this
Kyle Horimoto 2012/04/17 21:20:03 Done.
+ // If |g_last_updated_string| is NULL, the date has not yet been retrieved
+ // from the file system. Get the date of the last lsb-release file
+ // modification.
+ base::FileUtilProxy::GetFileInfo(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
+ base::SysInfo::GetLsbReleaseFilePath(),
+ base::Bind(&HelpHandler::ProcessLsbFileInfo,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ // If it is not NULL, the date has already been retrieved from the file
+ // system, so just use the cached value.
+ web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated",
+ *g_last_updated_string);
+ }
#endif // defined(OS_CHROMEOS)
version_updater_->CheckForUpdate(
@@ -380,4 +409,28 @@ void HelpHandler::OnReleaseChannel(const std::string& channel) {
web_ui()->CallJavascriptFunction(
"help.HelpPage.updateSelectedChannel", *channel_string);
}
+
+void HelpHandler::ProcessLsbFileInfo(
+ base::PlatformFileError error, const base::PlatformFileInfo& file_info) {
+ base::Time time;
+
+ if (error == base::PLATFORM_FILE_OK) {
+ // Retrieves the approximate time at which Chrome OS was last updated. Each
+ // time a new build is created, /etc/lsb-release is modified with the new
+ // version numbers of the release. Thus, this is a close approximation of
+ // the time that the last Chrome OS update occurred.
+ time = file_info.last_modified;
+ } else {
+ // If the time of the last update cannot be retrieved, punt and just set
+ // the last update time to be the current time.
+ time = base::Time::Now();
+ }
+
+ // Note that this string will be internationalized.
+ string16 last_updated = base::TimeFormatFriendlyDate(time);
+ g_last_updated_string = Value::CreateStringValue(last_updated);
+
+ web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated",
+ *g_last_updated_string);
+}
#endif // defined(OS_CHROMEOS)
« no previous file with comments | « chrome/browser/ui/webui/help/help_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698