OLD | NEW |
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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "grit/google_chrome_strings.h" | 29 #include "grit/google_chrome_strings.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
32 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
33 #include "webkit/glue/user_agent.h" | 33 #include "webkit/glue/user_agent.h" |
34 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
35 | 35 |
36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 37 #include "base/i18n/time_formatting.h" |
| 38 #include "base/file_util_proxy.h" |
| 39 #include "base/sys_info.h" |
37 #include "chrome/browser/chromeos/login/user_manager.h" | 40 #include "chrome/browser/chromeos/login/user_manager.h" |
38 #include "chrome/browser/chromeos/cros_settings.h" | 41 #include "chrome/browser/chromeos/cros_settings.h" |
39 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
40 #include "chrome/browser/prefs/pref_service.h" | 43 #include "chrome/browser/prefs/pref_service.h" |
| 44 #include "content/public/browser/browser_thread.h" |
41 #endif | 45 #endif |
42 | 46 |
43 using base::ListValue; | 47 using base::ListValue; |
| 48 using content::BrowserThread; |
44 | 49 |
45 namespace { | 50 namespace { |
46 | 51 |
47 // Returns the browser version as a string. | 52 // Returns the browser version as a string. |
48 string16 BuildBrowserVersionString() { | 53 string16 BuildBrowserVersionString() { |
49 chrome::VersionInfo version_info; | 54 chrome::VersionInfo version_info; |
50 DCHECK(version_info.is_valid()); | 55 DCHECK(version_info.is_valid()); |
51 | 56 |
52 std::string browser_version = version_info.Version(); | 57 std::string browser_version = version_info.Version(); |
53 std::string version_modifier = | 58 std::string version_modifier = |
(...skipping 29 matching lines...) Expand all Loading... |
83 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email(); | 88 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email(); |
84 size_t at_pos = user.find('@'); | 89 size_t at_pos = user.find('@'); |
85 if (at_pos != std::string::npos && at_pos + 1 < user.length()) | 90 if (at_pos != std::string::npos && at_pos + 1 < user.length()) |
86 domain = user.substr(user.find('@') + 1); | 91 domain = user.substr(user.find('@') + 1); |
87 return domain == g_browser_process->browser_policy_connector()-> | 92 return domain == g_browser_process->browser_policy_connector()-> |
88 GetEnterpriseDomain(); | 93 GetEnterpriseDomain(); |
89 } | 94 } |
90 return false; | 95 return false; |
91 } | 96 } |
92 | 97 |
| 98 // Pointer to a |StringValue| holding the date of the last update to Chromium |
| 99 // OS. Because this value is obtained by reading a file, it is cached here to |
| 100 // prevent the need to read from the file system multiple times unnecessarily. |
| 101 Value* g_last_updated_string = NULL; |
| 102 |
93 #endif // defined(OS_CHROMEOS) | 103 #endif // defined(OS_CHROMEOS) |
94 | 104 |
95 } // namespace | 105 } // namespace |
96 | 106 |
97 HelpHandler::HelpHandler() | 107 HelpHandler::HelpHandler() |
98 : version_updater_(VersionUpdater::Create()) { | 108 : version_updater_(VersionUpdater::Create()), |
| 109 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
99 } | 110 } |
100 | 111 |
101 HelpHandler::~HelpHandler() { | 112 HelpHandler::~HelpHandler() { |
102 } | 113 } |
103 | 114 |
104 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 115 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
105 DCHECK(localized_strings); | 116 DCHECK(localized_strings); |
106 DCHECK(localized_strings->empty()); | 117 DCHECK(localized_strings->empty()); |
107 | 118 |
108 struct L10nResources { | 119 struct L10nResources { |
(...skipping 20 matching lines...) Expand all Loading... |
129 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, | 140 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, |
130 { "showMoreInfo", IDS_SHOW_MORE_INFO }, | 141 { "showMoreInfo", IDS_SHOW_MORE_INFO }, |
131 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, | 142 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, |
132 { "channel", IDS_ABOUT_PAGE_CHANNEL }, | 143 { "channel", IDS_ABOUT_PAGE_CHANNEL }, |
133 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, | 144 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, |
134 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, | 145 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, |
135 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, | 146 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, |
136 { "webkit", IDS_WEBKIT }, | 147 { "webkit", IDS_WEBKIT }, |
137 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, | 148 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, |
138 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, | 149 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, |
| 150 { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED }, |
139 #endif | 151 #endif |
140 #if defined(OS_MACOSX) | 152 #if defined(OS_MACOSX) |
141 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, | 153 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, |
142 #endif | 154 #endif |
143 }; | 155 }; |
144 | 156 |
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { | 157 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
146 localized_strings->SetString(resources[i].name, | 158 localized_strings->SetString(resources[i].name, |
147 l10n_util::GetStringUTF16(resources[i].ids)); | 159 l10n_util::GetStringUTF16(resources[i].ids)); |
148 } | 160 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, | 240 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, |
229 base::Unretained(this)), | 241 base::Unretained(this)), |
230 chromeos::VersionLoader::VERSION_FULL); | 242 chromeos::VersionLoader::VERSION_FULL); |
231 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, | 243 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, |
232 base::Unretained(this))); | 244 base::Unretained(this))); |
233 | 245 |
234 scoped_ptr<base::Value> can_change_channel_value( | 246 scoped_ptr<base::Value> can_change_channel_value( |
235 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); | 247 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); |
236 web_ui()->CallJavascriptFunction( | 248 web_ui()->CallJavascriptFunction( |
237 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); | 249 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); |
| 250 |
| 251 if (g_last_updated_string == NULL) { |
| 252 // If |g_last_updated_string| is |NULL|, the date has not yet been assigned. |
| 253 // Get the date of the last lsb-release file modification. |
| 254 base::FileUtilProxy::GetFileInfo( |
| 255 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 256 base::SysInfo::GetLsbReleaseFilePath(), |
| 257 base::Bind(&HelpHandler::ProcessLsbFileInfo, |
| 258 weak_factory_.GetWeakPtr())); |
| 259 } else { |
| 260 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", |
| 261 *g_last_updated_string); |
| 262 } |
238 #endif // defined(OS_CHROMEOS) | 263 #endif // defined(OS_CHROMEOS) |
239 | 264 |
240 version_updater_->CheckForUpdate( | 265 version_updater_->CheckForUpdate( |
241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) | 266 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) |
242 #if defined(OS_MACOSX) | 267 #if defined(OS_MACOSX) |
243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) | 268 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) |
244 #endif | 269 #endif |
245 ); | 270 ); |
246 | 271 |
247 #if defined(OS_CHROMEOS) | 272 #if defined(OS_CHROMEOS) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); | 398 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); |
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 399 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
375 *firmware_string); | 400 *firmware_string); |
376 } | 401 } |
377 | 402 |
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 403 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 404 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
380 web_ui()->CallJavascriptFunction( | 405 web_ui()->CallJavascriptFunction( |
381 "help.HelpPage.updateSelectedChannel", *channel_string); | 406 "help.HelpPage.updateSelectedChannel", *channel_string); |
382 } | 407 } |
| 408 |
| 409 void HelpHandler::ProcessLsbFileInfo( |
| 410 base::PlatformFileError error, const base::PlatformFileInfo& file_info) { |
| 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 412 |
| 413 // If |g_last_updated_string| is not |NULL|, then the file's information has |
| 414 // already been retrieved by another tab. |
| 415 if (g_last_updated_string == NULL) { |
| 416 base::Time time; |
| 417 if (error == base::PLATFORM_FILE_OK) { |
| 418 // Retrieves the approximate time at which Chrome OS was last updated. |
| 419 // Each time a new build is created, /etc/lsb-release is modified with the |
| 420 // new version numbers of the release. |
| 421 time = file_info.last_modified; |
| 422 } else { |
| 423 // If the time of the last update cannot be retrieved, return and do not |
| 424 // display the "Last Updated" section. |
| 425 return; |
| 426 } |
| 427 |
| 428 // Note that this string will be internationalized. |
| 429 string16 last_updated = base::TimeFormatFriendlyDate(time); |
| 430 g_last_updated_string = Value::CreateStringValue(last_updated); |
| 431 } |
| 432 |
| 433 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", |
| 434 *g_last_updated_string); |
| 435 } |
383 #endif // defined(OS_CHROMEOS) | 436 #endif // defined(OS_CHROMEOS) |
OLD | NEW |