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::
~LauncherSearchProviderSetSearchResultsFunction() {
}
bool LauncherSearchProviderSetSearchResultsFunction::RunSync() {
ExtensionFunction::ResponseAction
LauncherSearchProviderSetSearchResultsFunction::Run() {
using chromeos::launcher_search_provider::ErrorReporter;
using chromeos::launcher_search_provider::Service;
using extensions::api::launcher_search_provider::SetSearchResults::Params;
......@@ -28,11 +29,11 @@ bool LauncherSearchProviderSetSearchResultsFunction::RunSync() {
std::unique_ptr<ErrorReporter> error_reporter(
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),
params->query_id, params->results);
return true;
return RespondNow(NoArguments());
}
} // namespace extensions
......@@ -5,19 +5,19 @@
#ifndef 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 {
// Implements chrome.launcherSearchProvider.setSearchResults method.
class LauncherSearchProviderSetSearchResultsFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("launcherSearchProvider.setSearchResults",
LAUNCHERSEARCHPROVIDER_SETSEARCHRESULTS)
protected:
~LauncherSearchProviderSetSearchResultsFunction() override;
bool RunSync() override;
ResponseAction Run() override;
};
} // namespace extensions
......
......@@ -60,8 +60,7 @@ class HotwordPrivateEventService : public BrowserContextKeyedAPI {
PrefChangeRegistrar pref_change_registrar_;
};
class HotwordPrivateSetEnabledFunction : public ChromeSyncExtensionFunction {
class HotwordPrivateSetEnabledFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setEnabled",
HOTWORDPRIVATE_SETENABLED)
......@@ -70,11 +69,11 @@ class HotwordPrivateSetEnabledFunction : public ChromeSyncExtensionFunction {
~HotwordPrivateSetEnabledFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateSetAudioLoggingEnabledFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setAudioLoggingEnabled",
HOTWORDPRIVATE_SETAUDIOLOGGINGENABLED)
......@@ -83,11 +82,11 @@ class HotwordPrivateSetAudioLoggingEnabledFunction
~HotwordPrivateSetAudioLoggingEnabledFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordAlwaysOnSearchEnabled",
HOTWORDPRIVATE_SETHOTWORDALWAYSONSEARCHENABLED)
......@@ -96,10 +95,10 @@ class HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction
~HotwordPrivateSetHotwordAlwaysOnSearchEnabledFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateGetStatusFunction : public ChromeSyncExtensionFunction {
class HotwordPrivateGetStatusFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getStatus",
HOTWORDPRIVATE_GETSTATUS)
......@@ -108,11 +107,11 @@ class HotwordPrivateGetStatusFunction : public ChromeSyncExtensionFunction {
~HotwordPrivateGetStatusFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateSetHotwordSessionStateFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.setHotwordSessionState",
HOTWORDPRIVATE_SETHOTWORDSESSIONSTATE);
......@@ -121,11 +120,11 @@ class HotwordPrivateSetHotwordSessionStateFunction
~HotwordPrivateSetHotwordSessionStateFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateNotifyHotwordRecognitionFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifyHotwordRecognition",
HOTWORDPRIVATE_NOTIFYHOTWORDRECOGNITION);
......@@ -134,11 +133,10 @@ class HotwordPrivateNotifyHotwordRecognitionFunction
~HotwordPrivateNotifyHotwordRecognitionFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateGetLaunchStateFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateGetLaunchStateFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLaunchState",
HOTWORDPRIVATE_GETLAUNCHSTATE)
......@@ -147,11 +145,10 @@ class HotwordPrivateGetLaunchStateFunction :
~HotwordPrivateGetLaunchStateFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateStartTrainingFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateStartTrainingFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.startTraining",
HOTWORDPRIVATE_STARTTRAINING)
......@@ -160,11 +157,11 @@ class HotwordPrivateStartTrainingFunction :
~HotwordPrivateStartTrainingFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateFinalizeSpeakerModelFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateFinalizeSpeakerModelFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.finalizeSpeakerModel",
HOTWORDPRIVATE_FINALIZESPEAKERMODEL)
......@@ -173,11 +170,11 @@ class HotwordPrivateFinalizeSpeakerModelFunction :
~HotwordPrivateFinalizeSpeakerModelFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateNotifySpeakerModelSavedFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateNotifySpeakerModelSavedFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.notifySpeakerModelSaved",
HOTWORDPRIVATE_NOTIFYSPEAKERMODELSAVED)
......@@ -186,11 +183,10 @@ class HotwordPrivateNotifySpeakerModelSavedFunction :
~HotwordPrivateNotifySpeakerModelSavedFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateStopTrainingFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateStopTrainingFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.stopTraining",
HOTWORDPRIVATE_STOPTRAINING)
......@@ -199,11 +195,11 @@ class HotwordPrivateStopTrainingFunction :
~HotwordPrivateStopTrainingFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateGetLocalizedStringsFunction
: public ChromeSyncExtensionFunction {
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.getLocalizedStrings",
HOTWORDPRIVATE_GETLOCALIZEDSTRINGS)
......@@ -212,7 +208,7 @@ class HotwordPrivateGetLocalizedStringsFunction
~HotwordPrivateGetLocalizedStringsFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class HotwordPrivateSetAudioHistoryEnabledFunction
......@@ -245,8 +241,8 @@ class HotwordPrivateGetAudioHistoryEnabledFunction
void SetResultAndSendResponse(bool success, bool new_enabled_value);
};
class HotwordPrivateSpeakerModelExistsResultFunction :
public ChromeSyncExtensionFunction {
class HotwordPrivateSpeakerModelExistsResultFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("hotwordPrivate.speakerModelExistsResult",
HOTWORDPRIVATE_SPEAKERMODELEXISTSRESULT)
......@@ -255,7 +251,7 @@ class HotwordPrivateSpeakerModelExistsResultFunction :
~HotwordPrivateSpeakerModelExistsResultFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
} // namespace extensions
......
......@@ -27,9 +27,10 @@ static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty.";
}
bool I18nGetAcceptLanguagesFunction::RunSync() {
std::string accept_languages =
GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
ExtensionFunction::ResponseAction I18nGetAcceptLanguagesFunction::Run() {
std::string accept_languages = Profile::FromBrowserContext(browser_context())
->GetPrefs()
->GetString(prefs::kAcceptLanguages);
// Currently, there are 2 ways to set browser's accept-languages: through UI
// or directly modify the preference file. The accept-languages set through
// UI is guranteed to be valid, and the accept-languages string returned from
......@@ -40,23 +41,19 @@ bool I18nGetAcceptLanguagesFunction::RunSync() {
// of the language code) on accept-languages set through editing preference
// file directly. So, here, we're adding extra checks to be resistant to
// crashes caused by data corruption.
if (accept_languages.empty()) {
error_ = kEmptyAcceptLanguagesError;
return false;
}
if (accept_languages.empty())
return RespondNow(Error(kEmptyAcceptLanguagesError));
std::vector<std::string> languages = base::SplitString(
accept_languages, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
languages.erase(std::remove(languages.begin(), languages.end(), ""),
languages.end());
if (languages.empty()) {
error_ = kEmptyAcceptLanguagesError;
return false;
}
if (languages.empty())
return RespondNow(Error(kEmptyAcceptLanguagesError));
results_ = GetAcceptLanguages::Results::Create(languages);
return true;
return RespondNow(
ArgumentList(GetAcceptLanguages::Results::Create(languages)));
}
} // namespace extensions
......@@ -5,16 +5,13 @@
#ifndef 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/browser_context_keyed_api_factory.h"
class Profile;
#include "extensions/browser/extension_function.h"
namespace extensions {
class I18nGetAcceptLanguagesFunction : public ChromeSyncExtensionFunction {
class I18nGetAcceptLanguagesFunction : public UIThreadExtensionFunction {
~I18nGetAcceptLanguagesFunction() override {}
bool RunSync() override;
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
};
......
......@@ -928,18 +928,17 @@ IdentityRemoveCachedAuthTokenFunction::
~IdentityRemoveCachedAuthTokenFunction() {
}
bool IdentityRemoveCachedAuthTokenFunction::RunSync() {
if (GetProfile()->IsOffTheRecord()) {
error_ = identity_constants::kOffTheRecord;
return false;
}
ExtensionFunction::ResponseAction IdentityRemoveCachedAuthTokenFunction::Run() {
if (Profile::FromBrowserContext(browser_context())->IsOffTheRecord())
return RespondNow(Error(identity_constants::kOffTheRecord));
std::unique_ptr<identity::RemoveCachedAuthToken::Params> params(
identity::RemoveCachedAuthToken::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
IdentityAPI::GetFactoryInstance()->Get(GetProfile())->EraseCachedToken(
extension()->id(), params->details.token);
return true;
IdentityAPI::GetFactoryInstance()
->Get(browser_context())
->EraseCachedToken(extension()->id(), params->details.token);
return RespondNow(NoArguments());
}
IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {}
......
......@@ -318,8 +318,7 @@ class IdentityGetProfileUserInfoFunction
ExtensionFunction::ResponseAction Run() override;
};
class IdentityRemoveCachedAuthTokenFunction
: public ChromeSyncExtensionFunction {
class IdentityRemoveCachedAuthTokenFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken",
EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN)
......@@ -328,8 +327,8 @@ class IdentityRemoveCachedAuthTokenFunction
protected:
~IdentityRemoveCachedAuthTokenFunction() override;
// SyncExtensionFunction implementation:
bool RunSync() override;
// ExtensionFunction:
ResponseAction Run() override;
};
class IdentityLaunchWebAuthFlowFunction : public ChromeAsyncExtensionFunction,
......
......@@ -284,33 +284,35 @@ void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() {
DependsOn(TemplateURLServiceFactory::GetInstance());
}
bool OmniboxSendSuggestionsFunction::RunSync() {
ExtensionFunction::ResponseAction OmniboxSendSuggestionsFunction::Run() {
std::unique_ptr<SendSuggestions::Params> params(
SendSuggestions::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
content::NotificationService::current()->Notify(
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()));
return true;
return RespondNow(NoArguments());
}
bool OmniboxSetDefaultSuggestionFunction::RunSync() {
ExtensionFunction::ResponseAction OmniboxSetDefaultSuggestionFunction::Run() {
std::unique_ptr<SetDefaultSuggestion::Params> params(
SetDefaultSuggestion::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
if (SetOmniboxDefaultSuggestion(
GetProfile(), extension_id(), params->suggestion)) {
Profile* profile = Profile::FromBrowserContext(browser_context());
if (SetOmniboxDefaultSuggestion(profile, extension_id(),
params->suggestion)) {
content::NotificationService::current()->Notify(
extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED,
content::Source<Profile>(GetProfile()->GetOriginalProfile()),
content::Source<Profile>(profile->GetOriginalProfile()),
content::NotificationService::NoDetails());
}
return true;
return RespondNow(NoArguments());
}
// This function converts style information populated by the JSON schema
......
......@@ -73,7 +73,7 @@ class ExtensionOmniboxEventRouter {
DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter);
};
class OmniboxSendSuggestionsFunction : public ChromeSyncExtensionFunction {
class OmniboxSendSuggestionsFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("omnibox.sendSuggestions", OMNIBOX_SENDSUGGESTIONS)
......@@ -81,7 +81,7 @@ class OmniboxSendSuggestionsFunction : public ChromeSyncExtensionFunction {
~OmniboxSendSuggestionsFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
class OmniboxAPI : public BrowserContextKeyedAPI,
......@@ -150,7 +150,7 @@ class OmniboxAPI : public BrowserContextKeyedAPI,
template <>
void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies();
class OmniboxSetDefaultSuggestionFunction : public ChromeSyncExtensionFunction {
class OmniboxSetDefaultSuggestionFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("omnibox.setDefaultSuggestion",
OMNIBOX_SETDEFAULTSUGGESTION)
......@@ -159,7 +159,7 @@ class OmniboxSetDefaultSuggestionFunction : public ChromeSyncExtensionFunction {
~OmniboxSetDefaultSuggestionFunction() override {}
// ExtensionFunction:
bool RunSync() override;
ResponseAction Run() override;
};
// 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