Commit 58961713 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Udpate Settings mojom API for UpdateSettings request

Add UpdateSettings API for update settings ui request.

Bug: 819782
Test: Manual Test
Change-Id: Ibd7c303da98f0bc95b53ac08c365cc4276ac605f
Reviewed-on: https://chromium-review.googlesource.com/1016039
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553873}
parent b9776932
...@@ -47,11 +47,18 @@ class AssistantManagerService : public mojom::Assistant { ...@@ -47,11 +47,18 @@ class AssistantManagerService : public mojom::Assistant {
virtual AssistantSettingsManager* GetAssistantSettingsManager() = 0; virtual AssistantSettingsManager* GetAssistantSettingsManager() = 0;
using GetSettingsUiResponseCallback = using GetSettingsUiResponseCallback =
base::RepeatingCallback<void(const std::string&)>; base::OnceCallback<void(const std::string&)>;
// Send request for getting settings ui. // Send request for getting settings ui.
virtual void SendGetSettingsUiRequest( virtual void SendGetSettingsUiRequest(
const std::string& selector, const std::string& selector,
GetSettingsUiResponseCallback callback) = 0; GetSettingsUiResponseCallback callback) = 0;
using UpdateSettingsUiResponseCallback =
base::OnceCallback<void(const std::string&)>;
// Send request for updating settings ui.
virtual void SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) = 0;
}; };
} // namespace assistant } // namespace assistant
......
...@@ -78,7 +78,9 @@ void AssistantManagerServiceImpl::SendGetSettingsUiRequest( ...@@ -78,7 +78,9 @@ void AssistantManagerServiceImpl::SendGetSettingsUiRequest(
std::string serialized_proto = SerializeGetSettingsUiRequest(selector); std::string serialized_proto = SerializeGetSettingsUiRequest(selector);
assistant_manager_internal_->SendGetSettingsUiRequest( assistant_manager_internal_->SendGetSettingsUiRequest(
serialized_proto, std::string(), [ serialized_proto, std::string(), [
callback, weak_ptr = weak_factory_.GetWeakPtr(), repeating_callback =
base::AdaptCallbackForRepeating(std::move(callback)),
weak_ptr = weak_factory_.GetWeakPtr(),
task_runner = main_thread_task_runner_ task_runner = main_thread_task_runner_
](const assistant_client::VoicelessResponse& response) { ](const assistant_client::VoicelessResponse& response) {
// This callback may be called from server multiple times. We should // This callback may be called from server multiple times. We should
...@@ -89,7 +91,31 @@ void AssistantManagerServiceImpl::SendGetSettingsUiRequest( ...@@ -89,7 +91,31 @@ void AssistantManagerServiceImpl::SendGetSettingsUiRequest(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&AssistantManagerServiceImpl::HandleGetSettingsResponse, &AssistantManagerServiceImpl::HandleGetSettingsResponse,
std::move(weak_ptr), callback, settings)); std::move(weak_ptr), repeating_callback, settings));
}
});
}
void AssistantManagerServiceImpl::SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) {
std::string serialized_proto = SerializeUpdateSettingsUiRequest(update);
assistant_manager_internal_->SendUpdateSettingsUiRequest(
serialized_proto, std::string(), [
repeating_callback =
base::AdaptCallbackForRepeating(std::move(callback)),
weak_ptr = weak_factory_.GetWeakPtr(),
task_runner = main_thread_task_runner_
](const assistant_client::VoicelessResponse& response) {
// This callback may be called from server multiple times. We should
// only process non-empty response.
std::string update = UnwrapUpdateSettingsUiResponse(response);
if (!update.empty()) {
task_runner->PostTask(
FROM_HERE,
base::BindOnce(
&AssistantManagerServiceImpl::HandleUpdateSettingsResponse,
std::move(weak_ptr), repeating_callback, update));
} }
}); });
} }
...@@ -231,11 +257,17 @@ std::string AssistantManagerServiceImpl::BuildUserAgent( ...@@ -231,11 +257,17 @@ std::string AssistantManagerServiceImpl::BuildUserAgent(
} }
void AssistantManagerServiceImpl::HandleGetSettingsResponse( void AssistantManagerServiceImpl::HandleGetSettingsResponse(
GetSettingsUiResponseCallback callback, base::RepeatingCallback<void(const std::string&)> callback,
const std::string& settings) { const std::string& settings) {
callback.Run(settings); callback.Run(settings);
} }
void AssistantManagerServiceImpl::HandleUpdateSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback,
const std::string& result) {
callback.Run(result);
}
void AssistantManagerServiceImpl::OnConversationTurnStartedOnMainThread() { void AssistantManagerServiceImpl::OnConversationTurnStartedOnMainThread() {
subscribers_.ForAllPtrs([](auto* ptr) { ptr->OnInteractionStarted(); }); subscribers_.ForAllPtrs([](auto* ptr) { ptr->OnInteractionStarted(); });
} }
......
...@@ -52,6 +52,9 @@ class AssistantManagerServiceImpl ...@@ -52,6 +52,9 @@ class AssistantManagerServiceImpl
void SendGetSettingsUiRequest( void SendGetSettingsUiRequest(
const std::string& selector, const std::string& selector,
GetSettingsUiResponseCallback callback) override; GetSettingsUiResponseCallback callback) override;
void SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) override;
// mojom::Assistant overrides: // mojom::Assistant overrides:
void SendTextQuery(const std::string& query) override; void SendTextQuery(const std::string& query) override;
...@@ -85,8 +88,12 @@ class AssistantManagerServiceImpl ...@@ -85,8 +88,12 @@ class AssistantManagerServiceImpl
assistant_client::AssistantManager* assistant_manager); assistant_client::AssistantManager* assistant_manager);
std::string BuildUserAgent(const std::string& arc_version) const; std::string BuildUserAgent(const std::string& arc_version) const;
void HandleGetSettingsResponse(GetSettingsUiResponseCallback callback, void HandleGetSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback,
const std::string& settings); const std::string& settings);
void HandleUpdateSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback,
const std::string& result);
void OnConversationTurnStartedOnMainThread(); void OnConversationTurnStartedOnMainThread();
void OnConversationTurnFinishedOnMainThread( void OnConversationTurnFinishedOnMainThread(
......
...@@ -24,8 +24,19 @@ void AssistantSettingsManagerImpl::GetSettings(const std::string& selector, ...@@ -24,8 +24,19 @@ void AssistantSettingsManagerImpl::GetSettings(const std::string& selector,
AssistantManagerService::State::RUNNING); AssistantManagerService::State::RUNNING);
// Wraps the callback into a repeating callback since the server side // Wraps the callback into a repeating callback since the server side
// interface requires the callback to be copyable. // interface requires the callback to be copyable.
assistant_manager_service_->SendGetSettingsUiRequest( assistant_manager_service_->SendGetSettingsUiRequest(selector,
selector, base::AdaptCallbackForRepeating(std::move(callback))); std::move(callback));
}
void AssistantSettingsManagerImpl::UpdateSettings(
const std::string& update,
GetSettingsCallback callback) {
DCHECK(assistant_manager_service_->GetState() ==
AssistantManagerService::State::RUNNING);
// Wraps the callback into a repeating callback since the server side
// interface requires the callback to be copyable.
assistant_manager_service_->SendUpdateSettingsUiRequest(update,
std::move(callback));
} }
} // namespace assistant } // namespace assistant
......
...@@ -26,6 +26,8 @@ class AssistantSettingsManagerImpl : public AssistantSettingsManager { ...@@ -26,6 +26,8 @@ class AssistantSettingsManagerImpl : public AssistantSettingsManager {
// mojom::AssistantSettingsManager overrides: // mojom::AssistantSettingsManager overrides:
void GetSettings(const std::string& selector, void GetSettings(const std::string& selector,
GetSettingsCallback callback) override; GetSettingsCallback callback) override;
void UpdateSettings(const std::string& update,
UpdateSettingsCallback callback) override;
// AssistantSettingsManager overrides: // AssistantSettingsManager overrides:
void BindRequest(mojom::AssistantSettingsManagerRequest request) override; void BindRequest(mojom::AssistantSettingsManagerRequest request) override;
......
...@@ -38,6 +38,10 @@ void FakeAssistantManagerServiceImpl::SendGetSettingsUiRequest( ...@@ -38,6 +38,10 @@ void FakeAssistantManagerServiceImpl::SendGetSettingsUiRequest(
const std::string& selector, const std::string& selector,
GetSettingsUiResponseCallback callback) {} GetSettingsUiResponseCallback callback) {}
void FakeAssistantManagerServiceImpl::SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) {}
void FakeAssistantManagerServiceImpl::SendTextQuery(const std::string& query) {} void FakeAssistantManagerServiceImpl::SendTextQuery(const std::string& query) {}
void FakeAssistantManagerServiceImpl::AddAssistantEventSubscriber( void FakeAssistantManagerServiceImpl::AddAssistantEventSubscriber(
......
...@@ -32,6 +32,9 @@ class FakeAssistantManagerServiceImpl : public AssistantManagerService { ...@@ -32,6 +32,9 @@ class FakeAssistantManagerServiceImpl : public AssistantManagerService {
void SendGetSettingsUiRequest( void SendGetSettingsUiRequest(
const std::string& selector, const std::string& selector,
GetSettingsUiResponseCallback callback) override; GetSettingsUiResponseCallback callback) override;
void SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) override;
// mojom::AssistantEvent overrides: // mojom::AssistantEvent overrides:
void SendTextQuery(const std::string& query) override; void SendTextQuery(const std::string& query) override;
......
...@@ -11,4 +11,11 @@ interface AssistantSettingsManager { ...@@ -11,4 +11,11 @@ interface AssistantSettingsManager {
// sub-pages requested. // sub-pages requested.
// Send a request for the settings ui sub-pages indicated by the |selector|. // Send a request for the settings ui sub-pages indicated by the |selector|.
GetSettings(string selector) => (string settings); GetSettings(string selector) => (string settings);
// |update| is a serialized proto of SettingsUiUpdate, indicating what kind
// of updates should be applied to the settings.
// |result| is a serialized proto of SettingsUiUpdateResult, containing the
// result of updates.
// Send a request to update the assistant settings indicated by the |update|.
UpdateSettings(string update) => (string result);
}; };
...@@ -25,6 +25,18 @@ message AboutMeSettingsUi { ...@@ -25,6 +25,18 @@ message AboutMeSettingsUi {
optional string full_name = 7; optional string full_name = 7;
} }
// Only the provided fields will be updated.
message AboutMeSettingsUiUpdate {
optional string name = 1;
optional string name_pronunciation = 2;
optional WeatherUnit weather_unit = 3;
}
message AboutMeSettingsUiUpdateResult {
// Localized message to display to the users regarding email optin status.
optional string email_optin_message = 2;
}
enum WeatherUnit { enum WeatherUnit {
CELSIUS = 0; CELSIUS = 0;
FAHRENHEIT = 1; FAHRENHEIT = 1;
......
...@@ -15,6 +15,14 @@ message SettingsUi { ...@@ -15,6 +15,14 @@ message SettingsUi {
optional AboutMeSettingsUi about_me_settings = 5; optional AboutMeSettingsUi about_me_settings = 5;
} }
message SettingsUiUpdate {
optional AboutMeSettingsUiUpdate about_me_settings_update = 4;
}
message SettingsUiUpdateResult {
optional AboutMeSettingsUiUpdateResult about_me_settings_update_result = 4;
}
// Determines which settings sub-pages should be requested to the server. // Determines which settings sub-pages should be requested to the server.
message SettingsUiSelector { message SettingsUiSelector {
optional bool about_me_settings = 5; optional bool about_me_settings = 5;
......
...@@ -179,15 +179,6 @@ void Service::GetAccessTokenCallback(const base::Optional<std::string>& token, ...@@ -179,15 +179,6 @@ void Service::GetAccessTokenCallback(const base::Optional<std::string>& token,
assistant_manager_service_->SetAccessToken(token.value()); assistant_manager_service_->SetAccessToken(token.value());
} }
if (!assistant_settings_manager_) {
assistant_settings_manager_ =
assistant_manager_service_.get()->GetAssistantSettingsManager();
#if BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
registry_.AddInterface<mojom::AssistantSettingsManager>(base::BindRepeating(
&Service::BindAssistantSettingsManager, base::Unretained(this)));
#endif
}
token_refresh_timer_->Start(FROM_HERE, expiration_time - base::Time::Now(), token_refresh_timer_->Start(FROM_HERE, expiration_time - base::Time::Now(),
this, &Service::RequestAccessToken); this, &Service::RequestAccessToken);
} }
...@@ -209,6 +200,11 @@ void Service::FinalizeAssistantManangerService() { ...@@ -209,6 +200,11 @@ void Service::FinalizeAssistantManangerService() {
&Service::BindAssistantConnection, base::Unretained(this))); &Service::BindAssistantConnection, base::Unretained(this)));
client_->OnAssistantStatusChanged(true); client_->OnAssistantStatusChanged(true);
DVLOG(1) << "Assistant is running"; DVLOG(1) << "Assistant is running";
assistant_settings_manager_ =
assistant_manager_service_.get()->GetAssistantSettingsManager();
registry_.AddInterface<mojom::AssistantSettingsManager>(base::BindRepeating(
&Service::BindAssistantSettingsManager, base::Unretained(this)));
} }
void Service::AddAshSessionObserver() { void Service::AddAshSessionObserver() {
......
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