| Index: chrome/browser/ui/webui/version_handler.cc
|
| diff --git a/chrome/browser/ui/webui/version_handler.cc b/chrome/browser/ui/webui/version_handler.cc
|
| index 7259e930e86882d37c505990f5c15dfb763efe35..2b096a1c13b8e653d798770536c77747aa0339ed 100644
|
| --- a/chrome/browser/ui/webui/version_handler.cc
|
| +++ b/chrome/browser/ui/webui/version_handler.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include <stddef.h>
|
|
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/command_line.h"
|
| #include "base/files/file_util.h"
|
| #include "base/metrics/field_trial.h"
|
| @@ -16,21 +18,25 @@
|
| #include "chrome/grit/generated_resources.h"
|
| #include "components/variations/active_field_trials.h"
|
| #include "components/version_ui/version_handler_helper.h"
|
| -#include "components/version_ui/version_ui_constants.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/plugin_service.h"
|
| #include "content/public/browser/web_ui.h"
|
| #include "content/public/common/content_constants.h"
|
| #include "grit/components_strings.h"
|
| +#include "mojo/common/common_type_converters.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "url/gurl.h"
|
|
|
| +#if defined(OS_CHROMEOS)
|
| +#include "chromeos/system/version_loader.h"
|
| +#endif
|
| +
|
| namespace {
|
|
|
| // Retrieves the executable and profile paths on the FILE thread.
|
| -void GetFilePaths(const base::FilePath& profile_path,
|
| - base::string16* exec_path_out,
|
| - base::string16* profile_path_out) {
|
| +void RetrieveFilePaths(const base::FilePath& profile_path,
|
| + base::string16* exec_path_out,
|
| + base::string16* profile_path_out) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
|
|
|
| base::FilePath executable_path = base::MakeAbsoluteFilePath(
|
| @@ -49,60 +55,89 @@ void GetFilePaths(const base::FilePath& profile_path,
|
|
|
| } // namespace
|
|
|
| -VersionHandler::VersionHandler()
|
| - : weak_ptr_factory_(this) {
|
| -}
|
| +VersionHandler::VersionHandler(
|
| + content::WebUI* web_ui,
|
| + mojo::InterfaceRequest<mojom::VersionPageHandler> request)
|
| + : web_ui_(web_ui),
|
| + binding_(this, std::move(request)),
|
| + weak_ptr_factory_(this) {}
|
|
|
| -VersionHandler::~VersionHandler() {
|
| -}
|
| -
|
| -void VersionHandler::RegisterMessages() {
|
| - web_ui()->RegisterMessageCallback(
|
| - version_ui::kRequestVersionInfo,
|
| - base::Bind(&VersionHandler::HandleRequestVersionInfo,
|
| - base::Unretained(this)));
|
| -}
|
| -
|
| -void VersionHandler::HandleRequestVersionInfo(const base::ListValue* args) {
|
| -#if defined(ENABLE_PLUGINS)
|
| - // The Flash version information is needed in the response, so make sure
|
| - // the plugins are loaded.
|
| - content::PluginService::GetInstance()->GetPlugins(
|
| - base::Bind(&VersionHandler::OnGotPlugins,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| -#endif
|
| +VersionHandler::~VersionHandler() {}
|
|
|
| +void VersionHandler::GetFilePaths(const GetFilePathsCallback& callback) {
|
| // Grab the executable path on the FILE thread. It is returned in
|
| // OnGotFilePaths.
|
| base::string16* exec_path_buffer = new base::string16;
|
| base::string16* profile_path_buffer = new base::string16;
|
| content::BrowserThread::PostTaskAndReply(
|
| content::BrowserThread::FILE, FROM_HERE,
|
| - base::Bind(&GetFilePaths, Profile::FromWebUI(web_ui())->GetPath(),
|
| - base::Unretained(exec_path_buffer),
|
| - base::Unretained(profile_path_buffer)),
|
| - base::Bind(&VersionHandler::OnGotFilePaths,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Owned(exec_path_buffer),
|
| - base::Owned(profile_path_buffer)));
|
| -
|
| - // Respond with the variations info immediately.
|
| - web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnVariationInfo,
|
| - *version_ui::GetVariationsList());
|
| + base::Bind(&RetrieveFilePaths, Profile::FromWebUI(web_ui_)->GetPath(),
|
| + base::Unretained(exec_path_buffer),
|
| + base::Unretained(profile_path_buffer)),
|
| + base::Bind(&VersionHandler::OnGotFilePaths,
|
| + weak_ptr_factory_.GetWeakPtr(), base::Owned(exec_path_buffer),
|
| + base::Owned(profile_path_buffer), callback));
|
| }
|
|
|
| void VersionHandler::OnGotFilePaths(base::string16* executable_path_data,
|
| - base::string16* profile_path_data) {
|
| + base::string16* profile_path_data,
|
| + const GetFilePathsCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + callback.Run(mojo::String::From(*executable_path_data),
|
| + mojo::String::From(*profile_path_data));
|
| +}
|
| +
|
| +void VersionHandler::GetFlashVersion(const GetFlashVersionCallback& callback) {
|
| +#if defined(ENABLE_PLUGINS)
|
| + // The Flash version information is needed in the response, so make sure
|
| + // the plugins are loaded.
|
| + content::PluginService::GetInstance()->GetPlugins(base::Bind(
|
| + &VersionHandler::OnGotPlugins, weak_ptr_factory_.GetWeakPtr(), callback));
|
| +#endif
|
| +}
|
| +
|
| +void VersionHandler::GetVariations(const GetVariationsCallback& callback) {
|
| + std::vector<std::string> variations = version_ui::GetVariations();
|
| + callback.Run(variations);
|
| +}
|
| +
|
| +void VersionHandler::GetOsVersion(const GetOsVersionCallback& callback) {
|
| +#if defined(OS_CHROMEOS)
|
| + base::PostTaskAndReplyWithResult(
|
| + content::BrowserThread::GetBlockingPool(), FROM_HERE,
|
| + base::Bind(&chromeos::version_loader::GetVersion,
|
| + chromeos::version_loader::VERSION_FULL),
|
| + base::Bind(&VersionHandler::OnGotOsVersion,
|
| + weak_ptr_factory_.GetWeakPtr(), callback));
|
| +#endif // defined(OS_CHROMEOS)
|
| +}
|
| +
|
| +void VersionHandler::GetArcVersion(const GetArcVersionCallback& callback) {
|
| +#if defined(OS_CHROMEOS)
|
| + base::PostTaskAndReplyWithResult(
|
| + content::BrowserThread::GetBlockingPool(),
|
| + FROM_HERE,
|
| + base::Bind(&chromeos::version_loader::GetARCVersion),
|
| + base::Bind(&VersionHandler::OnGotArcVersion,
|
| + weak_ptr_factory_.GetWeakPtr(), callback));
|
| +#endif // defined(OS_CHROMEOS)
|
| +}
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| +void VersionHandler::OnGotOsVersion(const GetOsVersionCallback& callback,
|
| + const std::string& version) {
|
| + callback.Run(mojo::String::From(version));
|
| +}
|
|
|
| - base::StringValue exec_path(*executable_path_data);
|
| - base::StringValue profile_path(*profile_path_data);
|
| - web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnFilePaths,
|
| - exec_path, profile_path);
|
| +void VersionHandler::OnGotArcVersion(const GetArcVersionCallback& callback,
|
| + const std::string& version) {
|
| + callback.Run(mojo::String::From(version));
|
| }
|
| +#endif // defined(OS_CHROMEOS)
|
|
|
| #if defined(ENABLE_PLUGINS)
|
| void VersionHandler::OnGotPlugins(
|
| + const GetFlashVersionCallback& callback,
|
| const std::vector<content::WebPluginInfo>& plugins) {
|
| // Obtain the version of the first enabled Flash plugin.
|
| std::vector<content::WebPluginInfo> info_array;
|
| @@ -111,7 +146,7 @@ void VersionHandler::OnGotPlugins(
|
| base::string16 flash_version =
|
| l10n_util::GetStringUTF16(IDS_PLUGINS_DISABLED_PLUGIN);
|
| PluginPrefs* plugin_prefs =
|
| - PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())).get();
|
| + PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)).get();
|
| if (plugin_prefs) {
|
| for (size_t i = 0; i < info_array.size(); ++i) {
|
| if (plugin_prefs->IsPluginEnabled(info_array[i])) {
|
| @@ -121,7 +156,6 @@ void VersionHandler::OnGotPlugins(
|
| }
|
| }
|
|
|
| - base::StringValue arg(flash_version);
|
| - web_ui()->CallJavascriptFunctionUnsafe(version_ui::kReturnFlashVersion, arg);
|
| + callback.Run(mojo::String::From(flash_version));
|
| }
|
| #endif // defined(ENABLE_PLUGINS)
|
|
|