Commit b4cf3a54 authored by shaktisahu's avatar shaktisahu Committed by Commit bot

Added features to BlimpClientContext and BlimpContents

This CL instantiates ImeFeature and NavigationFeature inside
BlimpClientContext. BlimpClientContext owns these features and passes
raw pointers to BlimpContents during construction.

BUG=611111

Review-Url: https://codereview.chromium.org/2258563003
Cr-Commit-Position: refs/heads/master@{#414786}
parent 8afa2d49
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "blimp/client/core/contents/blimp_contents_impl.h" #include "blimp/client/core/contents/blimp_contents_impl.h"
#include "blimp/client/core/contents/blimp_contents_manager.h" #include "blimp/client/core/contents/blimp_contents_manager.h"
#include "blimp/client/core/contents/ime_feature.h"
#include "blimp/client/core/contents/navigation_feature.h"
#include "blimp/client/core/contents/tab_control_feature.h" #include "blimp/client/core/contents/tab_control_feature.h"
#include "blimp/client/core/session/cross_thread_network_event_observer.h" #include "blimp/client/core/session/cross_thread_network_event_observer.h"
#include "blimp/client/public/blimp_client_context_delegate.h" #include "blimp/client/public/blimp_client_context_delegate.h"
...@@ -49,9 +51,13 @@ BlimpClientContextImpl::BlimpClientContextImpl( ...@@ -49,9 +51,13 @@ BlimpClientContextImpl::BlimpClientContextImpl(
: BlimpClientContext(), : BlimpClientContext(),
io_thread_task_runner_(io_thread_task_runner), io_thread_task_runner_(io_thread_task_runner),
file_thread_task_runner_(file_thread_task_runner), file_thread_task_runner_(file_thread_task_runner),
ime_feature_(new ImeFeature),
navigation_feature_(new NavigationFeature),
tab_control_feature_(new TabControlFeature), tab_control_feature_(new TabControlFeature),
blimp_contents_manager_(new BlimpContentsManager( blimp_contents_manager_(
tab_control_feature_.get())), new BlimpContentsManager(ime_feature_.get(),
navigation_feature_.get(),
tab_control_feature_.get())),
weak_factory_(this) { weak_factory_(this) {
net_components_.reset(new ClientNetworkComponents( net_components_.reset(new ClientNetworkComponents(
base::MakeUnique<CrossThreadNetworkEventObserver>( base::MakeUnique<CrossThreadNetworkEventObserver>(
...@@ -148,6 +154,12 @@ void BlimpClientContextImpl::ConnectWithAssignment( ...@@ -148,6 +154,12 @@ void BlimpClientContextImpl::ConnectWithAssignment(
void BlimpClientContextImpl::RegisterFeatures() { void BlimpClientContextImpl::RegisterFeatures() {
// Register features' message senders and receivers. // Register features' message senders and receivers.
ime_feature_->set_outgoing_message_processor(
thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme,
ime_feature_.get()));
navigation_feature_->set_outgoing_message_processor(
thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation,
navigation_feature_.get()));
tab_control_feature_->set_outgoing_message_processor( tab_control_feature_->set_outgoing_message_processor(
thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl,
tab_control_feature_.get())); tab_control_feature_.get()));
......
...@@ -25,6 +25,8 @@ namespace blimp { ...@@ -25,6 +25,8 @@ namespace blimp {
namespace client { namespace client {
class BlimpContentsManager; class BlimpContentsManager;
class ImeFeature;
class NavigationFeature;
class TabControlFeature; class TabControlFeature;
// BlimpClientContextImpl is the implementation of the main context-class for // BlimpClientContextImpl is the implementation of the main context-class for
...@@ -81,6 +83,9 @@ class BlimpClientContextImpl : public BlimpClientContext, ...@@ -81,6 +83,9 @@ class BlimpClientContextImpl : public BlimpClientContext,
// Connect() to get a valid assignment and later connect to the engine. // Connect() to get a valid assignment and later connect to the engine.
std::unique_ptr<AssignmentSource> assignment_source_; std::unique_ptr<AssignmentSource> assignment_source_;
// Features to handle all incoming and outgoing protobuf messages.
std::unique_ptr<ImeFeature> ime_feature_;
std::unique_ptr<NavigationFeature> navigation_feature_;
std::unique_ptr<TabControlFeature> tab_control_feature_; std::unique_ptr<TabControlFeature> tab_control_feature_;
std::unique_ptr<BlimpContentsManager> blimp_contents_manager_; std::unique_ptr<BlimpContentsManager> blimp_contents_manager_;
......
...@@ -24,8 +24,10 @@ const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android"; ...@@ -24,8 +24,10 @@ const char kBlimpContentsImplAndroidKey[] = "blimp_contents_impl_android";
} }
BlimpContentsImpl::BlimpContentsImpl(int id, BlimpContentsImpl::BlimpContentsImpl(int id,
ImeFeature* ime_feature,
NavigationFeature* navigation_feature,
TabControlFeature* tab_control_feature) TabControlFeature* tab_control_feature)
: navigation_controller_(this, nullptr), : navigation_controller_(this, navigation_feature),
id_(id), id_(id),
tab_control_feature_(tab_control_feature) {} tab_control_feature_(tab_control_feature) {}
......
...@@ -26,12 +26,18 @@ class BlimpContentsImplAndroid; ...@@ -26,12 +26,18 @@ class BlimpContentsImplAndroid;
class BlimpContentsObserver; class BlimpContentsObserver;
class BlimpNavigationController; class BlimpNavigationController;
class ImeFeature;
class NavigationFeature;
class TabControlFeature; class TabControlFeature;
class BlimpContentsImpl : public BlimpContents, class BlimpContentsImpl : public BlimpContents,
public BlimpNavigationControllerDelegate { public BlimpNavigationControllerDelegate {
public: public:
explicit BlimpContentsImpl(int id, TabControlFeature* tab_control_feature); // Ownership of the features remains with the caller.
explicit BlimpContentsImpl(int id,
ImeFeature* ime_feature,
NavigationFeature* navigation_feature,
TabControlFeature* tab_control_feature);
~BlimpContentsImpl() override; ~BlimpContentsImpl() override;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -44,13 +44,11 @@ class MockTabControlFeature : public TabControlFeature { ...@@ -44,13 +44,11 @@ class MockTabControlFeature : public TabControlFeature {
TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) { TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) {
base::MessageLoop loop; base::MessageLoop loop;
BlimpContentsImpl blimp_contents(kDummyTabId, nullptr); FakeNavigationFeature feature;
BlimpContentsImpl blimp_contents(kDummyTabId, nullptr, &feature, nullptr);
BlimpNavigationControllerImpl& navigation_controller = BlimpNavigationControllerImpl& navigation_controller =
blimp_contents.GetNavigationController(); blimp_contents.GetNavigationController();
FakeNavigationFeature feature;
feature.SetDelegate(1, &navigation_controller);
navigation_controller.SetNavigationFeatureForTesting(&feature);
testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents); testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents);
testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents); testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents);
...@@ -79,7 +77,8 @@ TEST(BlimpContentsImplTest, SetSizeAndScaleThroughTabControlFeature) { ...@@ -79,7 +77,8 @@ TEST(BlimpContentsImplTest, SetSizeAndScaleThroughTabControlFeature) {
MockTabControlFeature tab_control_feature; MockTabControlFeature tab_control_feature;
base::MessageLoop loop; base::MessageLoop loop;
BlimpContentsImpl blimp_contents(kDummyTabId, &tab_control_feature); BlimpContentsImpl blimp_contents(kDummyTabId, nullptr, nullptr,
&tab_control_feature);
EXPECT_CALL(tab_control_feature, EXPECT_CALL(tab_control_feature,
SetSizeAndScale(gfx::Size(width, height), dp_to_px)).Times(1); SetSizeAndScale(gfx::Size(width, height), dp_to_px)).Times(1);
......
...@@ -45,8 +45,12 @@ void BlimpContentsManager::BlimpContentsDeletionObserver:: ...@@ -45,8 +45,12 @@ void BlimpContentsManager::BlimpContentsDeletionObserver::
} }
BlimpContentsManager::BlimpContentsManager( BlimpContentsManager::BlimpContentsManager(
ImeFeature* ime_feature,
NavigationFeature* nav_feature,
TabControlFeature* tab_control_feature) TabControlFeature* tab_control_feature)
: tab_control_feature_(tab_control_feature), : ime_feature_(ime_feature),
navigation_feature_(nav_feature),
tab_control_feature_(tab_control_feature),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
BlimpContentsManager::~BlimpContentsManager() {} BlimpContentsManager::~BlimpContentsManager() {}
...@@ -55,7 +59,8 @@ std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents() { ...@@ -55,7 +59,8 @@ std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents() {
int id = CreateBlimpContentsId(); int id = CreateBlimpContentsId();
std::unique_ptr<BlimpContentsImpl> new_contents = std::unique_ptr<BlimpContentsImpl> new_contents =
base::MakeUnique<BlimpContentsImpl>(id, tab_control_feature_); base::MakeUnique<BlimpContentsImpl>(id, ime_feature_, navigation_feature_,
tab_control_feature_);
// Create an observer entry for the contents. // Create an observer entry for the contents.
std::unique_ptr<BlimpContentsDeletionObserver> observer = std::unique_ptr<BlimpContentsDeletionObserver> observer =
......
...@@ -17,7 +17,9 @@ class TabControlFeature; ...@@ -17,7 +17,9 @@ class TabControlFeature;
// monitor the life time of the contents it creates. // monitor the life time of the contents it creates.
class BlimpContentsManager { class BlimpContentsManager {
public: public:
explicit BlimpContentsManager(TabControlFeature* tab_control_feature); explicit BlimpContentsManager(ImeFeature* ime_feature,
NavigationFeature* nav_feature,
TabControlFeature* tab_control_feature);
~BlimpContentsManager(); ~BlimpContentsManager();
// Builds a BlimpContentsImpl and notifies the engine. // Builds a BlimpContentsImpl and notifies the engine.
...@@ -49,7 +51,9 @@ class BlimpContentsManager { ...@@ -49,7 +51,9 @@ class BlimpContentsManager {
// lifetime of the observers. // lifetime of the observers.
std::map<int, std::unique_ptr<BlimpContentsDeletionObserver>> observer_map_; std::map<int, std::unique_ptr<BlimpContentsDeletionObserver>> observer_map_;
TabControlFeature* tab_control_feature_ = nullptr; ImeFeature* ime_feature_;
NavigationFeature* navigation_feature_;
TabControlFeature* tab_control_feature_;
base::WeakPtrFactory<BlimpContentsManager> weak_ptr_factory_; base::WeakPtrFactory<BlimpContentsManager> weak_ptr_factory_;
......
...@@ -37,7 +37,8 @@ TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { ...@@ -37,7 +37,8 @@ TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) {
base::MessageLoop loop; base::MessageLoop loop;
MockTabControlFeature tab_control_feature; MockTabControlFeature tab_control_feature;
BlimpContentsManager blimp_contents_manager(&tab_control_feature); BlimpContentsManager blimp_contents_manager(nullptr, nullptr,
&tab_control_feature);
EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
std::unique_ptr<BlimpContentsImpl> blimp_contents = std::unique_ptr<BlimpContentsImpl> blimp_contents =
...@@ -51,7 +52,8 @@ TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { ...@@ -51,7 +52,8 @@ TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) {
TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) {
MockTabControlFeature tab_control_feature; MockTabControlFeature tab_control_feature;
BlimpContentsManager blimp_contents_manager(&tab_control_feature); BlimpContentsManager blimp_contents_manager(nullptr, nullptr,
&tab_control_feature);
BlimpContentsImpl* existing_contents = BlimpContentsImpl* existing_contents =
blimp_contents_manager.GetBlimpContents(kDummyTabId); blimp_contents_manager.GetBlimpContents(kDummyTabId);
...@@ -61,7 +63,8 @@ TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { ...@@ -61,7 +63,8 @@ TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) {
TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) {
base::MessageLoop loop; base::MessageLoop loop;
MockTabControlFeature tab_control_feature; MockTabControlFeature tab_control_feature;
BlimpContentsManager blimp_contents_manager(&tab_control_feature); BlimpContentsManager blimp_contents_manager(nullptr, nullptr,
&tab_control_feature);
int id; int id;
EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1);
......
...@@ -30,7 +30,7 @@ class BlimpContentsObserverTest : public BlimpContentsObserver { ...@@ -30,7 +30,7 @@ class BlimpContentsObserverTest : public BlimpContentsObserver {
}; };
TEST(BlimpContentsObserverUnittests, ObserverDies) { TEST(BlimpContentsObserverUnittests, ObserverDies) {
BlimpContentsImpl contents(kDummyTabId, nullptr); BlimpContentsImpl contents(kDummyTabId, nullptr, nullptr, nullptr);
std::unique_ptr<BlimpContentsObserver> observer = std::unique_ptr<BlimpContentsObserver> observer =
base::MakeUnique<BlimpContentsObserverTest>(&contents); base::MakeUnique<BlimpContentsObserverTest>(&contents);
...@@ -45,7 +45,8 @@ TEST(BlimpContentsObserverUnittests, ContentsDies) { ...@@ -45,7 +45,8 @@ TEST(BlimpContentsObserverUnittests, ContentsDies) {
std::unique_ptr<BlimpContentsObserverTest> observer; std::unique_ptr<BlimpContentsObserverTest> observer;
std::unique_ptr<BlimpContentsImpl> contents = std::unique_ptr<BlimpContentsImpl> contents =
base::MakeUnique<BlimpContentsImpl>(kDummyTabId, nullptr); base::MakeUnique<BlimpContentsImpl>(kDummyTabId, nullptr, nullptr,
nullptr);
observer.reset(new BlimpContentsObserverTest(contents.get())); observer.reset(new BlimpContentsObserverTest(contents.get()));
EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1);
EXPECT_EQ(observer->blimp_contents(), contents.get()); EXPECT_EQ(observer->blimp_contents(), contents.get());
......
...@@ -25,12 +25,6 @@ BlimpNavigationControllerImpl::BlimpNavigationControllerImpl( ...@@ -25,12 +25,6 @@ BlimpNavigationControllerImpl::BlimpNavigationControllerImpl(
BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default; BlimpNavigationControllerImpl::~BlimpNavigationControllerImpl() = default;
void BlimpNavigationControllerImpl::SetNavigationFeatureForTesting(
NavigationFeature* feature) {
navigation_feature_ = feature;
navigation_feature_->SetDelegate(kDummyTabId, this);
}
void BlimpNavigationControllerImpl::LoadURL(const GURL& url) { void BlimpNavigationControllerImpl::LoadURL(const GURL& url) {
current_url_ = url; current_url_ = url;
navigation_feature_->NavigateToUrlText(kDummyTabId, current_url_.spec()); navigation_feature_->NavigateToUrlText(kDummyTabId, current_url_.spec());
......
...@@ -27,9 +27,6 @@ class BlimpNavigationControllerImpl ...@@ -27,9 +27,6 @@ class BlimpNavigationControllerImpl
NavigationFeature* feature); NavigationFeature* feature);
~BlimpNavigationControllerImpl() override; ~BlimpNavigationControllerImpl() override;
// For testing only.
void SetNavigationFeatureForTesting(NavigationFeature* feature);
// BlimpNavigationController implementation. // BlimpNavigationController implementation.
void LoadURL(const GURL& url) override; void LoadURL(const GURL& url) override;
void Reload() override; void Reload() override;
......
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