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

Side by Side 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: Moved file operations to file thread, cached result, fixed style issues 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/help/help_handler.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 "chrome/browser/ui/webui/help/help_handler.h" 5 #include "chrome/browser/ui/webui/help/help_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util_proxy.h"
14 #include "base/message_loop_proxy.h"
13 #include "base/string16.h" 15 #include "base/string16.h"
14 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
18 #include "chrome/browser/policy/browser_policy_connector.h" 20 #include "chrome/browser/policy/browser_policy_connector.h"
19 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_version_info.h" 24 #include "chrome/common/chrome_version_info.h"
23 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
26 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_ui.h" 28 #include "content/public/browser/web_ui.h"
26 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
27 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
29 #include "grit/google_chrome_strings.h" 32 #include "grit/google_chrome_strings.h"
30 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
32 #include "v8/include/v8.h" 35 #include "v8/include/v8.h"
33 #include "webkit/glue/user_agent.h" 36 #include "webkit/glue/user_agent.h"
34 #include "webkit/glue/webkit_glue.h" 37 #include "webkit/glue/webkit_glue.h"
35 38
36 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
40 #include "base/i18n/time_formatting.h"
41 #include "base/sys_info.h"
37 #include "chrome/browser/chromeos/login/user_manager.h" 42 #include "chrome/browser/chromeos/login/user_manager.h"
38 #include "chrome/browser/chromeos/cros_settings.h" 43 #include "chrome/browser/chromeos/cros_settings.h"
39 #include "chrome/browser/profiles/profile.h" 44 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/prefs/pref_service.h" 45 #include "chrome/browser/prefs/pref_service.h"
41 #endif 46 #endif
42 47
43 using base::ListValue; 48 using base::ListValue;
49 using content::BrowserThread;
44 50
45 namespace { 51 namespace {
46 52
47 // Returns the browser version as a string. 53 // Returns the browser version as a string.
48 string16 BuildBrowserVersionString() { 54 string16 BuildBrowserVersionString() {
49 chrome::VersionInfo version_info; 55 chrome::VersionInfo version_info;
50 DCHECK(version_info.is_valid()); 56 DCHECK(version_info.is_valid());
51 57
52 std::string browser_version = version_info.Version(); 58 std::string browser_version = version_info.Version();
53 std::string version_modifier = 59 std::string version_modifier =
(...skipping 29 matching lines...) Expand all
83 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email(); 89 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email();
84 size_t at_pos = user.find('@'); 90 size_t at_pos = user.find('@');
85 if (at_pos != std::string::npos && at_pos + 1 < user.length()) 91 if (at_pos != std::string::npos && at_pos + 1 < user.length())
86 domain = user.substr(user.find('@') + 1); 92 domain = user.substr(user.find('@') + 1);
87 return domain == g_browser_process->browser_policy_connector()-> 93 return domain == g_browser_process->browser_policy_connector()->
88 GetEnterpriseDomain(); 94 GetEnterpriseDomain();
89 } 95 }
90 return false; 96 return false;
91 } 97 }
92 98
99 // Pointer to a |StringValue| holding the date of the last update to Chromium
100 // OS. Because this value is obtained by reading a file, it is cached here to
101 // prevent the need to read from the file system multiple times unnecessarily.
102 scoped_ptr<Value> last_updated_string(NULL);
Evan Stade 2012/04/17 19:49:50 you can't put non-POD data here. Besides, the scop
Kyle Horimoto 2012/04/17 20:20:22 Done.
103
93 #endif // defined(OS_CHROMEOS) 104 #endif // defined(OS_CHROMEOS)
94 105
95 } // namespace 106 } // namespace
96 107
97 HelpHandler::HelpHandler() 108 HelpHandler::HelpHandler()
98 : version_updater_(VersionUpdater::Create()) { 109 : version_updater_(VersionUpdater::Create()),
110 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
99 } 111 }
100 112
101 HelpHandler::~HelpHandler() { 113 HelpHandler::~HelpHandler() {
102 } 114 }
103 115
104 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { 116 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
105 DCHECK(localized_strings); 117 DCHECK(localized_strings);
106 DCHECK(localized_strings->empty()); 118 DCHECK(localized_strings->empty());
107 119
108 struct L10nResources { 120 struct L10nResources {
(...skipping 20 matching lines...) Expand all
129 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, 141 { "firmware", IDS_ABOUT_PAGE_FIRMWARE },
130 { "showMoreInfo", IDS_SHOW_MORE_INFO }, 142 { "showMoreInfo", IDS_SHOW_MORE_INFO },
131 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, 143 { "hideMoreInfo", IDS_HIDE_MORE_INFO },
132 { "channel", IDS_ABOUT_PAGE_CHANNEL }, 144 { "channel", IDS_ABOUT_PAGE_CHANNEL },
133 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, 145 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE },
134 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, 146 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA },
135 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, 147 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT },
136 { "webkit", IDS_WEBKIT }, 148 { "webkit", IDS_WEBKIT },
137 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, 149 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT },
138 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, 150 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE },
151 { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED },
139 #endif 152 #endif
140 #if defined(OS_MACOSX) 153 #if defined(OS_MACOSX)
141 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, 154 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER },
142 #endif 155 #endif
143 }; 156 };
144 157
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { 158 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) {
146 localized_strings->SetString(resources[i].name, 159 localized_strings->SetString(resources[i].name,
147 l10n_util::GetStringUTF16(resources[i].ids)); 160 l10n_util::GetStringUTF16(resources[i].ids));
148 } 161 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, 241 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion,
229 base::Unretained(this)), 242 base::Unretained(this)),
230 chromeos::VersionLoader::VERSION_FULL); 243 chromeos::VersionLoader::VERSION_FULL);
231 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, 244 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware,
232 base::Unretained(this))); 245 base::Unretained(this)));
233 246
234 scoped_ptr<base::Value> can_change_channel_value( 247 scoped_ptr<base::Value> can_change_channel_value(
235 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); 248 base::Value::CreateBooleanValue(CanChangeReleaseChannel()));
236 web_ui()->CallJavascriptFunction( 249 web_ui()->CallJavascriptFunction(
237 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); 250 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value);
251
252 if (last_updated_string == NULL) {
253 // If |last_updated_string| is NULL, the date has not yet been retrieved
254 // from the file system. Get the date of the last lsb-release file
255 // modification.
256 base::FileUtilProxy::GetFileInfo(
257 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
258 base::SysInfo::GetLsbReleaseFilePath(),
259 base::Bind(&HelpHandler::ProcessLsbFileInfo,
260 weak_factory_.GetWeakPtr()));
261 } else {
262 // If it is not NULL, the date has already been retrieved from the file
263 // system, so just use the cached value.
264 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated",
265 *last_updated_string);
266 }
238 #endif // defined(OS_CHROMEOS) 267 #endif // defined(OS_CHROMEOS)
239 268
240 version_updater_->CheckForUpdate( 269 version_updater_->CheckForUpdate(
241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) 270 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this))
242 #if defined(OS_MACOSX) 271 #if defined(OS_MACOSX)
243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) 272 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this))
244 #endif 273 #endif
245 ); 274 );
246 275
247 #if defined(OS_CHROMEOS) 276 #if defined(OS_CHROMEOS)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); 402 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware));
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", 403 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware",
375 *firmware_string); 404 *firmware_string);
376 } 405 }
377 406
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { 407 void HelpHandler::OnReleaseChannel(const std::string& channel) {
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); 408 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel));
380 web_ui()->CallJavascriptFunction( 409 web_ui()->CallJavascriptFunction(
381 "help.HelpPage.updateSelectedChannel", *channel_string); 410 "help.HelpPage.updateSelectedChannel", *channel_string);
382 } 411 }
412
413 void HelpHandler::ProcessLsbFileInfo(
414 base::PlatformFileError error, const base::PlatformFileInfo& file_info) {
415 base::Time time;
416
417 if (error == base::PLATFORM_FILE_OK) {
418 // Retrieves the approximate time at which Chrome OS was last updated. Each
419 // time a new build is created, /etc/lsb-release is modified with the new
420 // version numbers of the release. Thus, this is a close approximation of
421 // the time that the last Chrome OS update occurred.
422 time = file_info.last_modified;
423 } else {
424 // If the time of the last update cannot be retrieved, punt and just set
425 // the last update time to be the current time.
426 time = base::Time::Now();
427 }
428
429 // Note that this string will be internationalized.
430 string16 last_updated = base::TimeFormatFriendlyDate(time);
431 last_updated_string =
432 scoped_ptr<Value>(Value::CreateStringValue(last_updated));
433
434 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated",
435 *last_updated_string);
436 }
383 #endif // defined(OS_CHROMEOS) 437 #endif // defined(OS_CHROMEOS)
OLDNEW
« 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