Implemented a "Last Updated" field for the about page of Chrome OS.

BUG=117517
TEST=


Review URL: http://codereview.chromium.org/10038034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133840 0039d316-1c4b-4281-b951-d872f2087c98
parent 922828b3
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/file_path.h"
#include "base/time.h"
#include <string> #include <string>
...@@ -61,7 +63,7 @@ class BASE_EXPORT SysInfo { ...@@ -61,7 +63,7 @@ class BASE_EXPORT SysInfo {
#if defined(OS_POSIX) && !defined(OS_MACOSX) #if defined(OS_POSIX) && !defined(OS_MACOSX)
// Returns the maximum SysV shared memory segment size. // Returns the maximum SysV shared memory segment size.
static size_t MaxSharedMemorySize(); static size_t MaxSharedMemorySize();
#endif #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Returns the name of the version entry we wish to look up in the // Returns the name of the version entry we wish to look up in the
...@@ -74,7 +76,10 @@ class BASE_EXPORT SysInfo { ...@@ -74,7 +76,10 @@ class BASE_EXPORT SysInfo {
int32* major_version, int32* major_version,
int32* minor_version, int32* minor_version,
int32* bugfix_version); int32* bugfix_version);
#endif
// Returns the path to the lsb-release file.
static FilePath GetLsbReleaseFilePath();
#endif // defined(OS_CHROMEOS)
}; };
} // namespace base } // namespace base
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -113,4 +113,9 @@ void SysInfo::ParseLsbRelease(const std::string& lsb_release, ...@@ -113,4 +113,9 @@ void SysInfo::ParseLsbRelease(const std::string& lsb_release,
} }
} }
// static
FilePath SysInfo::GetLsbReleaseFilePath() {
return FilePath(kLinuxStandardBaseReleaseFile);
}
} // namespace base } // namespace base
...@@ -5884,6 +5884,9 @@ Because search results are requested even while you're typing your query, your d ...@@ -5884,6 +5884,9 @@ Because search results are requested even while you're typing your query, your d
<message name="IDS_ABOUT_VERSION_COMMAND_LINE" desc="label for the command line on the about:version page"> <message name="IDS_ABOUT_VERSION_COMMAND_LINE" desc="label for the command line on the about:version page">
Command Line Command Line
</message> </message>
<message name="IDS_ABOUT_VERSION_LAST_UPDATED" desc="label for date last updated on the about:version page">
Last Updated
</message>
<message name="IDS_ABOUT_VERSION_EXECUTABLE_PATH" desc="label for the executable path on the about:version page"> <message name="IDS_ABOUT_VERSION_EXECUTABLE_PATH" desc="label for the executable path on the about:version page">
Executable Path Executable Path
</message> </message>
......
...@@ -90,3 +90,7 @@ body { ...@@ -90,3 +90,7 @@ body {
margin-bottom: 0; margin-bottom: 0;
overflow: hidden; overflow: hidden;
} }
#last-updated-container.empty {
visibility: hidden;
}
...@@ -62,6 +62,10 @@ ...@@ -62,6 +62,10 @@
<h3 i18n-content="commandLine"></h3> <h3 i18n-content="commandLine"></h3>
<div i18n-content="commandLineInfo" dir="ltr"></div> <div i18n-content="commandLineInfo" dir="ltr"></div>
</section> </section>
<section id="last-updated-container" class="empty">
<h3 i18n-content="lastUpdated"></h3>
<div id="last-updated"></div>
</section>
</div> </div>
<button id="more-info-expander" class="link-button" <button id="more-info-expander" class="link-button"
i18n-content="showMoreInfo"> i18n-content="showMoreInfo">
......
...@@ -213,6 +213,16 @@ cr.define('help', function() { ...@@ -213,6 +213,16 @@ cr.define('help', function() {
setReleaseChannel_: function(channel) { setReleaseChannel_: function(channel) {
chrome.send('setReleaseTrack', [channel]); chrome.send('setReleaseTrack', [channel]);
}, },
/**
* Sets the value of the "Last Updated" field of the "More Info" section.
* @param {String} lastUpdated The date of the last update.
* @private
*/
setLastUpdated_: function(lastUpdated) {
$('last-updated-container').classList.remove('empty');
$('last-updated').textContent = lastUpdated;
},
}; };
HelpPage.setUpdateStatus = function(status, message) { HelpPage.setUpdateStatus = function(status, message) {
...@@ -251,6 +261,10 @@ cr.define('help', function() { ...@@ -251,6 +261,10 @@ cr.define('help', function() {
HelpPage.getInstance().setReleaseChannel_(channel); HelpPage.getInstance().setReleaseChannel_(channel);
}; };
HelpPage.setLastUpdated = function(lastUpdated) {
HelpPage.getInstance().setLastUpdated_(lastUpdated);
}
// Export // Export
return { return {
HelpPage: HelpPage HelpPage: HelpPage
......
...@@ -34,13 +34,18 @@ ...@@ -34,13 +34,18 @@
#include "webkit/glue/webkit_glue.h" #include "webkit/glue/webkit_glue.h"
#if defined(OS_CHROMEOS) #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/login/user_manager.h"
#include "chrome/browser/chromeos/cros_settings.h" #include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#endif #endif
using base::ListValue; using base::ListValue;
using content::BrowserThread;
namespace { namespace {
...@@ -90,12 +95,18 @@ bool CanChangeReleaseChannel() { ...@@ -90,12 +95,18 @@ bool CanChangeReleaseChannel() {
return false; 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) #endif // defined(OS_CHROMEOS)
} // namespace } // namespace
HelpHandler::HelpHandler() HelpHandler::HelpHandler()
: version_updater_(VersionUpdater::Create()) { : version_updater_(VersionUpdater::Create()),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
} }
HelpHandler::~HelpHandler() { HelpHandler::~HelpHandler() {
...@@ -136,6 +147,7 @@ void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { ...@@ -136,6 +147,7 @@ void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
{ "webkit", IDS_WEBKIT }, { "webkit", IDS_WEBKIT },
{ "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, { "userAgent", IDS_ABOUT_VERSION_USER_AGENT },
{ "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE },
{ "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED },
#endif #endif
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
{ "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER },
...@@ -235,6 +247,19 @@ void HelpHandler::OnPageLoaded(const ListValue* args) { ...@@ -235,6 +247,19 @@ void HelpHandler::OnPageLoaded(const ListValue* args) {
base::Value::CreateBooleanValue(CanChangeReleaseChannel())); base::Value::CreateBooleanValue(CanChangeReleaseChannel()));
web_ui()->CallJavascriptFunction( web_ui()->CallJavascriptFunction(
"help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); "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.
base::FileUtilProxy::GetFileInfo(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
base::SysInfo::GetLsbReleaseFilePath(),
base::Bind(&HelpHandler::ProcessLsbFileInfo,
weak_factory_.GetWeakPtr()));
} else {
web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated",
*g_last_updated_string);
}
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
version_updater_->CheckForUpdate( version_updater_->CheckForUpdate(
...@@ -380,4 +405,32 @@ void HelpHandler::OnReleaseChannel(const std::string& channel) { ...@@ -380,4 +405,32 @@ void HelpHandler::OnReleaseChannel(const std::string& channel) {
web_ui()->CallJavascriptFunction( web_ui()->CallJavascriptFunction(
"help.HelpPage.updateSelectedChannel", *channel_string); "help.HelpPage.updateSelectedChannel", *channel_string);
} }
void HelpHandler::ProcessLsbFileInfo(
base::PlatformFileError error, const base::PlatformFileInfo& file_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// If |g_last_updated_string| is not |NULL|, then the file's information has
// already been retrieved by another tab.
if (g_last_updated_string == NULL) {
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.
time = file_info.last_modified;
} else {
// If the time of the last update cannot be retrieved, return and do not
// display the "Last Updated" section.
return;
}
// 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) #endif // defined(OS_CHROMEOS)
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
#include <string> #include <string>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/help/version_updater.h" #include "chrome/browser/ui/webui/help/version_updater.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "base/platform_file.h"
#include "chrome/browser/chromeos/version_loader.h" #include "chrome/browser/chromeos/version_loader.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
...@@ -72,11 +74,17 @@ class HelpHandler : public content::WebUIMessageHandler, ...@@ -72,11 +74,17 @@ class HelpHandler : public content::WebUIMessageHandler,
void OnOSFirmware(chromeos::VersionLoader::Handle handle, void OnOSFirmware(chromeos::VersionLoader::Handle handle,
std::string firmware); std::string firmware);
void OnReleaseChannel(const std::string& channel); void OnReleaseChannel(const std::string& channel);
void ProcessLsbFileInfo(
base::PlatformFileError rv, const base::PlatformFileInfo& file_info);
#endif #endif
// Specialized instance of the VersionUpdater used to update the browser. // Specialized instance of the VersionUpdater used to update the browser.
scoped_ptr<VersionUpdater> version_updater_; scoped_ptr<VersionUpdater> version_updater_;
// Used for callbacks.
base::WeakPtrFactory<HelpHandler> weak_factory_;
// Used to observe notifications. // Used to observe notifications.
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment