Chromium Code Reviews| Index: chrome/browser/ui/webui/voicesearch_ui.cc |
| diff --git a/chrome/browser/ui/webui/voicesearch_ui.cc b/chrome/browser/ui/webui/voicesearch_ui.cc |
| index dc62edfaa120024a087583a03c6acdd8fc76f944..774d490d7c21830cf45626c111382535fd25199c 100644 |
| --- a/chrome/browser/ui/webui/voicesearch_ui.cc |
| +++ b/chrome/browser/ui/webui/voicesearch_ui.cc |
| @@ -7,6 +7,8 @@ |
| #include <string> |
| #include "base/command_line.h" |
| +#include "base/files/file_enumerator.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/metrics/field_trial.h" |
| #include "base/path_service.h" |
| #include "base/prefs/pref_service.h" |
| @@ -29,6 +31,7 @@ |
| #include "chrome/grit/chromium_strings.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chrome/grit/google_chrome_strings.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/plugin_service.h" |
| #include "content/public/browser/url_data_source.h" |
| #include "content/public/browser/web_ui.h" |
| @@ -89,6 +92,34 @@ void AddLineBreak(base::ListValue* list) { |
| AddPair(list, "", ""); |
| } |
| +void AddSharedModulePlatformsOnFileThread(base::ListValue* list, |
| + const base::FilePath& path, |
| + base::Closure callback) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| + |
| + if (!path.empty()) { |
| + // Display available platforms for shared module. |
| + base::FilePath platforms_path = path.AppendASCII("_platform_specific"); |
| + base::FileEnumerator enumerator( |
| + platforms_path, false, base::FileEnumerator::DIRECTORIES); |
| + base::string16 files; |
| + for (base::FilePath name = enumerator.Next(); |
| + !name.empty(); |
| + name = enumerator.Next()) { |
| + files += name.BaseName().LossyDisplayName() + ASCIIToUTF16(" "); |
| + } |
| + AddPair16(list, |
| + ASCIIToUTF16("Shared Module Platforms"), |
| + files.empty() ? |
| + ASCIIToUTF16("undefined") : files); |
|
rpetterson
2015/01/05 03:57:30
move to the line above or indent
Anand Mistry (off Chromium)
2015/01/05 04:11:48
Done.
|
| + AddLineBreak(list); |
| + } |
| + |
| + content::BrowserThread::PostTask(content::BrowserThread::UI, |
| + FROM_HERE, |
| + callback); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // |
| // VoiceSearchDomHandler |
| @@ -98,7 +129,9 @@ void AddLineBreak(base::ListValue* list) { |
| // The handler for Javascript messages for the about:flags page. |
| class VoiceSearchDomHandler : public WebUIMessageHandler { |
| public: |
| - explicit VoiceSearchDomHandler(Profile* profile) : profile_(profile) {} |
| + explicit VoiceSearchDomHandler(Profile* profile) |
| + : profile_(profile), |
| + weak_factory_(this) {} |
| ~VoiceSearchDomHandler() override {} |
| @@ -113,14 +146,21 @@ class VoiceSearchDomHandler : public WebUIMessageHandler { |
| private: |
| // Callback for the "requestVoiceSearchInfo" message. No arguments. |
| void HandleRequestVoiceSearchInfo(const base::ListValue* args) { |
| + PopulatePageInformation(); |
| + } |
| + |
| + void ReturnVoiceSearchInfo(scoped_ptr<base::ListValue> info) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(info); |
| base::DictionaryValue voiceSearchInfo; |
| - PopulatePageInformation(&voiceSearchInfo); |
| - web_ui()->CallJavascriptFunction("returnVoiceSearchInfo", |
| - voiceSearchInfo); |
| + // voiceSearchInfo will take ownership of |info|, and clean it up on |
| + // destruction. |
| + voiceSearchInfo.Set("voiceSearchInfo", info.release()); |
| + web_ui()->CallJavascriptFunction("returnVoiceSearchInfo", voiceSearchInfo); |
| } |
| // Fill in the data to be displayed on the page. |
| - void PopulatePageInformation(base::DictionaryValue* voiceSearchInfo) { |
| + void PopulatePageInformation() { |
| // Store Key-Value pairs of about-information. |
| scoped_ptr<base::ListValue> list(new base::ListValue()); |
| @@ -129,6 +169,7 @@ class VoiceSearchDomHandler : public WebUIMessageHandler { |
| AddAudioInfo(list.get()); |
| AddLanguageInfo(list.get()); |
| AddHotwordInfo(list.get()); |
| + AddAppListInfo(list.get()); |
| std::string extension_id = extension_misc::kHotwordExtensionId; |
| HotwordService* hotword_service = |
| @@ -140,11 +181,33 @@ class VoiceSearchDomHandler : public WebUIMessageHandler { |
| AddExtensionInfo(extension_misc::kHotwordSharedModuleId, |
| "Shared Module", |
| list.get()); |
| - AddAppListInfo(list.get()); |
| - // voiceSearchInfo will take ownership of list, and clean it up on |
| - // destruction. |
| - voiceSearchInfo->Set("voiceSearchInfo", list.release()); |
| + base::FilePath path; |
| + extensions::ExtensionSystem* extension_system = |
| + extensions::ExtensionSystem::Get(profile_); |
| + if (extension_system) { |
| + ExtensionService* extension_service = |
| + extension_system->extension_service(); |
| + const extensions::Extension* extension = |
| + extension_service->GetExtensionById( |
| + extension_misc::kHotwordSharedModuleId, true); |
| + if (extension) { |
| + path = extension->path(); |
| + } |
| + } |
| + // Temporary, unowned ptr to |list| to pass into |
| + // AddSharedModulePlatformsOnFileThread. |
| + base::ListValue* raw_list = list.get(); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind( |
| + &AddSharedModulePlatformsOnFileThread, |
| + raw_list, |
| + path, |
| + base::Bind(&VoiceSearchDomHandler::ReturnVoiceSearchInfo, |
| + weak_factory_.GetWeakPtr(), |
| + base::Passed(&list)))); |
| } |
| // Adds information regarding the system and chrome version info to list. |
| @@ -366,10 +429,12 @@ class VoiceSearchDomHandler : public WebUIMessageHandler { |
| } |
| } |
| AddPair(list, "Start Page State", state); |
| + AddLineBreak(list); |
| #endif |
| } |
| Profile* profile_; |
| + base::WeakPtrFactory<VoiceSearchDomHandler> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(VoiceSearchDomHandler); |
| }; |