Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: remoting/ios/facade/ios_client_runtime_delegate.mm

Issue 2949713002: [CRD iOS] Refactor an interface for RemotingAuthorization (Closed)
Patch Set: Resolve feedback Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if !defined(__has_feature) || !__has_feature(objc_arc) 5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support." 6 #error "This file requires ARC support."
7 #endif 7 #endif
8 8
9 #include "remoting/ios/facade/ios_client_runtime_delegate.h" 9 #include "remoting/ios/facade/ios_client_runtime_delegate.h"
10 10
11 #import "base/mac/bind_objc_block.h" 11 #import "base/mac/bind_objc_block.h"
12 #import "remoting/ios/facade/remoting_authentication.h" 12 #import "remoting/ios/facade/remoting_authentication.h"
13 #import "remoting/ios/facade/remoting_service.h" 13 #import "remoting/ios/facade/remoting_service.h"
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/strings/sys_string_conversions.h"
20 21
21 namespace remoting { 22 namespace remoting {
22 23
23 IosClientRuntimeDelegate::IosClientRuntimeDelegate() : weak_factory_(this) { 24 IosClientRuntimeDelegate::IosClientRuntimeDelegate() : weak_factory_(this) {
24 runtime_ = ChromotingClientRuntime::GetInstance(); 25 runtime_ = ChromotingClientRuntime::GetInstance();
25 } 26 }
26 27
27 IosClientRuntimeDelegate::~IosClientRuntimeDelegate() {} 28 IosClientRuntimeDelegate::~IosClientRuntimeDelegate() {}
28 29
29 void IosClientRuntimeDelegate::RuntimeWillShutdown() { 30 void IosClientRuntimeDelegate::RuntimeWillShutdown() {
30 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 31 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
31 // Nothing to do. 32 // Nothing to do.
32 } 33 }
33 34
34 void IosClientRuntimeDelegate::RuntimeDidShutdown() { 35 void IosClientRuntimeDelegate::RuntimeDidShutdown() {
35 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 36 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
36 // Nothing to do. 37 // Nothing to do.
37 } 38 }
38 39
39 void IosClientRuntimeDelegate::RequestAuthTokenForLogger() { 40 void IosClientRuntimeDelegate::RequestAuthTokenForLogger() {
40 if (!runtime_->ui_task_runner()->BelongsToCurrentThread()) { 41 if (!runtime_->ui_task_runner()->BelongsToCurrentThread()) {
41 runtime_->ui_task_runner()->PostTask( 42 runtime_->ui_task_runner()->PostTask(
42 FROM_HERE, 43 FROM_HERE,
43 base::Bind(&IosClientRuntimeDelegate::RequestAuthTokenForLogger, 44 base::Bind(&IosClientRuntimeDelegate::RequestAuthTokenForLogger,
44 base::Unretained(this))); 45 base::Unretained(this)));
45 return; 46 return;
46 } 47 }
47 if ([[RemotingService SharedInstance].authentication.user isAuthenticated]) { 48 if ([RemotingService.instance.authentication.user isAuthenticated]) {
48 [[RemotingService SharedInstance].authentication 49 [RemotingService.instance.authentication
49 callbackWithAccessToken:base::BindBlockArc(^( 50 callbackWithAccessToken:^(RemotingAuthenticationStatus status,
50 remoting::OAuthTokenGetter::Status status, 51 NSString* userEmail, NSString* accessToken) {
51 const std::string& user_email, 52 if (status == RemotingAuthenticationStatusSuccess) {
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. 53 // Set the new auth token for the log writer on the network thread.
54 std::string access_token = base::SysNSStringToUTF8(accessToken);
55 runtime_->network_task_runner()->PostTask( 55 runtime_->network_task_runner()->PostTask(
56 FROM_HERE, base::BindBlockArc(^{ 56 FROM_HERE, base::BindBlockArc(^{
57 runtime_->log_writer()->SetAuthToken(access_token); 57 runtime_->log_writer()->SetAuthToken(access_token);
58 })); 58 }));
59 } else { 59 } else {
60 LOG(ERROR) << "Failed to fetch access token for log writer. (" 60 LOG(ERROR) << "Failed to fetch access token for log writer. ("
61 << status << ")"; 61 << status << ")";
62 } 62 }
63 })]; 63 }];
64 } 64 }
65 } 65 }
66 66
67 base::WeakPtr<IosClientRuntimeDelegate> IosClientRuntimeDelegate::GetWeakPtr() { 67 base::WeakPtr<IosClientRuntimeDelegate> IosClientRuntimeDelegate::GetWeakPtr() {
68 return weak_factory_.GetWeakPtr(); 68 return weak_factory_.GetWeakPtr();
69 } 69 }
70 70
71 } // namespace remoting 71 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698