Commit 4e433f99 authored by nicholss's avatar nicholss Committed by Commit bot

Adding session object for iOS to integerate client sessions.

Not finished implementing yet, but this will be the iOS version of remoting
client that ties the remoting/client common session to iOS.

BUG=652781

Review-Url: https://codereview.chromium.org/2805963002
Cr-Commit-Position: refs/heads/master@{#463337}
parent 5f60fb4d
......@@ -5,27 +5,32 @@
#ifndef REMOTING_CLIENT_IOS_DISPLAY_GL_DISPLAY_HANDLER_H_
#define REMOTING_CLIENT_IOS_DISPLAY_GL_DISPLAY_HANDLER_H_
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
#import "remoting/client/display/sys_opengl.h"
#include "remoting/client/client_context.h"
#include "remoting/protocol/cursor_shape_stub.h"
#include "remoting/protocol/frame_consumer.h"
#include "remoting/protocol/video_renderer.h"
namespace remoting {
namespace ios {
class AppRuntime;
class ChromotingClientRuntime;
} // namespace ios
} // namespace remoting
@interface GlDisplayHandler : NSObject {
}
- (id)initWithRuntime:(remoting::ios::AppRuntime*)runtime;
- (id)initWithRuntime:(remoting::ChromotingClientRuntime*)runtime;
- (void)created;
- (void)stop;
- (void)glkView:(GLKView*)view drawInRect:(CGRect)rect;
- (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer;
- (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub;
@end
......
......@@ -6,47 +6,50 @@
#error "This file requires ARC support."
#endif
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
#import "remoting/client/ios/display/gl_display_handler.h"
#import "remoting/client/display/sys_opengl.h"
#import "remoting/client/ios/display/gl_demo_screen.h"
#import "remoting/client/ios/display/gl_display_handler.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "remoting/client/chromoting_client.h"
#include "remoting/client/chromoting_client_runtime.h"
#include "remoting/client/cursor_shape_stub_proxy.h"
#include "remoting/client/display/gl_canvas.h"
#include "remoting/client/display/gl_renderer.h"
#include "remoting/client/display/gl_renderer_delegate.h"
#include "remoting/client/dual_buffer_frame_consumer.h"
#include "remoting/client/ios/app_runtime.h"
#include "remoting/client/software_video_renderer.h"
namespace remoting {
namespace GlDisplayHandler {
// The core that lives on the display thread.
class Core : public GlRendererDelegate {
class Core : public protocol::CursorShapeStub, public GlRendererDelegate {
public:
Core(remoting::ios::AppRuntime* runtime);
Core();
~Core() override;
// CursorShapeStub interface.
void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
// GlRendererDelegate interface.
bool CanRenderFrame() override;
void OnFrameRendered() override;
void OnSizeChanged(int width, int height) override;
void Created();
void Stop();
void SurfaceChanged(int width, int height);
std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer();
base::WeakPtr<Core> GetWeakPtr();
private:
// Will be std::move'd when GrabFrameConsumer() is called.
remoting::ios::AppRuntime* runtime_;
remoting::ChromotingClientRuntime* runtime_;
std::unique_ptr<DualBufferFrameConsumer> owned_frame_consumer_;
base::WeakPtr<DualBufferFrameConsumer> frame_consumer_;
......@@ -61,8 +64,8 @@ class Core : public GlRendererDelegate {
DISALLOW_COPY_AND_ASSIGN(Core);
};
Core::Core(remoting::ios::AppRuntime* runtime)
: runtime_(runtime), weak_factory_(this) {
Core::Core() : weak_factory_(this) {
runtime_ = ChromotingClientRuntime::GetInstance();
weak_ptr_ = weak_factory_.GetWeakPtr();
renderer_.SetDelegate(weak_ptr_);
owned_frame_consumer_.reset(new remoting::DualBufferFrameConsumer(
......@@ -76,6 +79,11 @@ Core::Core(remoting::ios::AppRuntime* runtime)
Core::~Core() {}
void Core::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
renderer_.OnCursorShapeChanged(cursor_shape);
}
bool Core::CanRenderFrame() {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
return eagl_context_ != NULL;
......@@ -99,12 +107,25 @@ void Core::Created() {
DCHECK(!eagl_context_);
eagl_context_ = [EAGLContext currentContext];
if (!eagl_context_) {
eagl_context_ =
[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
[EAGLContext setCurrentContext:eagl_context_];
}
renderer_.RequestCanvasSize();
renderer_.OnSurfaceCreated(base::MakeUnique<GlCanvas>(
static_cast<int>([eagl_context_ API])));
}
void Core::Stop() {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
eagl_context_ = nil;
// demo_screen_
// renderer_ = nil;
}
void Core::SurfaceChanged(int width, int height) {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
renderer_.OnSurfaceChanged(width, height);
......@@ -119,7 +140,7 @@ base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() {
@interface GlDisplayHandler ()
@property(nonatomic) remoting::GlDisplayHandler::Core* core_;
@property(nonatomic) remoting::ios::AppRuntime* runtime_;
@property(nonatomic) remoting::ChromotingClientRuntime* runtime_;
@end
@implementation GlDisplayHandler
......@@ -127,24 +148,35 @@ base::WeakPtr<remoting::GlDisplayHandler::Core> Core::GetWeakPtr() {
@synthesize core_ = _core_;
@synthesize runtime_ = _runtime_;
- (id)initWithRuntime:(remoting::ios::AppRuntime*)runtime {
- (id)initWithRuntime:(remoting::ChromotingClientRuntime*)runtime {
self.runtime_ = runtime;
return self;
}
- (void)created {
_core_ = new remoting::GlDisplayHandler::Core(self.runtime_);
_core_ = new remoting::GlDisplayHandler::Core();
self.runtime_->display_task_runner()->PostTask(
FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Created,
self.core_->GetWeakPtr()));
}
- (void)stop {
self.runtime_->display_task_runner()->PostTask(
FROM_HERE, base::Bind(&remoting::GlDisplayHandler::Core::Stop,
self.core_->GetWeakPtr()));
}
- (std::unique_ptr<remoting::protocol::VideoRenderer>)CreateVideoRenderer {
return base::MakeUnique<remoting::SoftwareVideoRenderer>(
_core_->GrabFrameConsumer());
}
- (std::unique_ptr<remoting::protocol::CursorShapeStub>)CreateCursorShapeStub {
return base::MakeUnique<remoting::CursorShapeStubProxy>(
_core_->GetWeakPtr(), self.runtime_->display_task_runner());
}
// In general, avoid expensive work in this function to maximize frame rate.
- (void)glkView:(GLKView*)view drawInRect:(CGRect)rect {
if (_core_) {
......
# Copyright 2017 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.
import("//build/config/chrome_build.gni")
import("//build/config/ios/rules.gni")
import("//remoting/build/config/remoting_build.gni")
source_set("session") {
sources = [
"remoting_client.h",
"remoting_client.mm",
"remoting_client_session_delegate.h",
"remoting_client_session_delegate.mm",
]
deps = [
"//base",
"//remoting/client",
"//remoting/client/ios/domain",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2017 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 REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_H_
#define REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_H_
@interface RemotingClient : NSObject
- (void)connectToHost:(const remoting::ConnectToHostInfo&)info;
// Mirrors the native client session delegate interface:
- (void)onConnectionState:(protocol::ConnectionToHost::State)state
error:(protocol::ErrorCode)error;
- (void)commitPairingCredentialsForHost:(NSString*)host
id:(NSString*)id
secret:(NSString*)secret;
- (void)fetchThirdPartyTokenForUrl:(NSString*)tokenUrl
clientId:(NSString*)clinetId
scope:(NSString*)scope;
- (void)setCapabilities:(NSString*)capabilities;
- (void)handleExtensionMessageOfType:(NSString*)type message:(NSString*)message;
@end
#endif // REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_H_
// Copyright 2017 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.
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#import "remoting/client/ios/session/client.h"
#import "base/mac/bind_objc_block.h"
#include "remoting/client/chromoting_client_runtime.h"
#include "remoting/client/connect_to_host_info.h"
@interface RemotingClient () {
GlDisplayHandler* _displayHandler;
remoting::ChromotingClientRuntime* _runtime;
std::unique_ptr<remoting::ChromotingSession> _session;
remoting::RemotingClientSessonDelegate* _sessonDelegate;
}
@end
@implementation RemotingClient
- (instancetype)init {
self = [super init];
if (self) {
_runtime = ChromotingClientRuntime::GetInstance();
_sessonDelegate = new remoting::RemotingClientSessonDelegate(self);
}
return self;
}
- (void)connectToHost:(const remoting::ConnectToHostInfo&)info {
_displayHandler = [[GlDisplayHandler alloc] initWithRuntime:_runtime];
protocol::ClientAuthenticationConfig client_auth_config;
client_auth_config.host_id = info.host_id;
client_auth_config.pairing_client_id = info.pairing_id;
client_auth_config.pairing_secret = info.pairing_secret;
client_auth_config.fetch_secret_callback = base::BindBlockArc(
^(bool pairing_supported,
const SecretFetchedCallback& secret_fetched_callback) {
NSLog(@"TODO(nicholss): Implement the FetchSecretCallback.");
});
// TODO(nicholss): Add audio support to iOS.
base::WeakPtr<protocol::AudioStub> audioPlayer = nullptr;
_session.reset(new remoting::ChromotingSession(
_sessonDelegate->GetWeakPtr(), [_displayHandler CreateCursorShapeStub],
[_displayHandler CreateVideoRenderer], audioPlayer, info,
client_auth_config));
_session->Connect();
}
#pragma mark - ChromotingSession::Delegate
- (void)onConnectionState:(protocol::ConnectionToHost::State)state
error:(protocol::ErrorCode)error {
NSLog(@"TODO(nicholss): implement this.");
}
- (void)commitPairingCredentialsForHost:(NSString*)host
id:(NSString*)id
secret:(NSString*)secret {
NSLog(@"TODO(nicholss): implement this.");
}
- (void)fetchThirdPartyTokenForUrl:(NSString*)tokenUrl
clientId:(NSString*)clientId
scope:(NSString*)scope {
NSLog(@"TODO(nicholss): implement this.");
}
- (void)setCapabilities:(NSString*)capabilities {
NSLog(@"TODO(nicholss): implement this.");
}
- (void)handleExtensionMessageOfType:(NSString*)type
message:(NSString*)message {
NSLog(@"TODO(nicholss): implement this.");
}
@end
// Copyright 2017 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 REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_SESSION_DELEGATE_H_
#define REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_SESSION_DELEGATE_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "remoting/client/chromoting_session.h"
#include "remoting/protocol/connection_to_host.h"
namespace remoting {
class ChromotingClientRuntime;
class RemotingClientSessonDelegate : public ChromotingSession::Delegate {
public:
RemotingClientSessonDelegate();
~RemotingClientSessonDelegate() override;
// ChromotingSession::Delegate implementation
void OnConnectionState(protocol::ConnectionToHost::State state,
protocol::ErrorCode error) override;
void CommitPairingCredentials(const std::string& host,
const std::string& id,
const std::string& secret) override;
void FetchThirdPartyToken(const std::string& token_url,
const std::string& client_id,
const std::string& scope) override;
void SetCapabilities(const std::string& capabilities) override;
void HandleExtensionMessage(const std::string& type,
const std::string& message) override;
base::WeakPtr<RemotingClientSessonDelegate> GetWeakPtr();
private:
ChromotingClientRuntime* runtime_;
id client_;
base::WeakPtrFactory<RemotingClientSessonDelegate> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(RemotingClientSessonDelegate);
}
} // namespace remoting
#endif // REMOTING_CLIENT_IOS_SESSION_REMOTING_CLIENT_SESSION_DELEGATE_H_
// Copyright 2017 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.
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#import "remoting/client/ios/session/remoting_client_session_delegate.h"
#include "base/strings/sys_string_conversions.h"
#include "remoting/client/chromoting_client_runtime.h"
using base::SysUTF8ToNSString;
namespace remoting {
RemotingClientSessonDelegate::RemotingClientSessonDelegate(
RemotingClient* client)
: client_(client), weak_factory_(this) {
runtime_ = ChromotingClientRuntime::GetInstance();
}
RemotingClientSessonDelegate::~RemotingClientSessonDelegate() {
client_ = nil;
}
void RemotingClientSessonDelegate::OnConnectionState(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
[client_ onConnectionState:state error:error];
}
void RemotingClientSessonDelegate::CommitPairingCredentials(
const std::string& host,
const std::string& id,
const std::string& secret) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
[client_ commitPairingCredentialsForHost:SysUTF8ToNSString(host)
id:SysUTF8ToNSString(id)
secret:SysUTF8ToNSString(secret)];
}
void RemotingClientSessonDelegate::FetchThirdPartyToken(
const std::string& token_url,
const std::string& client_id,
const std::string& scope) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
[client_ fetchThirdPartyTokenForUrl:SysUTF8ToNSString(token_url)
clientId:SysUTF8ToNSString(client_id)
scope:SysUTF8ToNSString(scope)];
}
void RemotingClientSessonDelegate::SetCapabilities(
const std::string& capabilities) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
[client_ setCapabilities:SysUTF8ToNSString(capabilities)];
}
void RemotingClientSessonDelegate::HandleExtensionMessage(
const std::string& type,
const std::string& message) {
DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
[client_ handleExtensionMessageOfType:SysUTF8ToNSString(type)
message:SysUTF8ToNSString(message)];
}
base::WeakPtr<RemotingClientSessonDelegate>
RemotingClientSessonDelegate::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
} // namespace remoting
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