Chromium Code Reviews| 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/synchronization/lock.h" | |
| 40 #include "base/sys_info.h" | |
| 37 #include "chrome/browser/chromeos/login/user_manager.h" | 41 #include "chrome/browser/chromeos/login/user_manager.h" |
| 38 #include "chrome/browser/chromeos/cros_settings.h" | 42 #include "chrome/browser/chromeos/cros_settings.h" |
| 39 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 40 #include "chrome/browser/prefs/pref_service.h" | 44 #include "chrome/browser/prefs/pref_service.h" |
| 45 #include "content/public/browser/browser_thread.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 Loading... | |
| 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 Value* g_last_updated_string = NULL; | |
| 103 | |
| 104 // Whether a request has started to fetch the "Last Updated" string. | |
| 105 bool g_started_fetching_update_string = false; | |
| 106 | |
| 107 // Lock for |g_last_updated_string| and |g_started_fetching_update_string|. | |
| 108 base::Lock g_lock; | |
|
Mark Mentovai
2012/04/17 22:03:31
C’mon, you just fixed g_last_updated_string to not
Kyle Horimoto
2012/04/17 23:37:29
Done.
| |
| 109 | |
| 93 #endif // defined(OS_CHROMEOS) | 110 #endif // defined(OS_CHROMEOS) |
| 94 | 111 |
| 95 } // namespace | 112 } // namespace |
| 96 | 113 |
| 97 HelpHandler::HelpHandler() | 114 HelpHandler::HelpHandler() |
| 98 : version_updater_(VersionUpdater::Create()) { | 115 : version_updater_(VersionUpdater::Create()), |
| 116 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 99 } | 117 } |
| 100 | 118 |
| 101 HelpHandler::~HelpHandler() { | 119 HelpHandler::~HelpHandler() { |
| 102 } | 120 } |
| 103 | 121 |
| 104 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 122 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
| 105 DCHECK(localized_strings); | 123 DCHECK(localized_strings); |
| 106 DCHECK(localized_strings->empty()); | 124 DCHECK(localized_strings->empty()); |
| 107 | 125 |
| 108 struct L10nResources { | 126 struct L10nResources { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 129 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, | 147 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, |
| 130 { "showMoreInfo", IDS_SHOW_MORE_INFO }, | 148 { "showMoreInfo", IDS_SHOW_MORE_INFO }, |
| 131 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, | 149 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, |
| 132 { "channel", IDS_ABOUT_PAGE_CHANNEL }, | 150 { "channel", IDS_ABOUT_PAGE_CHANNEL }, |
| 133 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, | 151 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, |
| 134 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, | 152 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, |
| 135 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, | 153 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, |
| 136 { "webkit", IDS_WEBKIT }, | 154 { "webkit", IDS_WEBKIT }, |
| 137 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, | 155 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, |
| 138 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, | 156 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, |
| 157 { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED }, | |
| 139 #endif | 158 #endif |
| 140 #if defined(OS_MACOSX) | 159 #if defined(OS_MACOSX) |
| 141 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, | 160 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, |
| 142 #endif | 161 #endif |
| 143 }; | 162 }; |
| 144 | 163 |
| 145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { | 164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
| 146 localized_strings->SetString(resources[i].name, | 165 localized_strings->SetString(resources[i].name, |
| 147 l10n_util::GetStringUTF16(resources[i].ids)); | 166 l10n_util::GetStringUTF16(resources[i].ids)); |
| 148 } | 167 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, | 247 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, |
| 229 base::Unretained(this)), | 248 base::Unretained(this)), |
| 230 chromeos::VersionLoader::VERSION_FULL); | 249 chromeos::VersionLoader::VERSION_FULL); |
| 231 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, | 250 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, |
| 232 base::Unretained(this))); | 251 base::Unretained(this))); |
| 233 | 252 |
| 234 scoped_ptr<base::Value> can_change_channel_value( | 253 scoped_ptr<base::Value> can_change_channel_value( |
| 235 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); | 254 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); |
| 236 web_ui()->CallJavascriptFunction( | 255 web_ui()->CallJavascriptFunction( |
| 237 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); | 256 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); |
| 257 | |
| 258 g_lock.Acquire(); | |
| 259 if (!g_started_fetching_update_string) { | |
| 260 g_started_fetching_update_string = true; | |
| 261 | |
| 262 // If |g_started_fetching_update_string| is |false|, the date has not yet | |
| 263 // been requested from the file system. Get the date of the last lsb-release | |
| 264 // file modification. | |
| 265 base::FileUtilProxy::GetFileInfo( | |
| 266 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
| 267 base::SysInfo::GetLsbReleaseFilePath(), | |
| 268 base::Bind(&HelpHandler::ProcessLsbFileInfo, | |
| 269 weak_factory_.GetWeakPtr())); | |
| 270 } else if (g_last_updated_string != NULL) { | |
| 271 // If it is not NULL, the date has already been retrieved from the file | |
| 272 // system, so just use the cached value. | |
| 273 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
| 274 *g_last_updated_string); | |
| 275 } | |
| 276 g_lock.Release(); | |
| 238 #endif // defined(OS_CHROMEOS) | 277 #endif // defined(OS_CHROMEOS) |
| 239 | 278 |
| 240 version_updater_->CheckForUpdate( | 279 version_updater_->CheckForUpdate( |
| 241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) | 280 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) |
| 242 #if defined(OS_MACOSX) | 281 #if defined(OS_MACOSX) |
| 243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) | 282 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) |
| 244 #endif | 283 #endif |
| 245 ); | 284 ); |
| 246 | 285 |
| 247 #if defined(OS_CHROMEOS) | 286 #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)); | 412 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); |
| 374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 413 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
| 375 *firmware_string); | 414 *firmware_string); |
| 376 } | 415 } |
| 377 | 416 |
| 378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 417 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
| 379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 418 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
| 380 web_ui()->CallJavascriptFunction( | 419 web_ui()->CallJavascriptFunction( |
| 381 "help.HelpPage.updateSelectedChannel", *channel_string); | 420 "help.HelpPage.updateSelectedChannel", *channel_string); |
| 382 } | 421 } |
| 422 | |
| 423 void HelpHandler::ProcessLsbFileInfo( | |
| 424 base::PlatformFileError error, const base::PlatformFileInfo& file_info) { | |
| 425 base::Time time; | |
| 426 | |
| 427 if (error == base::PLATFORM_FILE_OK) { | |
| 428 // Retrieves the approximate time at which Chrome OS was last updated. Each | |
| 429 // time a new build is created, /etc/lsb-release is modified with the new | |
| 430 // version numbers of the release. Thus, this is a close approximation of | |
| 431 // the time that the last Chrome OS update occurred. | |
| 432 time = file_info.last_modified; | |
| 433 } else { | |
| 434 // If the time of the last update cannot be retrieved, punt and just set | |
| 435 // the last update time to be the current time. | |
| 436 time = base::Time::Now(); | |
| 437 } | |
| 438 | |
| 439 // Note that this string will be internationalized. | |
| 440 string16 last_updated = base::TimeFormatFriendlyDate(time); | |
| 441 | |
| 442 g_lock.Acquire(); | |
| 443 g_last_updated_string = Value::CreateStringValue(last_updated); | |
| 444 g_lock.Release(); | |
| 445 | |
| 446 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
| 447 *g_last_updated_string); | |
| 448 } | |
| 383 #endif // defined(OS_CHROMEOS) | 449 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |