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 #if defined(OS_CHROMEOS) | |
110 , ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) | |
111 #endif // defined(OS_CHROMEOS) | |
Evan Stade
2012/04/19 22:26:57
in order to avoid this ugly ifdef, I would make we
Kyle Horimoto
2012/04/23 20:37:03
Done.
| |
112 { | |
99 } | 113 } |
100 | 114 |
101 HelpHandler::~HelpHandler() { | 115 HelpHandler::~HelpHandler() { |
102 } | 116 } |
103 | 117 |
104 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 118 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
105 DCHECK(localized_strings); | 119 DCHECK(localized_strings); |
106 DCHECK(localized_strings->empty()); | 120 DCHECK(localized_strings->empty()); |
107 | 121 |
108 struct L10nResources { | 122 struct L10nResources { |
(...skipping 20 matching lines...) Expand all Loading... | |
129 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, | 143 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, |
130 { "showMoreInfo", IDS_SHOW_MORE_INFO }, | 144 { "showMoreInfo", IDS_SHOW_MORE_INFO }, |
131 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, | 145 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, |
132 { "channel", IDS_ABOUT_PAGE_CHANNEL }, | 146 { "channel", IDS_ABOUT_PAGE_CHANNEL }, |
133 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, | 147 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, |
134 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, | 148 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, |
135 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, | 149 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, |
136 { "webkit", IDS_WEBKIT }, | 150 { "webkit", IDS_WEBKIT }, |
137 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, | 151 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, |
138 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, | 152 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, |
153 { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED }, | |
139 #endif | 154 #endif |
140 #if defined(OS_MACOSX) | 155 #if defined(OS_MACOSX) |
141 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, | 156 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, |
142 #endif | 157 #endif |
143 }; | 158 }; |
144 | 159 |
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { | 160 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
146 localized_strings->SetString(resources[i].name, | 161 localized_strings->SetString(resources[i].name, |
147 l10n_util::GetStringUTF16(resources[i].ids)); | 162 l10n_util::GetStringUTF16(resources[i].ids)); |
148 } | 163 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, | 243 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, |
229 base::Unretained(this)), | 244 base::Unretained(this)), |
230 chromeos::VersionLoader::VERSION_FULL); | 245 chromeos::VersionLoader::VERSION_FULL); |
231 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, | 246 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, |
232 base::Unretained(this))); | 247 base::Unretained(this))); |
233 | 248 |
234 scoped_ptr<base::Value> can_change_channel_value( | 249 scoped_ptr<base::Value> can_change_channel_value( |
235 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); | 250 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); |
236 web_ui()->CallJavascriptFunction( | 251 web_ui()->CallJavascriptFunction( |
237 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); | 252 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); |
253 | |
254 if (g_last_updated_string == NULL) { | |
255 // If |g_last_updated_string| is |NULL|, the date has not yet been assigned. | |
256 // Get the date of the last lsb-release file modification. | |
257 base::FileUtilProxy::GetFileInfo( | |
258 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
259 base::SysInfo::GetLsbReleaseFilePath(), | |
260 base::Bind(&HelpHandler::ProcessLsbFileInfo, | |
261 weak_factory_.GetWeakPtr())); | |
262 } else { | |
263 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
264 *g_last_updated_string); | |
265 } | |
238 #endif // defined(OS_CHROMEOS) | 266 #endif // defined(OS_CHROMEOS) |
239 | 267 |
240 version_updater_->CheckForUpdate( | 268 version_updater_->CheckForUpdate( |
241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) | 269 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) |
242 #if defined(OS_MACOSX) | 270 #if defined(OS_MACOSX) |
243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) | 271 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) |
244 #endif | 272 #endif |
245 ); | 273 ); |
246 | 274 |
247 #if defined(OS_CHROMEOS) | 275 #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)); | 401 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); |
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 402 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
375 *firmware_string); | 403 *firmware_string); |
376 } | 404 } |
377 | 405 |
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 406 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 407 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
380 web_ui()->CallJavascriptFunction( | 408 web_ui()->CallJavascriptFunction( |
381 "help.HelpPage.updateSelectedChannel", *channel_string); | 409 "help.HelpPage.updateSelectedChannel", *channel_string); |
382 } | 410 } |
411 | |
412 void HelpHandler::ProcessLsbFileInfo( | |
413 base::PlatformFileError error, const base::PlatformFileInfo& file_info) { | |
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
415 | |
416 // If |g_last_updated_string| is not |NULL|, then the file's information has | |
417 // already been retrieved by another tab. | |
418 if (g_last_updated_string == NULL) { | |
419 base::Time time; | |
420 if (error == base::PLATFORM_FILE_OK) { | |
421 // Retrieves the approximate time at which Chrome OS was last updated. | |
422 // Each time a new build is created, /etc/lsb-release is modified with the | |
423 // new version numbers of the release. | |
424 time = file_info.last_modified; | |
425 } else { | |
426 // If the time of the last update cannot be retrieved, return and do not | |
427 // display the "Last Updated" section. | |
428 return; | |
429 } | |
430 | |
431 // Note that this string will be internationalized. | |
432 string16 last_updated = base::TimeFormatFriendlyDate(time); | |
433 g_last_updated_string = Value::CreateStringValue(last_updated); | |
434 } | |
435 | |
436 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
437 *g_last_updated_string); | |
438 } | |
383 #endif // defined(OS_CHROMEOS) | 439 #endif // defined(OS_CHROMEOS) |
OLD | NEW |