Commit 94676744 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Convert some ChromeSyncExtensionFunctions

SyncExtensionFunctions, AsyncExtensionFunctions,
ChromeSyncExtensionFunctions, and ChromeAsyncExtensionFunctions are
deprecated.

Remove ChromeSyncExtensionFunctions from:
- launcher_search_provider
- hotword_private
- i18n
- identity
- omnibox

BUG=634140

Review-Url: https://codereview.chromium.org/2344653002
Cr-Commit-Position: refs/heads/master@{#418733}
parent 9cedf753
...@@ -18,7 +18,8 @@ LauncherSearchProviderSetSearchResultsFunction:: ...@@ -18,7 +18,8 @@ LauncherSearchProviderSetSearchResultsFunction::
~LauncherSearchProviderSetSearchResultsFunction() { ~LauncherSearchProviderSetSearchResultsFunction() {
} }
bool LauncherSearchProviderSetSearchResultsFunction::RunSync() { ExtensionFunction::ResponseAction
LauncherSearchProviderSetSearchResultsFunction::Run() {
using chromeos::launcher_search_provider::ErrorReporter; using chromeos::launcher_search_provider::ErrorReporter;
using chromeos::launcher_search_provider::Service; using chromeos::launcher_search_provider::Service;
using extensions::api::launcher_search_provider::SetSearchResults::Params; using extensions::api::launcher_search_provider::SetSearchResults::Params;
...@@ -28,11 +29,11 @@ bool LauncherSearchProviderSetSearchResultsFunction::RunSync() { ...@@ -28,11 +29,11 @@ bool LauncherSearchProviderSetSearchResultsFunction::RunSync() {
std::unique_ptr<ErrorReporter> error_reporter( std::unique_ptr<ErrorReporter> error_reporter(
new ErrorReporter(render_frame_host())); new ErrorReporter(render_frame_host()));
Service* const service = Service::Get(GetProfile()); Service* const service = Service::Get(browser_context());
service->SetSearchResults(extension(), std::move(error_reporter), service->SetSearchResults(extension(), std::move(error_reporter),
params->query_id, params->results); params->query_id, params->results);
return true; return RespondNow(NoArguments());
} }
} // namespace extensions } // namespace extensions
...@@ -5,19 +5,19 @@ ...@@ -5,19 +5,19 @@
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_LAUNCHER_SEARCH_PROVIDER_H_ #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_LAUNCHER_SEARCH_PROVIDER_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_LAUNCHER_SEARCH_PROVIDER_H_ #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_LAUNCHER_SEARCH_PROVIDER_H_
#include "chrome/browser/extensions/chrome_extension_function.h" #include "extensions/browser/extension_function.h"
namespace extensions { namespace extensions {
// Implements chrome.launcherSearchProvider.setSearchResults method. // Implements chrome.launcherSearchProvider.setSearchResults method.
class LauncherSearchProviderSetSearchResultsFunction class LauncherSearchProviderSetSearchResultsFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("launcherSearchProvider.setSearchResults", DECLARE_EXTENSION_FUNCTION("launcherSearchProvider.setSearchResults",
LAUNCHERSEARCHPROVIDER_SETSEARCHRESULTS) LAUNCHERSEARCHPROVIDER_SETSEARCHRESULTS)
protected: protected:
~LauncherSearchProviderSetSearchResultsFunction() override; ~LauncherSearchProviderSetSearchResultsFunction() override;
bool RunSync() override; ResponseAction Run() override;
}; };
} // namespace extensions } // namespace extensions
......
...@@ -149,49 +149,55 @@ void HotwordPrivateEventService::SignalEvent( ...@@ -149,49 +149,55 @@ void HotwordPrivateEventService::SignalEvent(
router->BroadcastEvent(std::move(event)); router->BroadcastEvent(std::move(event));
} }
bool HotwordPrivateSetEnabledFunction::RunSync() { ExtensionFunction::ResponseAction HotwordPrivateSetEnabledFunction::Run() {
std::unique_ptr<api::hotword_private::SetEnabled::Params> params( std::unique_ptr<api::hotword_private::SetEnabled::Params> params(
api::hotword_private::SetEnabled::Params::Create(*args_)); api::hotword_private::SetEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
PrefService* prefs = GetProfile()->GetPrefs(); PrefService* prefs =
Profile::FromBrowserContext(browser_context())->GetPrefs();
prefs->SetBoolean(prefs::kHotwordSearchEnabled, params->state); prefs->SetBoolean(prefs::kHotwordSearchEnabled, params->state);
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateSetAudioLoggingEnabledFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateSetAudioLoggingEnabledFunction::Run() {
std::unique_ptr<api::hotword_private::SetAudioLoggingEnabled::Params> params( std::unique_ptr<api::hotword_private::SetAudioLoggingEnabled::Params> params(
api::hotword_private::SetAudioLoggingEnabled::Params::Create(*args_)); api::hotword_private::SetAudioLoggingEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
// TODO(kcarattini): Sync the chrome pref with the account-level // TODO(kcarattini): Sync the chrome pref with the account-level
// Audio History setting. // Audio History setting.
PrefService* prefs = GetProfile()->GetPrefs(); PrefService* prefs =
Profile::FromBrowserContext(browser_context())->GetPrefs();
prefs->SetBoolean(prefs::kHotwordAudioLoggingEnabled, params->state); prefs->SetBoolean(prefs::kHotwordAudioLoggingEnabled, params->state);
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction::Run() {
std::unique_ptr<api::hotword_private::SetHotwordAlwaysOnSearchEnabled::Params> std::unique_ptr<api::hotword_private::SetHotwordAlwaysOnSearchEnabled::Params>
params( params(
api::hotword_private::SetHotwordAlwaysOnSearchEnabled::Params::Create( api::hotword_private::SetHotwordAlwaysOnSearchEnabled::Params::Create(
*args_)); *args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
PrefService* prefs = GetProfile()->GetPrefs(); PrefService* prefs =
Profile::FromBrowserContext(browser_context())->GetPrefs();
prefs->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, params->state); prefs->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled, params->state);
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateGetStatusFunction::RunSync() { ExtensionFunction::ResponseAction HotwordPrivateGetStatusFunction::Run() {
std::unique_ptr<api::hotword_private::GetStatus::Params> params( std::unique_ptr<api::hotword_private::GetStatus::Params> params(
api::hotword_private::GetStatus::Params::Create(*args_)); api::hotword_private::GetStatus::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
api::hotword_private::StatusDetails result; api::hotword_private::StatusDetails result;
Profile* profile = Profile::FromBrowserContext(browser_context());
HotwordService* hotword_service = HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile()); HotwordServiceFactory::GetForProfile(profile);
if (!hotword_service) { if (!hotword_service) {
result.available = false; result.available = false;
result.always_on_available = false; result.always_on_available = false;
...@@ -217,28 +223,29 @@ bool HotwordPrivateGetStatusFunction::RunSync() { ...@@ -217,28 +223,29 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
HotwordService::IsHotwordHardwareAvailable(); HotwordService::IsHotwordHardwareAvailable();
} }
PrefService* prefs = GetProfile()->GetPrefs(); PrefService* prefs = profile->GetPrefs();
result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled);
SetResult(result.ToValue()); return RespondNow(OneArgument(result.ToValue()));
return true;
} }
bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateSetHotwordSessionStateFunction::Run() {
std::unique_ptr<api::hotword_private::SetHotwordSessionState::Params> params( std::unique_ptr<api::hotword_private::SetHotwordSessionState::Params> params(
api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); api::hotword_private::SetHotwordSessionState::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
HotwordService* hotword_service = HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
HotwordServiceFactory::GetForProfile(GetProfile()); Profile::FromBrowserContext(browser_context()));
if (hotword_service && if (hotword_service &&
hotword_service->client() && hotword_service->client() &&
!hotword_service->IsTraining()) !hotword_service->IsTraining())
hotword_service->client()->OnHotwordStateChanged(params->started); hotword_service->client()->OnHotwordStateChanged(params->started);
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateNotifyHotwordRecognitionFunction::Run() {
std::unique_ptr<api::hotword_private::NotifyHotwordRecognition::Params> std::unique_ptr<api::hotword_private::NotifyHotwordRecognition::Params>
params(api::hotword_private::NotifyHotwordRecognition::Params::Create( params(api::hotword_private::NotifyHotwordRecognition::Params::Create(
*args_)); *args_));
...@@ -255,8 +262,9 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { ...@@ -255,8 +262,9 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
preamble->sample_data.swap(params->log->buffer); preamble->sample_data.swap(params->log->buffer);
} }
Profile* profile = Profile::FromBrowserContext(browser_context());
HotwordService* hotword_service = HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(GetProfile()); HotwordServiceFactory::GetForProfile(profile);
if (hotword_service) { if (hotword_service) {
if (hotword_service->IsTraining()) { if (hotword_service->IsTraining()) {
hotword_service->NotifyHotwordTriggered(); hotword_service->NotifyHotwordTriggered();
...@@ -265,77 +273,80 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { ...@@ -265,77 +273,80 @@ bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() {
} else if (hotword_service->IsAlwaysOnEnabled()) { } else if (hotword_service->IsAlwaysOnEnabled()) {
AppListService* app_list_service = AppListService::Get(); AppListService* app_list_service = AppListService::Get();
CHECK(app_list_service); CHECK(app_list_service);
app_list_service->ShowForVoiceSearch(GetProfile(), preamble); app_list_service->ShowForVoiceSearch(profile, preamble);
} }
} }
return true;
return RespondNow(NoArguments());
} }
bool HotwordPrivateGetLaunchStateFunction::RunSync() { ExtensionFunction::ResponseAction HotwordPrivateGetLaunchStateFunction::Run() {
HotwordService* hotword_service = HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
HotwordServiceFactory::GetForProfile(GetProfile()); Profile::FromBrowserContext(browser_context()));
if (!hotword_service) { if (!hotword_service) {
error_ = hotword_private_constants::kHotwordServiceUnavailable; return RespondNow(
return false; Error(hotword_private_constants::kHotwordServiceUnavailable));
} }
api::hotword_private::LaunchState result; api::hotword_private::LaunchState result;
result.launch_mode = result.launch_mode =
hotword_service->GetHotwordAudioVerificationLaunchMode(); hotword_service->GetHotwordAudioVerificationLaunchMode();
SetResult(result.ToValue()); return RespondNow(OneArgument(result.ToValue()));
return true;
} }
bool HotwordPrivateStartTrainingFunction::RunSync() { ExtensionFunction::ResponseAction HotwordPrivateStartTrainingFunction::Run() {
HotwordService* hotword_service = HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
HotwordServiceFactory::GetForProfile(GetProfile()); Profile::FromBrowserContext(browser_context()));
if (!hotword_service) { if (!hotword_service) {
error_ = hotword_private_constants::kHotwordServiceUnavailable; return RespondNow(
return false; Error(hotword_private_constants::kHotwordServiceUnavailable));
} }
hotword_service->StartTraining(); hotword_service->StartTraining();
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateFinalizeSpeakerModelFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordService* hotword_service = HotwordPrivateFinalizeSpeakerModelFunction::Run() {
HotwordServiceFactory::GetForProfile(GetProfile()); HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
Profile::FromBrowserContext(browser_context()));
if (!hotword_service) { if (!hotword_service) {
error_ = hotword_private_constants::kHotwordServiceUnavailable; return RespondNow(
return false; Error(hotword_private_constants::kHotwordServiceUnavailable));
} }
hotword_service->FinalizeSpeakerModel(); hotword_service->FinalizeSpeakerModel();
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateNotifySpeakerModelSavedFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateNotifySpeakerModelSavedFunction::Run() {
HotwordPrivateEventService* event_service = HotwordPrivateEventService* event_service =
BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get( BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(
GetProfile()); Profile::FromBrowserContext(browser_context()));
if (!event_service) { if (!event_service) {
error_ = hotword_private_constants::kHotwordEventServiceUnavailable; return RespondNow(
return false; Error(hotword_private_constants::kHotwordEventServiceUnavailable));
} }
event_service->OnSpeakerModelSaved(); event_service->OnSpeakerModelSaved();
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateStopTrainingFunction::RunSync() { ExtensionFunction::ResponseAction HotwordPrivateStopTrainingFunction::Run() {
HotwordService* hotword_service = HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
HotwordServiceFactory::GetForProfile(GetProfile()); Profile::FromBrowserContext(browser_context()));
if (!hotword_service) { if (!hotword_service) {
error_ = hotword_private_constants::kHotwordServiceUnavailable; return RespondNow(
return false; Error(hotword_private_constants::kHotwordServiceUnavailable));
} }
hotword_service->StopTraining(); hotword_service->StopTraining();
return true; return RespondNow(NoArguments());
} }
bool HotwordPrivateGetLocalizedStringsFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateGetLocalizedStringsFunction::Run() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
base::string16 device_type = ash::GetChromeOSDeviceName(); base::string16 device_type = ash::GetChromeOSDeviceName();
#else #else
...@@ -454,8 +465,7 @@ bool HotwordPrivateGetLocalizedStringsFunction::RunSync() { ...@@ -454,8 +465,7 @@ bool HotwordPrivateGetLocalizedStringsFunction::RunSync() {
const std::string& app_locale = g_browser_process->GetApplicationLocale(); const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get());
SetResult(std::move(localized_strings)); return RespondNow(OneArgument(std::move(localized_strings)));
return true;
} }
bool HotwordPrivateSetAudioHistoryEnabledFunction::RunAsync() { bool HotwordPrivateSetAudioHistoryEnabledFunction::RunAsync() {
...@@ -511,19 +521,20 @@ void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse( ...@@ -511,19 +521,20 @@ void HotwordPrivateGetAudioHistoryEnabledFunction::SetResultAndSendResponse(
SendResponse(true); SendResponse(true);
} }
bool HotwordPrivateSpeakerModelExistsResultFunction::RunSync() { ExtensionFunction::ResponseAction
HotwordPrivateSpeakerModelExistsResultFunction::Run() {
std::unique_ptr<api::hotword_private::SpeakerModelExistsResult::Params> std::unique_ptr<api::hotword_private::SpeakerModelExistsResult::Params>
params(api::hotword_private::SpeakerModelExistsResult::Params::Create( params(api::hotword_private::SpeakerModelExistsResult::Params::Create(
*args_)); *args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
HotwordService* hotword_service = HotwordService* hotword_service = HotwordServiceFactory::GetForProfile(
HotwordServiceFactory::GetForProfile(GetProfile()); Profile::FromBrowserContext(browser_context()));
if (!hotword_service) if (!hotword_service)
return false; return RespondNow(Error(kUnknownErrorDoNotUse));
hotword_service->SpeakerModelExistsComplete(params->exists); hotword_service->SpeakerModelExistsComplete(params->exists);
return true; return RespondNow(NoArguments());
} }
} // namespace extensions } // namespace extensions
...@@ -60,8 +60,7 @@ class HotwordPrivateEventService : public BrowserContextKeyedAPI { ...@@ -60,8 +60,7 @@ class HotwordPrivateEventService : public BrowserContextKeyedAPI {
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
}; };
class HotwordPrivateSetEnabledFunction : public UIThreadExtensionFunction {
class HotwordPrivateSetEnabledFunction : public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setEnabled", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setEnabled",
HOTWORDPRIVATE_SETENABLED) HOTWORDPRIVATE_SETENABLED)
...@@ -70,11 +69,11 @@ class HotwordPrivateSetEnabledFunction : public ChromeSyncExtensionFunction { ...@@ -70,11 +69,11 @@ class HotwordPrivateSetEnabledFunction : public ChromeSyncExtensionFunction {
~HotwordPrivateSetEnabledFunction() override {} ~HotwordPrivateSetEnabledFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateSetAudioLoggingEnabledFunction class HotwordPrivateSetAudioLoggingEnabledFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setAudioLoggingEnabled", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setAudioLoggingEnabled",
HOTWORDPRIVATE_SETAUDIOLOGGINGENABLED) HOTWORDPRIVATE_SETAUDIOLOGGINGENABLED)
...@@ -83,11 +82,11 @@ class HotwordPrivateSetAudioLoggingEnabledFunction ...@@ -83,11 +82,11 @@ class HotwordPrivateSetAudioLoggingEnabledFunction
~HotwordPrivateSetAudioLoggingEnabledFunction() override {} ~HotwordPrivateSetAudioLoggingEnabledFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordAlwaysOnSearchEnabled", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordAlwaysOnSearchEnabled",
HOTWORDPRIVATE_SETHOTWORDALWAYSONSEARCHENABLED) HOTWORDPRIVATE_SETHOTWORDALWAYSONSEARCHENABLED)
...@@ -96,10 +95,10 @@ class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction ...@@ -96,10 +95,10 @@ class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction
~HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction() override {} ~HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateGetStatusFunction : public ChromeSyncExtensionFunction { class HotwordPrivateGetStatusFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getStatus", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getStatus",
HOTWORDPRIVATE_GETSTATUS) HOTWORDPRIVATE_GETSTATUS)
...@@ -108,11 +107,11 @@ class HotwordPrivateGetStatusFunction : public ChromeSyncExtensionFunction { ...@@ -108,11 +107,11 @@ class HotwordPrivateGetStatusFunction : public ChromeSyncExtensionFunction {
~HotwordPrivateGetStatusFunction() override {} ~HotwordPrivateGetStatusFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateSetHotwordSessionStateFunction class HotwordPrivateSetHotwordSessionStateFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordSessionState", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordSessionState",
HOTWORDPRIVATE_SETHOTWORDSESSIONSTATE); HOTWORDPRIVATE_SETHOTWORDSESSIONSTATE);
...@@ -121,11 +120,11 @@ class HotwordPrivateSetHotwordSessionStateFunction ...@@ -121,11 +120,11 @@ class HotwordPrivateSetHotwordSessionStateFunction
~HotwordPrivateSetHotwordSessionStateFunction() override {} ~HotwordPrivateSetHotwordSessionStateFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateNotifyHotwordRecognitionFunction class HotwordPrivateNotifyHotwordRecognitionFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifyHotwordRecognition", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifyHotwordRecognition",
HOTWORDPRIVATE_NOTIFYHOTWORDRECOGNITION); HOTWORDPRIVATE_NOTIFYHOTWORDRECOGNITION);
...@@ -134,11 +133,10 @@ class HotwordPrivateNotifyHotwordRecognitionFunction ...@@ -134,11 +133,10 @@ class HotwordPrivateNotifyHotwordRecognitionFunction
~HotwordPrivateNotifyHotwordRecognitionFunction() override {} ~HotwordPrivateNotifyHotwordRecognitionFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateGetLaunchStateFunction : class HotwordPrivateGetLaunchStateFunction : public UIThreadExtensionFunction {
public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLaunchState", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLaunchState",
HOTWORDPRIVATE_GETLAUNCHSTATE) HOTWORDPRIVATE_GETLAUNCHSTATE)
...@@ -147,11 +145,10 @@ class HotwordPrivateGetLaunchStateFunction : ...@@ -147,11 +145,10 @@ class HotwordPrivateGetLaunchStateFunction :
~HotwordPrivateGetLaunchStateFunction() override {} ~HotwordPrivateGetLaunchStateFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateStartTrainingFunction : class HotwordPrivateStartTrainingFunction : public UIThreadExtensionFunction {
public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.startTraining", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.startTraining",
HOTWORDPRIVATE_STARTTRAINING) HOTWORDPRIVATE_STARTTRAINING)
...@@ -160,11 +157,11 @@ class HotwordPrivateStartTrainingFunction : ...@@ -160,11 +157,11 @@ class HotwordPrivateStartTrainingFunction :
~HotwordPrivateStartTrainingFunction() override {} ~HotwordPrivateStartTrainingFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateFinalizeSpeakerModelFunction : class HotwordPrivateFinalizeSpeakerModelFunction
public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.finalizeSpeakerModel", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.finalizeSpeakerModel",
HOTWORDPRIVATE_FINALIZESPEAKERMODEL) HOTWORDPRIVATE_FINALIZESPEAKERMODEL)
...@@ -173,11 +170,11 @@ class HotwordPrivateFinalizeSpeakerModelFunction : ...@@ -173,11 +170,11 @@ class HotwordPrivateFinalizeSpeakerModelFunction :
~HotwordPrivateFinalizeSpeakerModelFunction() override {} ~HotwordPrivateFinalizeSpeakerModelFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateNotifySpeakerModelSavedFunction : class HotwordPrivateNotifySpeakerModelSavedFunction
public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifySpeakerModelSaved", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifySpeakerModelSaved",
HOTWORDPRIVATE_NOTIFYSPEAKERMODELSAVED) HOTWORDPRIVATE_NOTIFYSPEAKERMODELSAVED)
...@@ -186,11 +183,10 @@ class HotwordPrivateNotifySpeakerModelSavedFunction : ...@@ -186,11 +183,10 @@ class HotwordPrivateNotifySpeakerModelSavedFunction :
~HotwordPrivateNotifySpeakerModelSavedFunction() override {} ~HotwordPrivateNotifySpeakerModelSavedFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateStopTrainingFunction : class HotwordPrivateStopTrainingFunction : public UIThreadExtensionFunction {
public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.stopTraining", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.stopTraining",
HOTWORDPRIVATE_STOPTRAINING) HOTWORDPRIVATE_STOPTRAINING)
...@@ -199,11 +195,11 @@ class HotwordPrivateStopTrainingFunction : ...@@ -199,11 +195,11 @@ class HotwordPrivateStopTrainingFunction :
~HotwordPrivateStopTrainingFunction() override {} ~HotwordPrivateStopTrainingFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateGetLocalizedStringsFunction class HotwordPrivateGetLocalizedStringsFunction
: public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLocalizedStrings", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLocalizedStrings",
HOTWORDPRIVATE_GETLOCALIZEDSTRINGS) HOTWORDPRIVATE_GETLOCALIZEDSTRINGS)
...@@ -212,7 +208,7 @@ class HotwordPrivateGetLocalizedStringsFunction ...@@ -212,7 +208,7 @@ class HotwordPrivateGetLocalizedStringsFunction
~HotwordPrivateGetLocalizedStringsFunction() override {} ~HotwordPrivateGetLocalizedStringsFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class HotwordPrivateSetAudioHistoryEnabledFunction class HotwordPrivateSetAudioHistoryEnabledFunction
...@@ -245,8 +241,8 @@ class HotwordPrivateGetAudioHistoryEnabledFunction ...@@ -245,8 +241,8 @@ class HotwordPrivateGetAudioHistoryEnabledFunction
void SetResultAndSendResponse(bool success, bool new_enabled_value); void SetResultAndSendResponse(bool success, bool new_enabled_value);
}; };
class HotwordPrivateSpeakerModelExistsResultFunction : class HotwordPrivateSpeakerModelExistsResultFunction
public ChromeSyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.speakerModelExistsResult", DECLARE_EXTENSION_FUNCTION("hotwordPrivate.speakerModelExistsResult",
HOTWORDPRIVATE_SPEAKERMODELEXISTSRESULT) HOTWORDPRIVATE_SPEAKERMODELEXISTSRESULT)
...@@ -255,7 +251,7 @@ class HotwordPrivateSpeakerModelExistsResultFunction : ...@@ -255,7 +251,7 @@ class HotwordPrivateSpeakerModelExistsResultFunction :
~HotwordPrivateSpeakerModelExistsResultFunction() override {} ~HotwordPrivateSpeakerModelExistsResultFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
} // namespace extensions } // namespace extensions
......
...@@ -27,9 +27,10 @@ static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty."; ...@@ -27,9 +27,10 @@ static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty.";
} }
bool I18nGetAcceptLanguagesFunction::RunSync() { ExtensionFunction::ResponseAction I18nGetAcceptLanguagesFunction::Run() {
std::string accept_languages = std::string accept_languages = Profile::FromBrowserContext(browser_context())
GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); ->GetPrefs()
->GetString(prefs::kAcceptLanguages);
// Currently, there are 2 ways to set browser's accept-languages: through UI // Currently, there are 2 ways to set browser's accept-languages: through UI
// or directly modify the preference file. The accept-languages set through // or directly modify the preference file. The accept-languages set through
// UI is guranteed to be valid, and the accept-languages string returned from // UI is guranteed to be valid, and the accept-languages string returned from
...@@ -40,23 +41,19 @@ bool I18nGetAcceptLanguagesFunction::RunSync() { ...@@ -40,23 +41,19 @@ bool I18nGetAcceptLanguagesFunction::RunSync() {
// of the language code) on accept-languages set through editing preference // of the language code) on accept-languages set through editing preference
// file directly. So, here, we're adding extra checks to be resistant to // file directly. So, here, we're adding extra checks to be resistant to
// crashes caused by data corruption. // crashes caused by data corruption.
if (accept_languages.empty()) { if (accept_languages.empty())
error_ = kEmptyAcceptLanguagesError; return RespondNow(Error(kEmptyAcceptLanguagesError));
return false;
}
std::vector<std::string> languages = base::SplitString( std::vector<std::string> languages = base::SplitString(
accept_languages, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); accept_languages, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
languages.erase(std::remove(languages.begin(), languages.end(), ""), languages.erase(std::remove(languages.begin(), languages.end(), ""),
languages.end()); languages.end());
if (languages.empty()) { if (languages.empty())
error_ = kEmptyAcceptLanguagesError; return RespondNow(Error(kEmptyAcceptLanguagesError));
return false;
}
results_ = GetAcceptLanguages::Results::Create(languages); return RespondNow(
return true; ArgumentList(GetAcceptLanguages::Results::Create(languages)));
} }
} // namespace extensions } // namespace extensions
...@@ -5,16 +5,13 @@ ...@@ -5,16 +5,13 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ #ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_ #define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
#include "chrome/browser/extensions/chrome_extension_function.h" #include "extensions/browser/extension_function.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
class Profile;
namespace extensions { namespace extensions {
class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction { class I18nGetAcceptLanguagesFunction : public UIThreadExtensionFunction {
~I18nGetAcceptLanguagesFunction() override {} ~I18nGetAcceptLanguagesFunction() override {}
bool RunSync() override; ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES) DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
}; };
......
...@@ -928,18 +928,17 @@ IdentityRemoveCachedAuthTokenFunction:: ...@@ -928,18 +928,17 @@ IdentityRemoveCachedAuthTokenFunction::
~IdentityRemoveCachedAuthTokenFunction() { ~IdentityRemoveCachedAuthTokenFunction() {
} }
bool IdentityRemoveCachedAuthTokenFunction::RunSync() { ExtensionFunction::ResponseAction IdentityRemoveCachedAuthTokenFunction::Run() {
if (GetProfile()->IsOffTheRecord()) { if (Profile::FromBrowserContext(browser_context())->IsOffTheRecord())
error_ = identity_constants::kOffTheRecord; return RespondNow(Error(identity_constants::kOffTheRecord));
return false;
}
std::unique_ptr<identity::RemoveCachedAuthToken::Params> params( std::unique_ptr<identity::RemoveCachedAuthToken::Params> params(
identity::RemoveCachedAuthToken::Params::Create(*args_)); identity::RemoveCachedAuthToken::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
IdentityAPI::GetFactoryInstance()->Get(GetProfile())->EraseCachedToken( IdentityAPI::GetFactoryInstance()
extension()->id(), params->details.token); ->Get(browser_context())
return true; ->EraseCachedToken(extension()->id(), params->details.token);
return RespondNow(NoArguments());
} }
IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {} IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {}
......
...@@ -318,8 +318,7 @@ class IdentityGetProfileUserInfoFunction ...@@ -318,8 +318,7 @@ class IdentityGetProfileUserInfoFunction
ExtensionFunction::ResponseAction Run() override; ExtensionFunction::ResponseAction Run() override;
}; };
class IdentityRemoveCachedAuthTokenFunction class IdentityRemoveCachedAuthTokenFunction : public UIThreadExtensionFunction {
: public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken", DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken",
EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN) EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN)
...@@ -328,8 +327,8 @@ class IdentityRemoveCachedAuthTokenFunction ...@@ -328,8 +327,8 @@ class IdentityRemoveCachedAuthTokenFunction
protected: protected:
~IdentityRemoveCachedAuthTokenFunction() override; ~IdentityRemoveCachedAuthTokenFunction() override;
// SyncExtensionFunction implementation: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class IdentityLaunchWebAuthFlowFunction : public ChromeAsyncExtensionFunction, class IdentityLaunchWebAuthFlowFunction : public ChromeAsyncExtensionFunction,
......
...@@ -284,33 +284,35 @@ void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() { ...@@ -284,33 +284,35 @@ void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() {
DependsOn(TemplateURLServiceFactory::GetInstance()); DependsOn(TemplateURLServiceFactory::GetInstance());
} }
bool OmniboxSendSuggestionsFunction::RunSync() { ExtensionFunction::ResponseAction OmniboxSendSuggestionsFunction::Run() {
std::unique_ptr<SendSuggestions::Params> params( std::unique_ptr<SendSuggestions::Params> params(
SendSuggestions::Params::Create(*args_)); SendSuggestions::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY,
content::Source<Profile>(GetProfile()->GetOriginalProfile()), content::Source<Profile>(
Profile::FromBrowserContext(browser_context())->GetOriginalProfile()),
content::Details<SendSuggestions::Params>(params.get())); content::Details<SendSuggestions::Params>(params.get()));
return true; return RespondNow(NoArguments());
} }
bool OmniboxSetDefaultSuggestionFunction::RunSync() { ExtensionFunction::ResponseAction OmniboxSetDefaultSuggestionFunction::Run() {
std::unique_ptr<SetDefaultSuggestion::Params> params( std::unique_ptr<SetDefaultSuggestion::Params> params(
SetDefaultSuggestion::Params::Create(*args_)); SetDefaultSuggestion::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
if (SetOmniboxDefaultSuggestion( Profile* profile = Profile::FromBrowserContext(browser_context());
GetProfile(), extension_id(), params->suggestion)) { if (SetOmniboxDefaultSuggestion(profile, extension_id(),
params->suggestion)) {
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED,
content::Source<Profile>(GetProfile()->GetOriginalProfile()), content::Source<Profile>(profile->GetOriginalProfile()),
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
} }
return true; return RespondNow(NoArguments());
} }
// This function converts style information populated by the JSON schema // This function converts style information populated by the JSON schema
......
...@@ -73,7 +73,7 @@ class ExtensionOmniboxEventRouter { ...@@ -73,7 +73,7 @@ class ExtensionOmniboxEventRouter {
DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter); DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter);
}; };
class OmniboxSendSuggestionsFunction : public ChromeSyncExtensionFunction { class OmniboxSendSuggestionsFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("omnibox.sendSuggestions", OMNIBOX_SENDSUGGESTIONS) DECLARE_EXTENSION_FUNCTION("omnibox.sendSuggestions", OMNIBOX_SENDSUGGESTIONS)
...@@ -81,7 +81,7 @@ class OmniboxSendSuggestionsFunction : public ChromeSyncExtensionFunction { ...@@ -81,7 +81,7 @@ class OmniboxSendSuggestionsFunction : public ChromeSyncExtensionFunction {
~OmniboxSendSuggestionsFunction() override {} ~OmniboxSendSuggestionsFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class OmniboxAPI : public BrowserContextKeyedAPI, class OmniboxAPI : public BrowserContextKeyedAPI,
...@@ -150,7 +150,7 @@ class OmniboxAPI : public BrowserContextKeyedAPI, ...@@ -150,7 +150,7 @@ class OmniboxAPI : public BrowserContextKeyedAPI,
template <> template <>
void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies(); void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies();
class OmniboxSetDefaultSuggestionFunction : public ChromeSyncExtensionFunction { class OmniboxSetDefaultSuggestionFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("omnibox.setDefaultSuggestion", DECLARE_EXTENSION_FUNCTION("omnibox.setDefaultSuggestion",
OMNIBOX_SETDEFAULTSUGGESTION) OMNIBOX_SETDEFAULTSUGGESTION)
...@@ -159,7 +159,7 @@ class OmniboxSetDefaultSuggestionFunction : public ChromeSyncExtensionFunction { ...@@ -159,7 +159,7 @@ class OmniboxSetDefaultSuggestionFunction : public ChromeSyncExtensionFunction {
~OmniboxSetDefaultSuggestionFunction() override {} ~OmniboxSetDefaultSuggestionFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
// If the extension has set a custom default suggestion via // If the extension has set a custom default suggestion via
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment