| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 6 #error "This file requires ARC support." | |
| 7 #endif | |
| 8 | |
| 9 #include "remoting/client/ios/facade/ios_client_runtime_delegate.h" | |
| 10 | |
| 11 #import "base/mac/bind_objc_block.h" | |
| 12 #import "remoting/client/ios/facade/remoting_authentication.h" | |
| 13 #import "remoting/client/ios/facade/remoting_service.h" | |
| 14 | |
| 15 #include "base/bind.h" | |
| 16 #include "base/logging.h" | |
| 17 #include "base/macros.h" | |
| 18 #include "base/memory/ptr_util.h" | |
| 19 #include "base/memory/weak_ptr.h" | |
| 20 | |
| 21 namespace remoting { | |
| 22 | |
| 23 IosClientRuntimeDelegate::IosClientRuntimeDelegate() : weak_factory_(this) { | |
| 24 runtime_ = ChromotingClientRuntime::GetInstance(); | |
| 25 } | |
| 26 | |
| 27 IosClientRuntimeDelegate::~IosClientRuntimeDelegate() {} | |
| 28 | |
| 29 void IosClientRuntimeDelegate::RuntimeWillShutdown() { | |
| 30 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); | |
| 31 // Nothing to do. | |
| 32 } | |
| 33 | |
| 34 void IosClientRuntimeDelegate::RuntimeDidShutdown() { | |
| 35 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); | |
| 36 // Nothing to do. | |
| 37 } | |
| 38 | |
| 39 void IosClientRuntimeDelegate::RequestAuthTokenForLogger() { | |
| 40 if (!runtime_->ui_task_runner()->BelongsToCurrentThread()) { | |
| 41 runtime_->ui_task_runner()->PostTask( | |
| 42 FROM_HERE, | |
| 43 base::Bind(&IosClientRuntimeDelegate::RequestAuthTokenForLogger, | |
| 44 base::Unretained(this))); | |
| 45 return; | |
| 46 } | |
| 47 if ([[RemotingService SharedInstance].authentication.user isAuthenticated]) { | |
| 48 [[RemotingService SharedInstance].authentication | |
| 49 callbackWithAccessToken:base::BindBlockArc(^( | |
| 50 remoting::OAuthTokenGetter::Status status, | |
| 51 const std::string& user_email, | |
| 52 const std::string& access_token) { | |
| 53 if (status == remoting::OAuthTokenGetter::Status::SUCCESS) { | |
| 54 // Set the new auth token for the log writer on the network thread. | |
| 55 runtime_->network_task_runner()->PostTask( | |
| 56 FROM_HERE, base::BindBlockArc(^{ | |
| 57 runtime_->log_writer()->SetAuthToken(access_token); | |
| 58 })); | |
| 59 } else { | |
| 60 LOG(ERROR) << "Failed to fetch access token for log writer. (" | |
| 61 << status << ")"; | |
| 62 } | |
| 63 })]; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 base::WeakPtr<IosClientRuntimeDelegate> IosClientRuntimeDelegate::GetWeakPtr() { | |
| 68 return weak_factory_.GetWeakPtr(); | |
| 69 } | |
| 70 | |
| 71 } // namespace remoting | |
| OLD | NEW |