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. Note that there | |
254 // is a chance that multiple tabs could request the file information at | |
255 // roughly the same time, causing this request to go through multiple times. | |
256 // While this may cause the file to be read multiple times unnecessarily, | |
257 // it does not leak resources and is a rare in that it only happens if | |
258 // multiple "Help" tabs are opened simultaneously. | |
259 base::FileUtilProxy::GetFileInfo( | |
260 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
261 base::SysInfo::GetLsbReleaseFilePath(), | |
262 base::Bind(&HelpHandler::ProcessLsbFileInfo, | |
263 weak_factory_.GetWeakPtr())); | |
264 } else { | |
265 // If it is not NULL, the date has already been retrieved from the file | |
266 // system, so just use the cached value. | |
267 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
268 *g_last_updated_string); | |
269 } | |
238 #endif // defined(OS_CHROMEOS) | 270 #endif // defined(OS_CHROMEOS) |
239 | 271 |
240 version_updater_->CheckForUpdate( | 272 version_updater_->CheckForUpdate( |
241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) | 273 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) |
242 #if defined(OS_MACOSX) | 274 #if defined(OS_MACOSX) |
243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) | 275 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) |
244 #endif | 276 #endif |
245 ); | 277 ); |
246 | 278 |
247 #if defined(OS_CHROMEOS) | 279 #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)); | 405 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); |
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 406 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
375 *firmware_string); | 407 *firmware_string); |
376 } | 408 } |
377 | 409 |
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 410 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 411 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
380 web_ui()->CallJavascriptFunction( | 412 web_ui()->CallJavascriptFunction( |
381 "help.HelpPage.updateSelectedChannel", *channel_string); | 413 "help.HelpPage.updateSelectedChannel", *channel_string); |
382 } | 414 } |
415 | |
416 void HelpHandler::ProcessLsbFileInfo( | |
417 base::PlatformFileError error, const base::PlatformFileInfo& file_info) { | |
418 base::Time time; | |
419 if (error == base::PLATFORM_FILE_OK) { | |
420 // Retrieves the approximate time at which Chrome OS was last updated. Each | |
421 // time a new build is created, /etc/lsb-release is modified with the new | |
422 // version numbers of the release. Thus, this is a close approximation of | |
423 // the time that the last Chrome OS update occurred. | |
424 time = file_info.last_modified; | |
425 } else { | |
426 // If the time of the last update cannot be retrieved, punt and just set | |
427 // the last update time to be the current time. | |
428 time = base::Time::Now(); | |
429 } | |
430 | |
431 // Note that this string will be internationalized. | |
432 string16 last_updated = base::TimeFormatFriendlyDate(time); | |
433 | |
434 // If |g_last_updated_string| is NULL, then the file's information was already | |
435 // retrieved once by another tab. In this case, do not allocate the Value | |
436 // again and simply reuse the value already allocated. | |
437 if (g_last_updated_string != NULL) | |
Mark Mentovai
2012/04/18 15:59:07
The only reason this works and isn’t racy is that
Kyle Horimoto
2012/04/18 20:54:19
Yep, that's why it's not racy. I'll add that in.
| |
438 g_last_updated_string = Value::CreateStringValue(last_updated); | |
439 | |
440 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
441 *g_last_updated_string); | |
442 } | |
383 #endif // defined(OS_CHROMEOS) | 443 #endif // defined(OS_CHROMEOS) |
OLD | NEW |