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..4d3fbc7caffb1c77ac506215cc1e99ab149a38eb 100644 |
--- a/chrome/browser/ui/webui/help/help_handler.cc |
+++ b/chrome/browser/ui/webui/help/help_handler.cc |
@@ -34,13 +34,18 @@ |
#include "webkit/glue/webkit_glue.h" |
#if defined(OS_CHROMEOS) |
+#include "base/i18n/time_formatting.h" |
+#include "base/file_util_proxy.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" |
#include "chrome/browser/prefs/pref_service.h" |
+#include "content/public/browser/browser_thread.h" |
#endif |
using base::ListValue; |
+using content::BrowserThread; |
namespace { |
@@ -90,12 +95,21 @@ 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()) |
+#if defined(OS_CHROMEOS) |
+ , ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) |
+#endif // defined(OS_CHROMEOS) |
+ { |
} |
HelpHandler::~HelpHandler() { |
@@ -136,6 +150,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 }, |
@@ -223,6 +238,8 @@ void HelpHandler::Observe(int type, const content::NotificationSource& source, |
} |
void HelpHandler::OnPageLoaded(const ListValue* args) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
Evan Stade
2012/04/19 03:40:27
I disagree this is necessary, the one down below i
Mark Mentovai
2012/04/19 03:44:50
Evan Stade wrote:
Kyle Horimoto
2012/04/19 18:31:29
Done.
Kyle Horimoto
2012/04/19 18:31:29
Done.
|
+ |
#if defined(OS_CHROMEOS) |
// Version information is loaded from a callback |
loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, |
@@ -235,6 +252,26 @@ 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) { |
+ // If |g_last_updated_string| is |NULL|, the date has not yet been assigned. |
+ // Get the date of the last lsb-release file modification. Note that there |
+ // is a chance that multiple tabs could request the file information at |
Evan Stade
2012/04/19 03:40:27
leaner comments. While this comment is all true, e
Kyle Horimoto
2012/04/19 18:31:29
Done.
|
+ // roughly the same time, causing this request to go through multiple times. |
+ // While this may cause the file to be read multiple times unnecessarily, |
+ // it does not leak resources and is a rare in that it only happens if |
+ // multiple "Help" tabs are opened simultaneously. |
+ 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 |
Evan Stade
2012/04/19 03:40:27
I would remove this comment; it's already covered
Kyle Horimoto
2012/04/19 18:31:29
Done.
|
+ // 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 +417,34 @@ 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) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ 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 |
Evan Stade
2012/04/19 03:40:27
remove last sentence
Kyle Horimoto
2012/04/19 18:31:29
Done.
|
+ // 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. |
Evan Stade
2012/04/19 03:40:27
instead of telling a lie, it's better to not show
Kyle Horimoto
2012/04/19 18:31:29
I made the "Last Updated" section hidden by defaul
|
+ time = base::Time::Now(); |
+ } |
+ |
+ // Note that this string will be internationalized. |
+ string16 last_updated = base::TimeFormatFriendlyDate(time); |
+ |
+ // If |g_last_updated_string| is |NULL|, then the file's information has not |
+ // already been retrieved by another tab. In this case, allocate the Value |
Evan Stade
2012/04/19 03:40:27
invert the first sentence (if string is not null..
Kyle Horimoto
2012/04/19 18:31:29
Done.
|
+ // here. |
+ if (g_last_updated_string == NULL) |
Evan Stade
2012/04/19 03:40:27
if g_last_updated_string is not null, you needn't
Kyle Horimoto
2012/04/19 18:31:29
Done.
Evan Stade
2012/04/19 19:30:57
I don't see any changes. What I meant was somethin
Kyle Horimoto
2012/04/19 20:07:33
Oops, misunderstood you the first time. Got it now
|
+ g_last_updated_string = Value::CreateStringValue(last_updated); |
+ |
+ web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", |
+ *g_last_updated_string); |
+} |
#endif // defined(OS_CHROMEOS) |