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

Side by Side Diff: remoting/client/ios/facade/remoting_service.mm

Issue 2681173002: Adding domain and facade supporting classes for remoting iOS app. (Closed)
Patch Set: Renaming domain objects based on feedback. Created 3 years, 10 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
« no previous file with comments | « remoting/client/ios/facade/remoting_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #import <Foundation/Foundation.h>
10
11 #import "remoting/client/ios/facade/remoting_service.h"
12
13 #include "base/logging.h"
14
15 @interface RemotingService ()
16
17 @property(nonatomic, copy) NSString* authorizationCode;
18
19 @end
20
21 //
22 // RemodingService will act as the facade to the C++ layer that has not been
23 // implemented/integrated yet.
24 // TODO(nicholss): Implement/Integrate this class. At the moment it is being
25 // used to generate fake data to implement the UI of the app.
26 //
27 @implementation RemotingService
28
29 @synthesize authorizationCode = _authorizationCode;
30
31 - (BOOL)isAuthenticated {
32 return self.authorizationCode != nil;
33 }
34
35 - (void)authenticateWithAuthorizationCode:(NSString*)authorizationCode {
36 self.authorizationCode = authorizationCode;
37 }
38
39 - (UserInfo*)getUser {
40 if (![self isAuthenticated]) {
41 return nil;
42 }
43
44 NSMutableString* json = [[NSMutableString alloc] init];
45 [json appendString:@"{"];
46 [json appendString:@"\"userId\":\"AABBCC123\","];
47 [json appendString:@"\"userFullName\":\"John Smith\","];
48 [json appendString:@"\"userEmail\":\"john@example.com\","];
49 [json appendString:@"}"];
50
51 NSMutableData* data = [NSMutableData
52 dataWithData:[[json copy] dataUsingEncoding:NSUTF8StringEncoding]];
53
54 UserInfo* user = [UserInfo parseListFromJSON:data];
55 return user;
56 }
57
58 - (NSArray<HostInfo*>*)getHosts {
59 if (![self isAuthenticated]) {
60 return nil;
61 }
62
63 NSMutableString* json = [[NSMutableString alloc] init];
64 [json
65 appendString:@"{\"data\":{\"kind\":\"chromoting#hostList\",\"items\":["];
66 [json appendString:@"{"];
67 [json appendString:@"\"createdTime\":\"2000-01-01T00:00:01.000Z\","];
68 [json appendString:@"\"hostId\":\"Host1\","];
69 [json appendString:@"\"hostName\":\"HostName1\","];
70 [json appendString:@"\"hostVersion\":\"2.22.5.4\","];
71 [json appendString:@"\"kind\":\"Chromoting#host\","];
72 [json appendString:@"\"jabberId\":\"JabberingOn\","];
73 [json appendString:@"\"publicKey\":\"AAAAABBBBBZZZZZ\","];
74 [json appendString:@"\"status\":\"TESTING\","];
75 [json appendString:@"\"updatedTime\":\"2000-01-01T00:00:01.000Z\""];
76 [json appendString:@"},"];
77 [json appendString:@"{"];
78 [json appendString:@"\"createdTime\":\"2000-01-01T00:00:01.000Z\","];
79 [json appendString:@"\"hostId\":\"Host2\","];
80 [json appendString:@"\"hostName\":\"HostName2\","];
81 [json appendString:@"\"hostVersion\":\"2.22.5.4\","];
82 [json appendString:@"\"kind\":\"Chromoting#host\","];
83 [json appendString:@"\"jabberId\":\"JabberingOn\","];
84 [json appendString:@"\"publicKey\":\"AAAAABBBBBZZZZZ\","];
85 [json appendString:@"\"status\":\"ONLINE\","];
86 [json appendString:@"\"updatedTime\":\"2000-01-01T00:00:01.000Z\""];
87 [json appendString:@"}"];
88 [json appendString:@"]}}"];
89
90 NSMutableData* data = [NSMutableData
91 dataWithData:[[json copy] dataUsingEncoding:NSUTF8StringEncoding]];
92
93 NSMutableArray<HostInfo*>* hosts = [HostInfo parseListFromJSON:data];
94 return hosts;
95 }
96
97 // RemotingService is a singleton.
98 + (RemotingService*)sharedInstance {
99 static RemotingService* sharedInstance = nil;
100 static dispatch_once_t guard;
101 dispatch_once(&guard, ^{
102 sharedInstance = [[RemotingService alloc] init];
103 });
104 return sharedInstance;
105 }
106
107 @end
OLDNEW
« no previous file with comments | « remoting/client/ios/facade/remoting_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698