Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: chrome/browser/ui/webui/voicesearch_ui.cc

Issue 804193003: Display shared module platforms on about://voicesearch page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..95688d06437bdf7fc73238ba17c9b70d9820899d 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,33 @@ 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);
+ AddLineBreak(list);
+ }
+
+ content::BrowserThread::PostTask(content::BrowserThread::UI,
+ FROM_HERE,
+ callback);
+}
+
////////////////////////////////////////////////////////////////////////////////
//
// VoiceSearchDomHandler
@@ -98,7 +128,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 +145,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
Evan Stade 2015/01/05 19:13:38 nit: remove this comment
Anand Mistry (off Chromium) 2015/01/05 23:33:01 Done.
+ // 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 +168,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 +180,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) {
Evan Stade 2015/01/05 19:13:38 nit: no curlies
Anand Mistry (off Chromium) 2015/01/05 23:33:01 Done.
+ path = extension->path();
+ }
+ }
+ // Temporary, unowned ptr to |list| to pass into
+ // AddSharedModulePlatformsOnFileThread.
Evan Stade 2015/01/05 19:13:38 nit: remove comment
Anand Mistry (off Chromium) 2015/01/05 23:33:01 Done.
+ 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))));
Evan Stade 2015/01/05 19:13:38 optional nit: I think list.Pass() is more self-doc
Anand Mistry (off Chromium) 2015/01/05 23:33:01 It fails to compile: ../../base/bind_internal.h:1
Evan Stade 2015/01/06 01:07:19 base::Passed(list.Pass());
Anand Mistry (off Chromium) 2015/01/06 01:53:33 Done.
}
// Adds information regarding the system and chrome version info to list.
@@ -366,10 +428,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);
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698