Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ios / chrome / browser / xcallback_parameters.mm
blob0d55d38b85334d24c891bbd5daff072a78f7c8fa
1 // Copyright 2012 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.
5 #import "ios/chrome/browser/xcallback_parameters.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/sys_string_conversions.h"
10 namespace {
11 NSString* const kSourceAppIdKey = @"sourceAppId";
12 NSString* const kSourceAppNameKey = @"sourceAppName";
13 NSString* const kSuccessURLKey = @"successURL";
14 NSString* const kCreateNewTabKey = @"createNewTab";
17 @interface XCallbackParameters () {
18   base::scoped_nsobject<NSString> _sourceAppId;
19   base::scoped_nsobject<NSString> _sourceAppName;
20   GURL _successURL;
21   BOOL _createNewTab;
23 @end
25 @implementation XCallbackParameters
27 @synthesize successURL = _successURL;
28 @synthesize createNewTab = _createNewTab;
30 - (instancetype)initWithSourceAppId:(NSString*)sourceAppId
31                       sourceAppName:(NSString*)sourceAppName
32                          successURL:(const GURL&)successURL
33                        createNewTab:(BOOL)createNewTab {
34   self = [super init];
35   if (self) {
36     _sourceAppId.reset([sourceAppId copy]);
37     _sourceAppName.reset([sourceAppName copy]);
38     _successURL = successURL;
39     _createNewTab = createNewTab;
40   }
41   return self;
44 - (NSString*)description {
45   return [NSString stringWithFormat:@"SourceApp: %@ (%@)\nSuccessURL: %s\n",
46                                     _sourceAppName.get(), _sourceAppId.get(),
47                                     _successURL.spec().c_str()];
50 - (NSString*)sourceAppId {
51   return _sourceAppId.get();
54 - (NSString*)sourceAppName {
55   return _sourceAppName.get();
58 #pragma mark - NSCoding Methods
60 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
61   GURL successURL;
62   NSString* successURLStr = [aDecoder decodeObjectForKey:kSuccessURLKey];
63   if (successURLStr)
64     _successURL = GURL(base::SysNSStringToUTF8(successURLStr));
66   return
67       [self initWithSourceAppId:[aDecoder decodeObjectForKey:kSourceAppIdKey]
68                   sourceAppName:[aDecoder decodeObjectForKey:kSourceAppNameKey]
69                      successURL:successURL
70                    createNewTab:[aDecoder decodeBoolForKey:kCreateNewTabKey]];
73 - (void)encodeWithCoder:(NSCoder*)aCoder {
74   [aCoder encodeObject:_sourceAppId forKey:kSourceAppIdKey];
75   [aCoder encodeObject:_sourceAppName forKey:kSourceAppNameKey];
76   if (_successURL.is_valid()) {
77     NSString* successStr = base::SysUTF8ToNSString(_successURL.spec());
78     [aCoder encodeObject:successStr forKey:kSuccessURLKey];
79   }
80   [aCoder encodeBool:_createNewTab forKey:kCreateNewTabKey];
83 #pragma mark - NSCopying Methods
85 - (instancetype)copyWithZone:(NSZone*)zone {
86   XCallbackParameters* copy = [[[self class] allocWithZone:zone] init];
87   copy->_sourceAppId.reset([_sourceAppId copy]);
88   copy->_sourceAppName.reset([_sourceAppName copy]);
89   copy->_successURL = _successURL;
90   copy->_createNewTab = _createNewTab;
91   return copy;
94 @end