Commit 7adb12c2 authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[Autofill Assistant] Introduce ClientMemory, expose it to actions.

This change extends the controller to include a ClientMemory struct,
that is data shared between all actions.

Bug: 806868
Change-Id: I32e43c2302b93cb6f8a6972789843b08df5d0750
Reviewed-on: https://chromium-review.googlesource.com/1186881Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585919}
parent c492203d
......@@ -43,6 +43,7 @@ jumbo_static_library("browser") {
"assistant_ui_delegate.h",
"assistant_web_controller.cc",
"assistant_web_controller.h",
"client_memory.h",
]
deps = [
......
......@@ -11,6 +11,8 @@
#include "base/callback_forward.h"
namespace autofill_assistant {
struct ClientMemory;
// Assistant action delegate called when processing assistant actions.
class AssistantActionDelegate {
public:
......@@ -51,6 +53,9 @@ class AssistantActionDelegate {
const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) = 0;
// Return the current ClientMemory.
virtual ClientMemory* GetClientMemory() = 0;
protected:
AssistantActionDelegate() = default;
};
......
......@@ -28,6 +28,10 @@ AssistantWebController* AssistantController::GetAssistantWebController() {
return assistant_web_controller_.get();
}
ClientMemory* AssistantController::GetClientMemory() {
return &memory_;
}
AssistantController::AssistantController(
content::WebContents* web_contents,
std::unique_ptr<AssistantUiController> ui_controller)
......@@ -89,4 +93,4 @@ void AssistantController::WebContentsDestroyed() {
OnDestroy();
}
} // namespace autofill_assistant
\ No newline at end of file
} // namespace autofill_assistant
......@@ -11,6 +11,7 @@
#include "components/autofill_assistant/browser/assistant_ui_controller.h"
#include "components/autofill_assistant/browser/assistant_ui_delegate.h"
#include "components/autofill_assistant/browser/assistant_web_controller.h"
#include "components/autofill_assistant/browser/client_memory.h"
#include "content/public/browser/web_contents_observer.h"
namespace content {
......@@ -34,6 +35,7 @@ class AssistantController : public AssistantScriptExecutorDelegate,
AssistantService* GetAssistantService() override;
AssistantUiController* GetAssistantUiController() override;
AssistantWebController* GetAssistantWebController() override;
ClientMemory* GetClientMemory() override;
private:
AssistantController(content::WebContents* web_contents,
......@@ -57,10 +59,11 @@ class AssistantController : public AssistantScriptExecutorDelegate,
std::unique_ptr<AssistantService> assistant_service_;
std::map<AssistantScript*, std::unique_ptr<AssistantScript>>
assistant_scripts_;
ClientMemory memory_;
DISALLOW_COPY_AND_ASSIGN(AssistantController);
};
} // namespace autofill_assistant
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ASSISTANT_CONTROLLER_H_
\ No newline at end of file
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_ASSISTANT_CONTROLLER_H_
......@@ -79,6 +79,10 @@ void AssistantScriptExecutor::FillCardForm(
std::move(callback));
}
ClientMemory* AssistantScriptExecutor::GetClientMemory() {
return delegate_->GetClientMemory();
}
void AssistantScriptExecutor::OnGetAssistantActions(
bool result,
const std::string& response) {
......
......@@ -47,6 +47,7 @@ class AssistantScriptExecutor : public AssistantActionDelegate {
void FillCardForm(const std::string& guid,
const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override;
ClientMemory* GetClientMemory() override;
private:
void OnGetAssistantActions(bool result, const std::string& response);
......
......@@ -10,6 +10,7 @@ namespace autofill_assistant {
class AssistantService;
class AssistantUiController;
class AssistantWebController;
struct ClientMemory;
class AssistantScriptExecutorDelegate {
public:
......@@ -19,6 +20,8 @@ class AssistantScriptExecutorDelegate {
virtual AssistantWebController* GetAssistantWebController() = 0;
virtual ClientMemory* GetClientMemory() = 0;
protected:
virtual ~AssistantScriptExecutorDelegate() {}
};
......
......@@ -6,6 +6,7 @@
#include "base/test/mock_callback.h"
#include "components/autofill_assistant/browser/assistant_service.h"
#include "components/autofill_assistant/browser/client_memory.h"
#include "components/autofill_assistant/browser/mock_assistant_service.h"
#include "components/autofill_assistant/browser/mock_assistant_ui_controller.h"
#include "components/autofill_assistant/browser/mock_assistant_web_controller.h"
......@@ -53,6 +54,8 @@ class AssistantScriptExecutorTest : public testing::Test,
return &mock_assistant_web_controller_;
}
ClientMemory* GetClientMemory() override { return &memory_; }
std::string Serialize(const google::protobuf::MessageLite& message) {
std::string output;
message.SerializeToString(&output);
......@@ -60,6 +63,7 @@ class AssistantScriptExecutorTest : public testing::Test,
}
AssistantScript script_;
ClientMemory memory_;
StrictMock<MockAssistantService> mock_assistant_service_;
NiceMock<MockAssistantWebController> mock_assistant_web_controller_;
NiceMock<MockAssistantUiController> mock_assistant_ui_controller_;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_CLIENT_MEMORY_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_CLIENT_MEMORY_H_
#include <string>
namespace autofill_assistant {
// Data shared between scripts and actions.
struct ClientMemory {
// GUID of the currently selected credit card or empty.
std::string selected_credit_card;
};
} // namespace autofill_assistant
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_CLIENT_MEMORY_H_
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