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) | |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 #endif | 231 #endif |
217 ); | 232 ); |
218 break; | 233 break; |
219 } | 234 } |
220 default: | 235 default: |
221 NOTREACHED(); | 236 NOTREACHED(); |
222 } | 237 } |
223 } | 238 } |
224 | 239 |
225 void HelpHandler::OnPageLoaded(const ListValue* args) { | 240 void HelpHandler::OnPageLoaded(const ListValue* args) { |
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Evan Stade
2012/04/19 03:40:27
I disagree this is necessary, the one down below i
Mark Mentovai
2012/04/19 03:44:50
Evan Stade wrote:
Kyle Horimoto
2012/04/19 18:31:29
Done.
Kyle Horimoto
2012/04/19 18:31:29
Done.
| |
242 | |
226 #if defined(OS_CHROMEOS) | 243 #if defined(OS_CHROMEOS) |
227 // Version information is loaded from a callback | 244 // Version information is loaded from a callback |
228 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, | 245 loader_.GetVersion(&consumer_, base::Bind(&HelpHandler::OnOSVersion, |
229 base::Unretained(this)), | 246 base::Unretained(this)), |
230 chromeos::VersionLoader::VERSION_FULL); | 247 chromeos::VersionLoader::VERSION_FULL); |
231 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, | 248 loader_.GetFirmware(&consumer_, base::Bind(&HelpHandler::OnOSFirmware, |
232 base::Unretained(this))); | 249 base::Unretained(this))); |
233 | 250 |
234 scoped_ptr<base::Value> can_change_channel_value( | 251 scoped_ptr<base::Value> can_change_channel_value( |
235 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); | 252 base::Value::CreateBooleanValue(CanChangeReleaseChannel())); |
236 web_ui()->CallJavascriptFunction( | 253 web_ui()->CallJavascriptFunction( |
237 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); | 254 "help.HelpPage.updateEnableReleaseChannel", *can_change_channel_value); |
255 | |
256 if (g_last_updated_string == NULL) { | |
257 // If |g_last_updated_string| is |NULL|, the date has not yet been assigned. | |
258 // Get the date of the last lsb-release file modification. Note that there | |
259 // is a chance that multiple tabs could request the file information at | |
Evan Stade
2012/04/19 03:40:27
leaner comments. While this comment is all true, e
Kyle Horimoto
2012/04/19 18:31:29
Done.
| |
260 // roughly the same time, causing this request to go through multiple times. | |
261 // While this may cause the file to be read multiple times unnecessarily, | |
262 // it does not leak resources and is a rare in that it only happens if | |
263 // multiple "Help" tabs are opened simultaneously. | |
264 base::FileUtilProxy::GetFileInfo( | |
265 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
266 base::SysInfo::GetLsbReleaseFilePath(), | |
267 base::Bind(&HelpHandler::ProcessLsbFileInfo, | |
268 weak_factory_.GetWeakPtr())); | |
269 } else { | |
270 // If it is not NULL, the date has already been retrieved from the file | |
Evan Stade
2012/04/19 03:40:27
I would remove this comment; it's already covered
Kyle Horimoto
2012/04/19 18:31:29
Done.
| |
271 // system, so just use the cached value. | |
272 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
273 *g_last_updated_string); | |
274 } | |
238 #endif // defined(OS_CHROMEOS) | 275 #endif // defined(OS_CHROMEOS) |
239 | 276 |
240 version_updater_->CheckForUpdate( | 277 version_updater_->CheckForUpdate( |
241 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) | 278 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)) |
242 #if defined(OS_MACOSX) | 279 #if defined(OS_MACOSX) |
243 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) | 280 , base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this)) |
244 #endif | 281 #endif |
245 ); | 282 ); |
246 | 283 |
247 #if defined(OS_CHROMEOS) | 284 #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)); | 410 scoped_ptr<Value> firmware_string(Value::CreateStringValue(firmware)); |
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 411 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
375 *firmware_string); | 412 *firmware_string); |
376 } | 413 } |
377 | 414 |
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 415 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 416 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
380 web_ui()->CallJavascriptFunction( | 417 web_ui()->CallJavascriptFunction( |
381 "help.HelpPage.updateSelectedChannel", *channel_string); | 418 "help.HelpPage.updateSelectedChannel", *channel_string); |
382 } | 419 } |
420 | |
421 void HelpHandler::ProcessLsbFileInfo( | |
422 base::PlatformFileError error, const base::PlatformFileInfo& file_info) { | |
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
424 | |
425 base::Time time; | |
426 if (error == base::PLATFORM_FILE_OK) { | |
427 // Retrieves the approximate time at which Chrome OS was last updated. Each | |
428 // time a new build is created, /etc/lsb-release is modified with the new | |
429 // version numbers of the release. Thus, this is a close approximation of | |
Evan Stade
2012/04/19 03:40:27
remove last sentence
Kyle Horimoto
2012/04/19 18:31:29
Done.
| |
430 // the time that the last Chrome OS update occurred. | |
431 time = file_info.last_modified; | |
432 } else { | |
433 // If the time of the last update cannot be retrieved, punt and just set | |
434 // the last update time to be the current time. | |
Evan Stade
2012/04/19 03:40:27
instead of telling a lie, it's better to not show
Kyle Horimoto
2012/04/19 18:31:29
I made the "Last Updated" section hidden by defaul
| |
435 time = base::Time::Now(); | |
436 } | |
437 | |
438 // Note that this string will be internationalized. | |
439 string16 last_updated = base::TimeFormatFriendlyDate(time); | |
440 | |
441 // If |g_last_updated_string| is |NULL|, then the file's information has not | |
442 // already been retrieved by another tab. In this case, allocate the Value | |
Evan Stade
2012/04/19 03:40:27
invert the first sentence (if string is not null..
Kyle Horimoto
2012/04/19 18:31:29
Done.
| |
443 // here. | |
444 if (g_last_updated_string == NULL) | |
Evan Stade
2012/04/19 03:40:27
if g_last_updated_string is not null, you needn't
Kyle Horimoto
2012/04/19 18:31:29
Done.
Evan Stade
2012/04/19 19:30:57
I don't see any changes. What I meant was somethin
Kyle Horimoto
2012/04/19 20:07:33
Oops, misunderstood you the first time. Got it now
| |
445 g_last_updated_string = Value::CreateStringValue(last_updated); | |
446 | |
447 web_ui()->CallJavascriptFunction("help.HelpPage.setLastUpdated", | |
448 *g_last_updated_string); | |
449 } | |
383 #endif // defined(OS_CHROMEOS) | 450 #endif // defined(OS_CHROMEOS) |
OLD | NEW |