Remove base ios files
Change-Id: Id3e521926bf1d7a26000b9d7bf8dc637f48914f7
Reviewed-on: https://gn-review.googlesource.com/1407
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/critical_closure_internal_ios.mm b/base/critical_closure_internal_ios.mm
deleted file mode 100644
index e35eca0..0000000
--- a/base/critical_closure_internal_ios.mm
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-#include "base/critical_closure.h"
-
-#import <UIKit/UIKit.h>
-
-namespace base {
-namespace internal {
-
-bool IsMultiTaskingSupported() {
- return [[UIDevice currentDevice] isMultitaskingSupported];
-}
-
-CriticalClosure::CriticalClosure(OnceClosure closure)
- : closure_(std::move(closure)) {}
-
-CriticalClosure::~CriticalClosure() {}
-
-void CriticalClosure::Run() {
- std::move(closure_).Run();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/ios/OWNERS b/base/ios/OWNERS
deleted file mode 100644
index bdb59ec..0000000
--- a/base/ios/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-eugenebut@chromium.org
-rohitrao@chromium.org
-sdefresne@chromium.org
diff --git a/base/ios/block_types.h b/base/ios/block_types.h
deleted file mode 100644
index e4dde79..0000000
--- a/base/ios/block_types.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2013 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 BASE_IOS_BLOCK_TYPES_H_
-#define BASE_IOS_BLOCK_TYPES_H_
-
-// A generic procedural block type that takes no arguments and returns nothing.
-typedef void (^ProceduralBlock)(void);
-
-// A block that takes no arguments and returns a bool.
-typedef bool (^ConditionBlock)(void);
-
-#endif // BASE_IOS_BLOCK_TYPES_H_
diff --git a/base/ios/crb_protocol_observers.h b/base/ios/crb_protocol_observers.h
deleted file mode 100644
index 8ff5878..0000000
--- a/base/ios/crb_protocol_observers.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 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 BASE_IOS_CRB_PROTOCOL_OBSERVERS_H_
-#define BASE_IOS_CRB_PROTOCOL_OBSERVERS_H_
-
-#import <Foundation/Foundation.h>
-
-typedef void (^ExecutionWithObserverBlock)(id);
-
-// Implements a container for observers that implement a specific Objective-C
-// protocol. The container forwards method invocations to its contained
-// observers, so that sending a message to all the observers is as simple as
-// sending the message to the container.
-// It is safe for an observer to remove itself or another observer while being
-// notified. It is also safe to add an other observer while being notified but
-// the newly added observer will not be notified as part of the current
-// notification dispatch.
-@interface CRBProtocolObservers : NSObject
-
-// The Objective-C protocol that the observers in this container conform to.
-@property(nonatomic, readonly) Protocol* protocol;
-
-// Returns a CRBProtocolObservers container for observers that conform to
-// |protocol|.
-+ (instancetype)observersWithProtocol:(Protocol*)protocol;
-
-// Adds |observer| to this container.
-- (void)addObserver:(id)observer;
-
-// Remove |observer| from this container.
-- (void)removeObserver:(id)observer;
-
-// Returns true if there are currently no observers.
-- (BOOL)empty;
-
-// Executes callback on every observer. |callback| cannot be nil.
-- (void)executeOnObservers:(ExecutionWithObserverBlock)callback;
-
-@end
-
-#endif // BASE_IOS_CRB_PROTOCOL_OBSERVERS_H_
diff --git a/base/ios/crb_protocol_observers.mm b/base/ios/crb_protocol_observers.mm
deleted file mode 100644
index 1a3b9f7..0000000
--- a/base/ios/crb_protocol_observers.mm
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright 2014 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 "base/ios/crb_protocol_observers.h"
-
-#include <objc/runtime.h>
-#include <stddef.h>
-#include <algorithm>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/stl_util.h"
-
-@interface CRBProtocolObservers () {
- base::scoped_nsobject<Protocol> _protocol;
- // ivars declared here are private to the implementation but must be
- // public for allowing the C++ |Iterator| class access to those ivars.
- @public
- // vector of weak pointers to observers.
- std::vector<__unsafe_unretained id> _observers;
- // The nested level of observer iteration.
- // A depth of 0 means nobody is currently iterating on the list of observers.
- int _invocationDepth;
-}
-
-// Removes nil observers from the list and is called when the
-// |_invocationDepth| reaches 0.
-- (void)compact;
-
-@end
-
-namespace {
-
-class Iterator {
- public:
- explicit Iterator(CRBProtocolObservers* protocol_observers);
- ~Iterator();
- id GetNext();
-
- private:
- CRBProtocolObservers* protocol_observers_;
- size_t index_;
- size_t max_index_;
-};
-
-Iterator::Iterator(CRBProtocolObservers* protocol_observers)
- : protocol_observers_(protocol_observers),
- index_(0),
- max_index_(protocol_observers->_observers.size()) {
- DCHECK(protocol_observers_);
- ++protocol_observers->_invocationDepth;
-}
-
-Iterator::~Iterator() {
- if (protocol_observers_ && --protocol_observers_->_invocationDepth == 0)
- [protocol_observers_ compact];
-}
-
-id Iterator::GetNext() {
- if (!protocol_observers_)
- return nil;
- auto& observers = protocol_observers_->_observers;
- // Skip nil elements.
- size_t max_index = std::min(max_index_, observers.size());
- while (index_ < max_index && !observers[index_])
- ++index_;
- return index_ < max_index ? observers[index_++] : nil;
-}
-}
-
-@interface CRBProtocolObservers ()
-
-// Designated initializer.
-- (id)initWithProtocol:(Protocol*)protocol;
-
-@end
-
-@implementation CRBProtocolObservers
-
-+ (instancetype)observersWithProtocol:(Protocol*)protocol {
- return [[[self alloc] initWithProtocol:protocol] autorelease];
-}
-
-- (id)init {
- NOTREACHED();
- return nil;
-}
-
-- (id)initWithProtocol:(Protocol*)protocol {
- self = [super init];
- if (self) {
- _protocol.reset([protocol retain]);
- }
- return self;
-}
-
-- (Protocol*)protocol {
- return _protocol.get();
-}
-
-- (void)addObserver:(id)observer {
- DCHECK(observer);
- DCHECK([observer conformsToProtocol:self.protocol]);
-
- if (base::ContainsValue(_observers, observer))
- return;
-
- _observers.push_back(observer);
-}
-
-- (void)removeObserver:(id)observer {
- DCHECK(observer);
- auto it = std::find(_observers.begin(), _observers.end(), observer);
- if (it != _observers.end()) {
- if (_invocationDepth)
- *it = nil;
- else
- _observers.erase(it);
- }
-}
-
-- (BOOL)empty {
- int count = 0;
- for (id observer : _observers) {
- if (observer != nil)
- ++count;
- }
- return count == 0;
-}
-
-#pragma mark - NSObject
-
-- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector {
- NSMethodSignature* signature = [super methodSignatureForSelector:selector];
- if (signature)
- return signature;
-
- // Look for a required method in the protocol. protocol_getMethodDescription
- // returns a struct whose fields are null if a method for the selector was
- // not found.
- struct objc_method_description description =
- protocol_getMethodDescription(self.protocol, selector, YES, YES);
- if (description.types)
- return [NSMethodSignature signatureWithObjCTypes:description.types];
-
- // Look for an optional method in the protocol.
- description = protocol_getMethodDescription(self.protocol, selector, NO, YES);
- if (description.types)
- return [NSMethodSignature signatureWithObjCTypes:description.types];
-
- // There is neither a required nor optional method with this selector in the
- // protocol, so invoke -[NSObject doesNotRecognizeSelector:] to raise
- // NSInvalidArgumentException.
- [self doesNotRecognizeSelector:selector];
- return nil;
-}
-
-- (void)forwardInvocation:(NSInvocation*)invocation {
- DCHECK(invocation);
- if (_observers.empty())
- return;
- SEL selector = [invocation selector];
- Iterator it(self);
- id observer;
- while ((observer = it.GetNext()) != nil) {
- if ([observer respondsToSelector:selector])
- [invocation invokeWithTarget:observer];
- }
-}
-
-- (void)executeOnObservers:(ExecutionWithObserverBlock)callback {
- DCHECK(callback);
- if (_observers.empty())
- return;
- Iterator it(self);
- id observer;
- while ((observer = it.GetNext()) != nil)
- callback(observer);
-}
-
-#pragma mark - Private
-
-- (void)compact {
- DCHECK(!_invocationDepth);
- _observers.erase(std::remove(_observers.begin(), _observers.end(), nil),
- _observers.end());
-}
-
-@end
diff --git a/base/ios/crb_protocol_observers_unittest.mm b/base/ios/crb_protocol_observers_unittest.mm
deleted file mode 100644
index 07f5cff..0000000
--- a/base/ios/crb_protocol_observers_unittest.mm
+++ /dev/null
@@ -1,290 +0,0 @@
-// Copyright 2014 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 "base/ios/crb_protocol_observers.h"
-#include "base/ios/weak_nsobject.h"
-#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/mac/scoped_nsobject.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-@protocol TestObserver
-
-@required
-- (void)requiredMethod;
-- (void)reset;
-
-@optional
-- (void)optionalMethod;
-- (void)mutateByAddingObserver:(id<TestObserver>)observer;
-- (void)mutateByRemovingObserver:(id<TestObserver>)observer;
-- (void)nestedMutateByAddingObserver:(id<TestObserver>)observer;
-- (void)nestedMutateByRemovingObserver:(id<TestObserver>)observer;
-
-@end
-
-// Implements only the required methods in the TestObserver protocol.
-@interface TestPartialObserver : NSObject<TestObserver>
-@property(nonatomic, readonly) BOOL requiredMethodInvoked;
-@end
-
-// Implements all the methods in the TestObserver protocol.
-@interface TestCompleteObserver : TestPartialObserver<TestObserver>
-@property(nonatomic, readonly) BOOL optionalMethodInvoked;
-@end
-
-@interface TestMutateObserver : TestCompleteObserver
-- (instancetype)initWithObserver:(CRBProtocolObservers*)observer
- NS_DESIGNATED_INITIALIZER;
-- (instancetype)init NS_UNAVAILABLE;
-@end
-
-namespace {
-
-class CRBProtocolObserversTest : public PlatformTest {
- public:
- CRBProtocolObserversTest() {}
-
- protected:
- void SetUp() override {
- PlatformTest::SetUp();
-
- observers_.reset([[CRBProtocolObservers observersWithProtocol:
- @protocol(TestObserver)] retain]);
-
- partial_observer_.reset([[TestPartialObserver alloc] init]);
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-
- complete_observer_.reset([[TestCompleteObserver alloc] init]);
- EXPECT_FALSE([complete_observer_ requiredMethodInvoked]);
- EXPECT_FALSE([complete_observer_ optionalMethodInvoked]);
-
- mutate_observer_.reset(
- [[TestMutateObserver alloc] initWithObserver:observers_.get()]);
- EXPECT_FALSE([mutate_observer_ requiredMethodInvoked]);
- }
-
- base::scoped_nsobject<id> observers_;
- base::scoped_nsobject<TestPartialObserver> partial_observer_;
- base::scoped_nsobject<TestCompleteObserver> complete_observer_;
- base::scoped_nsobject<TestMutateObserver> mutate_observer_;
-};
-
-// Verifies basic functionality of -[CRBProtocolObservers addObserver:] and
-// -[CRBProtocolObservers removeObserver:].
-TEST_F(CRBProtocolObserversTest, AddRemoveObserver) {
- // Add an observer and verify that the CRBProtocolObservers instance forwards
- // an invocation to it.
- [observers_ addObserver:partial_observer_];
- [observers_ requiredMethod];
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
-
- [partial_observer_ reset];
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-
- // Remove the observer and verify that the CRBProtocolObservers instance no
- // longer forwards an invocation to it.
- [observers_ removeObserver:partial_observer_];
- [observers_ requiredMethod];
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-}
-
-// Verifies that CRBProtocolObservers correctly forwards the invocation of a
-// required method in the protocol.
-TEST_F(CRBProtocolObserversTest, RequiredMethods) {
- [observers_ addObserver:partial_observer_];
- [observers_ addObserver:complete_observer_];
- [observers_ requiredMethod];
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
- EXPECT_TRUE([complete_observer_ requiredMethodInvoked]);
-}
-
-// Verifies that CRBProtocolObservers correctly forwards the invocation of an
-// optional method in the protocol.
-TEST_F(CRBProtocolObserversTest, OptionalMethods) {
- [observers_ addObserver:partial_observer_];
- [observers_ addObserver:complete_observer_];
- [observers_ optionalMethod];
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
- EXPECT_FALSE([complete_observer_ requiredMethodInvoked]);
- EXPECT_TRUE([complete_observer_ optionalMethodInvoked]);
-}
-
-// Verifies that CRBProtocolObservers only holds a weak reference to an
-// observer.
-TEST_F(CRBProtocolObserversTest, WeakReference) {
- base::WeakNSObject<TestPartialObserver> weak_observer(
- partial_observer_);
- EXPECT_TRUE(weak_observer);
-
- [observers_ addObserver:partial_observer_];
-
- {
- // Need an autorelease pool here, because
- // -[CRBProtocolObservers forwardInvocation:] creates a temporary
- // autoreleased array that holds all the observers.
- base::mac::ScopedNSAutoreleasePool pool;
- [observers_ requiredMethod];
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
- }
-
- partial_observer_.reset();
- EXPECT_FALSE(weak_observer.get());
-}
-
-// Verifies that an observer can safely remove itself as observer while being
-// notified.
-TEST_F(CRBProtocolObserversTest, SelfMutateObservers) {
- [observers_ addObserver:mutate_observer_];
- EXPECT_FALSE([observers_ empty]);
-
- [observers_ requiredMethod];
- EXPECT_TRUE([mutate_observer_ requiredMethodInvoked]);
-
- [mutate_observer_ reset];
-
- [observers_ nestedMutateByRemovingObserver:mutate_observer_];
- EXPECT_FALSE([mutate_observer_ requiredMethodInvoked]);
-
- [observers_ addObserver:partial_observer_];
-
- [observers_ requiredMethod];
- EXPECT_FALSE([mutate_observer_ requiredMethodInvoked]);
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
-
- [observers_ removeObserver:partial_observer_];
- EXPECT_TRUE([observers_ empty]);
-}
-
-// Verifies that - [CRBProtocolObservers addObserver:] and
-// - [CRBProtocolObservers removeObserver:] can be called while methods are
-// being forwarded.
-TEST_F(CRBProtocolObserversTest, MutateObservers) {
- // Indirectly add an observer while forwarding an observer method.
- [observers_ addObserver:mutate_observer_];
-
- [observers_ mutateByAddingObserver:partial_observer_];
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-
- // Check that methods are correctly forwared to the indirectly added observer.
- [mutate_observer_ reset];
- [observers_ requiredMethod];
- EXPECT_TRUE([mutate_observer_ requiredMethodInvoked]);
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
-
- [mutate_observer_ reset];
- [partial_observer_ reset];
-
- // Indirectly remove an observer while forwarding an observer method.
- [observers_ mutateByRemovingObserver:partial_observer_];
-
- // Check that method is not forwared to the indirectly removed observer.
- [observers_ requiredMethod];
- EXPECT_TRUE([mutate_observer_ requiredMethodInvoked]);
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-}
-
-// Verifies that - [CRBProtocolObservers addObserver:] and
-// - [CRBProtocolObservers removeObserver:] can be called while methods are
-// being forwarded with a nested invocation depth > 0.
-TEST_F(CRBProtocolObserversTest, NestedMutateObservers) {
- // Indirectly add an observer while forwarding an observer method.
- [observers_ addObserver:mutate_observer_];
-
- [observers_ nestedMutateByAddingObserver:partial_observer_];
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-
- // Check that methods are correctly forwared to the indirectly added observer.
- [mutate_observer_ reset];
- [observers_ requiredMethod];
- EXPECT_TRUE([mutate_observer_ requiredMethodInvoked]);
- EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
-
- [mutate_observer_ reset];
- [partial_observer_ reset];
-
- // Indirectly remove an observer while forwarding an observer method.
- [observers_ nestedMutateByRemovingObserver:partial_observer_];
-
- // Check that method is not forwared to the indirectly removed observer.
- [observers_ requiredMethod];
- EXPECT_TRUE([mutate_observer_ requiredMethodInvoked]);
- EXPECT_FALSE([partial_observer_ requiredMethodInvoked]);
-}
-
-} // namespace
-
-@implementation TestPartialObserver {
- BOOL _requiredMethodInvoked;
-}
-
-- (BOOL)requiredMethodInvoked {
- return _requiredMethodInvoked;
-}
-
-- (void)requiredMethod {
- _requiredMethodInvoked = YES;
-}
-
-- (void)reset {
- _requiredMethodInvoked = NO;
-}
-
-@end
-
-@implementation TestCompleteObserver {
- BOOL _optionalMethodInvoked;
-}
-
-- (BOOL)optionalMethodInvoked {
- return _optionalMethodInvoked;
-}
-
-- (void)optionalMethod {
- _optionalMethodInvoked = YES;
-}
-
-- (void)reset {
- [super reset];
- _optionalMethodInvoked = NO;
-}
-
-@end
-
-@implementation TestMutateObserver {
- id _observers; // weak
-}
-
-- (instancetype)initWithObserver:(CRBProtocolObservers*)observers {
- self = [super init];
- if (self) {
- _observers = observers;
- }
- return self;
-}
-
-- (instancetype)init {
- NOTREACHED();
- return nil;
-}
-
-- (void)mutateByAddingObserver:(id<TestObserver>)observer {
- [_observers addObserver:observer];
-}
-
-- (void)mutateByRemovingObserver:(id<TestObserver>)observer {
- [_observers removeObserver:observer];
-}
-
-- (void)nestedMutateByAddingObserver:(id<TestObserver>)observer {
- [_observers mutateByAddingObserver:observer];
-}
-
-- (void)nestedMutateByRemovingObserver:(id<TestObserver>)observer {
- [_observers mutateByRemovingObserver:observer];
-}
-
-@end
diff --git a/base/ios/device_util.h b/base/ios/device_util.h
deleted file mode 100644
index b1bed5c..0000000
--- a/base/ios/device_util.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2012 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 BASE_IOS_DEVICE_UTIL_H_
-#define BASE_IOS_DEVICE_UTIL_H_
-
-#include <stdint.h>
-
-#include <string>
-
-namespace ios {
-namespace device_util {
-
-// Returns the hardware version of the device the app is running on.
-//
-// The returned string is the string returned by sysctlbyname() with name
-// "hw.machine". Possible (known) values include:
-//
-// iPhone1,1 -> iPhone 1G
-// iPhone1,2 -> iPhone 3G
-// iPhone2,1 -> iPhone 3GS
-// iPhone3,1 -> iPhone 4/AT&T
-// iPhone3,2 -> iPhone 4/Other Carrier?
-// iPhone3,3 -> iPhone 4/Other Carrier?
-// iPhone4,1 -> iPhone 4S
-//
-// iPod1,1 -> iPod touch 1G
-// iPod2,1 -> iPod touch 2G
-// iPod2,2 -> ?
-// iPod3,1 -> iPod touch 3G
-// iPod4,1 -> iPod touch 4G
-// iPod5,1 -> ?
-//
-// iPad1,1 -> iPad 1G, WiFi
-// iPad1,? -> iPad 1G, 3G <- needs 3G owner to test
-// iPad2,1 -> iPad 2G, WiFi
-//
-// AppleTV2,1 -> AppleTV 2
-//
-// i386 -> Simulator
-// x86_64 -> Simulator
-std::string GetPlatform();
-
-// Returns true if the application is running on a device with 512MB or more
-// RAM.
-bool RamIsAtLeast512Mb();
-
-// Returns true if the application is running on a device with 1024MB or more
-// RAM.
-bool RamIsAtLeast1024Mb();
-
-// Returns true if the application is running on a device with |ram_in_mb| MB or
-// more RAM.
-// Use with caution! Actual RAM reported by devices is less than the commonly
-// used powers-of-two values. For example, a 512MB device may report only 502MB
-// RAM. The convenience methods above should be used in most cases because they
-// correctly handle this issue.
-bool RamIsAtLeast(uint64_t ram_in_mb);
-
-// Returns true if the device has only one core.
-bool IsSingleCoreDevice();
-
-// Returns the MAC address of the interface with name |interface_name|.
-std::string GetMacAddress(const std::string& interface_name);
-
-// Returns a random UUID.
-std::string GetRandomId();
-
-// Returns an identifier for the device, using the given |salt|. A global
-// identifier is generated the first time this method is called, and the salt
-// is used to be able to generate distinct identifiers for the same device. If
-// |salt| is NULL, a default value is used. Unless you are using this value for
-// something that should be anonymous, you should probably pass NULL.
-std::string GetDeviceIdentifier(const char* salt);
-
-// Returns a hashed version of |in_string| using |salt| (which must not be
-// zero-length). Different salt values should result in differently hashed
-// strings.
-std::string GetSaltedString(const std::string& in_string,
- const std::string& salt);
-
-} // namespace device_util
-} // namespace ios
-
-#endif // BASE_IOS_DEVICE_UTIL_H_
diff --git a/base/ios/device_util.mm b/base/ios/device_util.mm
deleted file mode 100644
index 5ec1e69..0000000
--- a/base/ios/device_util.mm
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/ios/device_util.h"
-
-#include <CommonCrypto/CommonDigest.h>
-#import <UIKit/UIKit.h>
-#include <ifaddrs.h>
-#include <net/if_dl.h>
-#include <stddef.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-
-#include <memory>
-
-#include "base/logging.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/sys_string_conversions.h"
-
-namespace {
-
-// Client ID key in the user preferences.
-NSString* const kLegacyClientIdPreferenceKey = @"ChromiumClientID";
-NSString* const kClientIdPreferenceKey = @"ChromeClientID";
-// Current hardware type. This is used to detect that a device has been backed
-// up and restored to another device, and allows regenerating a new device id.
-NSString* const kHardwareTypePreferenceKey = @"ClientIDGenerationHardwareType";
-// Default salt for device ids.
-const char kDefaultSalt[] = "Salt";
-// Zero UUID returned on buggy iOS devices.
-NSString* const kZeroUUID = @"00000000-0000-0000-0000-000000000000";
-
-NSString* GenerateClientId() {
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
-
- // Try to migrate from legacy client id.
- NSString* client_id = [defaults stringForKey:kLegacyClientIdPreferenceKey];
-
- // Some iOS6 devices return a buggy identifierForVendor:
- // http://openradar.appspot.com/12377282. If this is the case, revert to
- // generating a new one.
- if (!client_id || [client_id isEqualToString:kZeroUUID]) {
- client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
- if ([client_id isEqualToString:kZeroUUID])
- client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId());
- }
- return client_id;
-}
-
-} // namespace
-
-namespace ios {
-namespace device_util {
-
-std::string GetPlatform() {
- std::string platform;
- size_t size = 0;
- sysctlbyname("hw.machine", NULL, &size, NULL, 0);
- sysctlbyname("hw.machine", base::WriteInto(&platform, size), &size, NULL, 0);
- return platform;
-}
-
-bool RamIsAtLeast512Mb() {
- // 512MB devices report anywhere from 502-504 MB, use 450 MB just to be safe.
- return RamIsAtLeast(450);
-}
-
-bool RamIsAtLeast1024Mb() {
- // 1GB devices report anywhere from 975-999 MB, use 900 MB just to be safe.
- return RamIsAtLeast(900);
-}
-
-bool RamIsAtLeast(uint64_t ram_in_mb) {
- uint64_t memory_size = 0;
- size_t size = sizeof(memory_size);
- if (sysctlbyname("hw.memsize", &memory_size, &size, NULL, 0) == 0) {
- // Anything >= 500M, call high ram.
- return memory_size >= ram_in_mb * 1024 * 1024;
- }
- return false;
-}
-
-bool IsSingleCoreDevice() {
- uint64_t cpu_number = 0;
- size_t sizes = sizeof(cpu_number);
- sysctlbyname("hw.physicalcpu", &cpu_number, &sizes, NULL, 0);
- return cpu_number == 1;
-}
-
-std::string GetMacAddress(const std::string& interface_name) {
- std::string mac_string;
- struct ifaddrs* addresses;
- if (getifaddrs(&addresses) == 0) {
- for (struct ifaddrs* address = addresses; address;
- address = address->ifa_next) {
- if ((address->ifa_addr->sa_family == AF_LINK) &&
- strcmp(interface_name.c_str(), address->ifa_name) == 0) {
- const struct sockaddr_dl* found_address_struct =
- reinterpret_cast<const struct sockaddr_dl*>(address->ifa_addr);
-
- // |found_address_struct->sdl_data| contains the interface name followed
- // by the interface address. The address part can be accessed based on
- // the length of the name, that is, |found_address_struct->sdl_nlen|.
- const unsigned char* found_address =
- reinterpret_cast<const unsigned char*>(
- &found_address_struct->sdl_data[
- found_address_struct->sdl_nlen]);
-
- int found_address_length = found_address_struct->sdl_alen;
- for (int i = 0; i < found_address_length; ++i) {
- if (i != 0)
- mac_string.push_back(':');
- base::StringAppendF(&mac_string, "%02X", found_address[i]);
- }
- break;
- }
- }
- freeifaddrs(addresses);
- }
- return mac_string;
-}
-
-std::string GetRandomId() {
- base::ScopedCFTypeRef<CFUUIDRef> uuid_object(
- CFUUIDCreate(kCFAllocatorDefault));
- base::ScopedCFTypeRef<CFStringRef> uuid_string(
- CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
- return base::SysCFStringRefToUTF8(uuid_string);
-}
-
-std::string GetDeviceIdentifier(const char* salt) {
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
-
- NSString* last_seen_hardware =
- [defaults stringForKey:kHardwareTypePreferenceKey];
- NSString* current_hardware = base::SysUTF8ToNSString(GetPlatform());
- if (!last_seen_hardware) {
- last_seen_hardware = current_hardware;
- [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey];
- [defaults synchronize];
- }
-
- NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
-
- if (!client_id || ![last_seen_hardware isEqualToString:current_hardware]) {
- client_id = GenerateClientId();
- [defaults setObject:client_id forKey:kClientIdPreferenceKey];
- [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey];
- [defaults synchronize];
- }
-
- return GetSaltedString(base::SysNSStringToUTF8(client_id),
- salt ? salt : kDefaultSalt);
-}
-
-std::string GetSaltedString(const std::string& in_string,
- const std::string& salt) {
- DCHECK(salt.length());
- NSData* hash_data = [base::SysUTF8ToNSString(in_string + salt)
- dataUsingEncoding:NSUTF8StringEncoding];
-
- unsigned char hash[CC_SHA256_DIGEST_LENGTH];
- CC_SHA256([hash_data bytes], [hash_data length], hash);
- CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash);
-
- base::ScopedCFTypeRef<CFUUIDRef> uuid_object(
- CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes));
- base::ScopedCFTypeRef<CFStringRef> device_id(
- CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
- return base::SysCFStringRefToUTF8(device_id);
-}
-
-} // namespace device_util
-} // namespace ios
diff --git a/base/ios/device_util_unittest.mm b/base/ios/device_util_unittest.mm
deleted file mode 100644
index 82d4217..0000000
--- a/base/ios/device_util_unittest.mm
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright (c) 2012 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 <UIKit/UIKit.h>
-
-#include "base/ios/device_util.h"
-#include "base/strings/sys_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-namespace {
-// The behavior of most of these utility functions depends on what they are run
-// on, so there is not much to unittest them. The APIs are run to make sure they
-// don't choke. Additional checks are added for particular APIs when needed.
-
-typedef PlatformTest DeviceUtilTest;
-
-void CleanNSUserDefaultsForDeviceId() {
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
- [defaults removeObjectForKey:@"ChromeClientID"];
- [defaults removeObjectForKey:@"ChromiumClientID"];
- [defaults removeObjectForKey:@"ClientIDGenerationHardwareType"];
- [defaults synchronize];
-}
-
-TEST_F(DeviceUtilTest, GetPlatform) {
- GTEST_ASSERT_GT(ios::device_util::GetPlatform().length(), 0U);
-}
-
-TEST_F(DeviceUtilTest, IsSingleCoreDevice) {
- ios::device_util::IsSingleCoreDevice();
-}
-
-TEST_F(DeviceUtilTest, GetMacAddress) {
- GTEST_ASSERT_GT(ios::device_util::GetMacAddress("en0").length(), 0U);
-}
-
-TEST_F(DeviceUtilTest, GetRandomId) {
- GTEST_ASSERT_GT(ios::device_util::GetRandomId().length(), 0U);
-}
-
-TEST_F(DeviceUtilTest, GetDeviceIdentifier) {
- CleanNSUserDefaultsForDeviceId();
-
- std::string default_id = ios::device_util::GetDeviceIdentifier(NULL);
- std::string other_id = ios::device_util::GetDeviceIdentifier("ForTest");
- EXPECT_NE(default_id, other_id);
-
- CleanNSUserDefaultsForDeviceId();
-
- std::string new_default_id = ios::device_util::GetDeviceIdentifier(NULL);
- if (![[[[UIDevice currentDevice] identifierForVendor] UUIDString]
- isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
- EXPECT_EQ(default_id, new_default_id);
- } else {
- EXPECT_NE(default_id, new_default_id);
- }
-
- CleanNSUserDefaultsForDeviceId();
-}
-
-TEST_F(DeviceUtilTest, CheckMigration) {
- CleanNSUserDefaultsForDeviceId();
-
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:@"10000000-0000-0000-0000-000000000000"
- forKey:@"ChromeClientID"];
- [defaults synchronize];
- std::string expected_id = ios::device_util::GetDeviceIdentifier(NULL);
- [defaults removeObjectForKey:@"ChromeClientID"];
- [defaults setObject:@"10000000-0000-0000-0000-000000000000"
- forKey:@"ChromiumClientID"];
- [defaults synchronize];
- std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
- EXPECT_EQ(expected_id, new_id);
-
- CleanNSUserDefaultsForDeviceId();
-}
-
-TEST_F(DeviceUtilTest, CheckMigrationFromZero) {
- CleanNSUserDefaultsForDeviceId();
-
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:@"00000000-0000-0000-0000-000000000000"
- forKey:@"ChromeClientID"];
- [defaults synchronize];
- std::string zero_id = ios::device_util::GetDeviceIdentifier(NULL);
- [defaults removeObjectForKey:@"ChromeClientID"];
- [defaults setObject:@"00000000-0000-0000-0000-000000000000"
- forKey:@"ChromiumClientID"];
- [defaults synchronize];
- std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
- EXPECT_NE(zero_id, new_id);
-
- CleanNSUserDefaultsForDeviceId();
-}
-
-TEST_F(DeviceUtilTest, GetSaltedStringEquals) {
- std::string string1("The quick brown fox jumps over the lazy dog");
- std::string string2("The quick brown fox jumps over the lazy dog");
- std::string salt("salt");
- // Same string and same salt should result in the same salted string.
- EXPECT_EQ(ios::device_util::GetSaltedString(string1, salt),
- ios::device_util::GetSaltedString(string2, salt));
-}
-
-TEST_F(DeviceUtilTest, GetSaltedStringNotEquals) {
- std::string string1("The quick brown fox jumps over the lazy dog");
- std::string string2("The lazy brown fox jumps over the quick dog");
- std::string salt("salt");
- // Different string and same salt should result in different salted strings.
- EXPECT_NE(ios::device_util::GetSaltedString(string1, salt),
- ios::device_util::GetSaltedString(string2, salt));
-}
-
-TEST_F(DeviceUtilTest, GetSaltedStringDifferentSalt) {
- std::string string1("The quick brown fox jumps over the lazy dog");
- std::string salt1("salt");
- std::string salt2("pepper");
- // Same string with different salt should result in different salted strings.
- EXPECT_NE(ios::device_util::GetSaltedString(string1, salt1),
- ios::device_util::GetSaltedString(string1, salt2));
-}
-
-TEST_F(DeviceUtilTest, CheckDeviceMigration) {
- CleanNSUserDefaultsForDeviceId();
-
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:@"10000000-0000-0000-0000-000000000000"
- forKey:@"ChromeClientID"];
- [defaults synchronize];
- std::string base_id = ios::device_util::GetDeviceIdentifier(NULL);
- [defaults setObject:@"Foo" forKey:@"ClientIDGenerationHardwareType"];
- [defaults synchronize];
- std::string new_id = ios::device_util::GetDeviceIdentifier(NULL);
- EXPECT_NE(new_id, base_id);
-
- CleanNSUserDefaultsForDeviceId();
-}
-
-} // namespace
diff --git a/base/ios/ios_util.h b/base/ios/ios_util.h
deleted file mode 100644
index 2464b1c..0000000
--- a/base/ios/ios_util.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2012 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 BASE_IOS_IOS_UTIL_H_
-#define BASE_IOS_IOS_UTIL_H_
-
-#include <stdint.h>
-
-#include "base/base_export.h"
-#include "base/files/file_path.h"
-
-namespace base {
-namespace ios {
-
-// Returns whether the operating system is iOS 10 or later.
-BASE_EXPORT bool IsRunningOnIOS10OrLater();
-
-// Returns whether the operating system is iOS 11 or later.
-BASE_EXPORT bool IsRunningOnIOS11OrLater();
-
-// Returns whether the operating system is at the given version or later.
-BASE_EXPORT bool IsRunningOnOrLater(int32_t major,
- int32_t minor,
- int32_t bug_fix);
-
-// Returns whether iOS is signalling that an RTL text direction should be used
-// regardless of the current locale. This should not return true if the current
-// language is a "real" RTL language such as Arabic or Urdu; it should only
-// return true in cases where the RTL text direction has been forced (for
-// example by using the "RTL Psuedolanguage" option when launching from XCode).
-BASE_EXPORT bool IsInForcedRTL();
-
-// Stores the |path| of the ICU dat file in a global to be referenced later by
-// FilePathOfICUFile(). This should only be called once.
-BASE_EXPORT void OverridePathOfEmbeddedICU(const char* path);
-
-// Returns the overriden path set by OverridePathOfEmbeddedICU(), otherwise
-// returns invalid FilePath.
-BASE_EXPORT FilePath FilePathOfEmbeddedICU();
-
-} // namespace ios
-} // namespace base
-
-#endif // BASE_IOS_IOS_UTIL_H_
diff --git a/base/ios/ios_util.mm b/base/ios/ios_util.mm
deleted file mode 100644
index 2402d30..0000000
--- a/base/ios/ios_util.mm
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2012 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.
-
-#include "base/ios/ios_util.h"
-
-#import <Foundation/Foundation.h>
-#include <stddef.h>
-
-#include "base/macros.h"
-#include "base/sys_info.h"
-
-namespace {
-
-// Return a 3 elements array containing the major, minor and bug fix version of
-// the OS.
-const int32_t* OSVersionAsArray() {
- int32_t* digits = new int32_t[3];
- base::SysInfo::OperatingSystemVersionNumbers(
- &digits[0], &digits[1], &digits[2]);
- return digits;
-}
-
-std::string* g_icudtl_path_override = nullptr;
-
-} // namespace
-
-namespace base {
-namespace ios {
-
-bool IsRunningOnIOS10OrLater() {
- static const bool is_running_on_or_later = IsRunningOnOrLater(10, 0, 0);
- return is_running_on_or_later;
-}
-
-bool IsRunningOnIOS11OrLater() {
- static const bool is_running_on_or_later = IsRunningOnOrLater(11, 0, 0);
- return is_running_on_or_later;
-}
-
-bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
- static const int32_t* current_version = OSVersionAsArray();
- int32_t version[] = {major, minor, bug_fix};
- for (size_t i = 0; i < arraysize(version); i++) {
- if (current_version[i] != version[i])
- return current_version[i] > version[i];
- }
- return true;
-}
-
-bool IsInForcedRTL() {
- NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
- return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
-}
-
-void OverridePathOfEmbeddedICU(const char* path) {
- DCHECK(!g_icudtl_path_override);
- g_icudtl_path_override = new std::string(path);
-}
-
-FilePath FilePathOfEmbeddedICU() {
- if (g_icudtl_path_override) {
- return FilePath(*g_icudtl_path_override);
- }
- return FilePath();
-}
-
-} // namespace ios
-} // namespace base
diff --git a/base/ios/ns_error_util.h b/base/ios/ns_error_util.h
deleted file mode 100644
index 1012292..0000000
--- a/base/ios/ns_error_util.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 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 BASE_IOS_NS_ERROR_UTIL_H_
-#define BASE_IOS_NS_ERROR_UTIL_H_
-
-@class NSError;
-
-namespace base {
-namespace ios {
-
-// Iterates through |error|'s underlying errors and returns the first error for
-// which there is no underlying error.
-NSError* GetFinalUnderlyingErrorFromError(NSError* error);
-
-// Returns a copy of |original_error| with |underlying_error| appended to the
-// end of its underlying error chain.
-NSError* ErrorWithAppendedUnderlyingError(NSError* original_error,
- NSError* underlying_error);
-
-} // namespace ios
-} // namespace base
-
-#endif // BASE_IOS_NS_ERROR_UTIL_H_
diff --git a/base/ios/ns_error_util.mm b/base/ios/ns_error_util.mm
deleted file mode 100644
index c44d9ee..0000000
--- a/base/ios/ns_error_util.mm
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2015 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 "base/ios/ns_error_util.h"
-
-#import <Foundation/Foundation.h>
-
-#include "base/logging.h"
-#include "base/mac/scoped_nsobject.h"
-
-namespace base {
-namespace ios {
-
-namespace {
-// Iterates through |error|'s underlying errors and returns them in an array.
-NSArray* GetFullErrorChainForError(NSError* error) {
- NSMutableArray* error_chain = [NSMutableArray array];
- NSError* current_error = error;
- while (current_error) {
- DCHECK([current_error isKindOfClass:[NSError class]]);
- [error_chain addObject:current_error];
- current_error = current_error.userInfo[NSUnderlyingErrorKey];
- }
- return error_chain;
-}
-} // namespace
-
-NSError* GetFinalUnderlyingErrorFromError(NSError* error) {
- DCHECK(error);
- return [GetFullErrorChainForError(error) lastObject];
-}
-
-NSError* ErrorWithAppendedUnderlyingError(NSError* original_error,
- NSError* underlying_error) {
- DCHECK(original_error);
- DCHECK(underlying_error);
- NSArray* error_chain = GetFullErrorChainForError(original_error);
- NSError* current_error = underlying_error;
- for (NSInteger idx = error_chain.count - 1; idx >= 0; --idx) {
- NSError* error = error_chain[idx];
- scoped_nsobject<NSMutableDictionary> user_info(
- [error.userInfo mutableCopy]);
- [user_info setObject:current_error forKey:NSUnderlyingErrorKey];
- current_error = [NSError errorWithDomain:error.domain
- code:error.code
- userInfo:user_info];
- }
- return current_error;
-}
-
-} // namespace ios
-} // namespace base
diff --git a/base/ios/scoped_critical_action.h b/base/ios/scoped_critical_action.h
deleted file mode 100644
index 2f7d16c..0000000
--- a/base/ios/scoped_critical_action.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2012 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 BASE_IOS_SCOPED_CRITICAL_ACTION_H_
-#define BASE_IOS_SCOPED_CRITICAL_ACTION_H_
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/synchronization/lock.h"
-
-namespace base {
-namespace ios {
-
-// This class attempts to allow the application to continue to run for a period
-// of time after it transitions to the background. The construction of an
-// instance of this class marks the beginning of a task that needs background
-// running time when the application is moved to the background and the
-// destruction marks the end of such a task.
-//
-// Note there is no guarantee that the task will continue to finish when the
-// application is moved to the background.
-//
-// This class should be used at times where leaving a task unfinished might be
-// detrimental to user experience. For example, it should be used to ensure that
-// the application has enough time to save important data or at least attempt to
-// save such data.
-class ScopedCriticalAction {
- public:
- ScopedCriticalAction();
- ~ScopedCriticalAction();
-
- private:
- // Core logic; ScopedCriticalAction should not be reference counted so
- // that it follows the normal pattern of stack-allocating ScopedFoo objects,
- // but the expiration handler needs to have a reference counted object to
- // refer to.
- class Core : public base::RefCountedThreadSafe<Core> {
- public:
- Core();
-
- // Informs the OS that the background task has started. This is a
- // static method to ensure that the instance has a non-zero refcount.
- static void StartBackgroundTask(scoped_refptr<Core> core);
- // Informs the OS that the background task has completed. This is a
- // static method to ensure that the instance has a non-zero refcount.
- static void EndBackgroundTask(scoped_refptr<Core> core);
-
- private:
- friend base::RefCountedThreadSafe<Core>;
- ~Core();
-
- // |UIBackgroundTaskIdentifier| returned by
- // |beginBackgroundTaskWithExpirationHandler:| when marking the beginning of
- // a long-running background task. It is defined as an |unsigned int|
- // instead of a |UIBackgroundTaskIdentifier| so this class can be used in
- // .cc files.
- unsigned int background_task_id_;
- Lock background_task_id_lock_;
-
- DISALLOW_COPY_AND_ASSIGN(Core);
- };
-
- // The instance of the core that drives the background task.
- scoped_refptr<Core> core_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedCriticalAction);
-};
-
-} // namespace ios
-} // namespace base
-
-#endif // BASE_IOS_SCOPED_CRITICAL_ACTION_H_
diff --git a/base/ios/scoped_critical_action.mm b/base/ios/scoped_critical_action.mm
deleted file mode 100644
index dbfbd45..0000000
--- a/base/ios/scoped_critical_action.mm
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/ios/scoped_critical_action.h"
-
-#import <UIKit/UIKit.h>
-
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "base/synchronization/lock.h"
-
-namespace base {
-namespace ios {
-
-ScopedCriticalAction::ScopedCriticalAction()
- : core_(MakeRefCounted<ScopedCriticalAction::Core>()) {
- ScopedCriticalAction::Core::StartBackgroundTask(core_);
-}
-
-ScopedCriticalAction::~ScopedCriticalAction() {
- ScopedCriticalAction::Core::EndBackgroundTask(core_);
-}
-
-ScopedCriticalAction::Core::Core()
- : background_task_id_(UIBackgroundTaskInvalid) {}
-
-ScopedCriticalAction::Core::~Core() {
- DCHECK_EQ(background_task_id_, UIBackgroundTaskInvalid);
-}
-
-// This implementation calls |beginBackgroundTaskWithExpirationHandler:| when
-// instantiated and |endBackgroundTask:| when destroyed, creating a scope whose
-// execution will continue (temporarily) even after the app is backgrounded.
-// static
-void ScopedCriticalAction::Core::StartBackgroundTask(scoped_refptr<Core> core) {
- UIApplication* application = [UIApplication sharedApplication];
- if (!application) {
- return;
- }
-
- core->background_task_id_ =
- [application beginBackgroundTaskWithExpirationHandler:^{
- DLOG(WARNING) << "Background task with id " << core->background_task_id_
- << " expired.";
- // Note if |endBackgroundTask:| is not called for each task before time
- // expires, the system kills the application.
- EndBackgroundTask(core);
- }];
-
- if (core->background_task_id_ == UIBackgroundTaskInvalid) {
- DLOG(WARNING)
- << "beginBackgroundTaskWithExpirationHandler: returned an invalid ID";
- } else {
- VLOG(3) << "Beginning background task with id "
- << core->background_task_id_;
- }
-}
-
-// static
-void ScopedCriticalAction::Core::EndBackgroundTask(scoped_refptr<Core> core) {
- UIBackgroundTaskIdentifier task_id;
- {
- AutoLock lock_scope(core->background_task_id_lock_);
- if (core->background_task_id_ == UIBackgroundTaskInvalid) {
- return;
- }
- task_id = core->background_task_id_;
- core->background_task_id_ = UIBackgroundTaskInvalid;
- }
-
- VLOG(3) << "Ending background task with id " << task_id;
- [[UIApplication sharedApplication] endBackgroundTask:task_id];
-}
-
-} // namespace ios
-} // namespace base
diff --git a/base/ios/weak_nsobject.h b/base/ios/weak_nsobject.h
deleted file mode 100644
index 498cdee..0000000
--- a/base/ios/weak_nsobject.h
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright 2013 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 BASE_IOS_WEAK_NSOBJECT_H_
-#define BASE_IOS_WEAK_NSOBJECT_H_
-
-#import <Foundation/Foundation.h>
-#import <objc/runtime.h>
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-
-// WeakNSObject<> is patterned after scoped_nsobject<>, but instead of
-// maintaining ownership of an NSObject subclass object, it will nil itself out
-// when the object is deallocated.
-//
-// WeakNSProtocol<> has the same behavior as WeakNSObject, but can be used
-// with protocols.
-//
-// Example usage (base::WeakNSObject<T>):
-// scoped_nsobject<Foo> foo([[Foo alloc] init]);
-// WeakNSObject<Foo> weak_foo; // No pointer
-// weak_foo.reset(foo) // Now a weak reference is kept.
-// [weak_foo description]; // Returns [foo description].
-// foo.reset(); // The reference is released.
-// [weak_foo description]; // Returns nil, as weak_foo is pointing to nil.
-//
-//
-// Implementation wise a WeakNSObject keeps a reference to a refcounted
-// WeakContainer. There is one unique instance of a WeakContainer per watched
-// NSObject, this relationship is maintained via the ObjectiveC associated
-// object API, indirectly via an ObjectiveC CRBWeakNSProtocolSentinel class.
-//
-// Threading restrictions:
-// - Several WeakNSObject pointing to the same underlying object must all be
-// created and dereferenced on the same thread;
-// - thread safety is enforced by the implementation, except in two cases:
-// (1) it is allowed to copy a WeakNSObject on a different thread. However,
-// that copy must return to the original thread before being dereferenced,
-// (2) it is allowed to destroy a WeakNSObject on any thread;
-// - the implementation assumes that the tracked object will be released on the
-// same thread that the WeakNSObject is created on.
-namespace base {
-
-// WeakContainer keeps a weak pointer to an object and clears it when it
-// receives nullify() from the object's sentinel.
-class WeakContainer : public base::RefCountedThreadSafe<WeakContainer> {
- public:
- explicit WeakContainer(id object);
-
- id object() {
- DCHECK(checker_.CalledOnValidThread());
- return object_;
- }
-
- void nullify() {
- DCHECK(checker_.CalledOnValidThread());
- object_ = nil;
- }
-
- private:
- friend base::RefCountedThreadSafe<WeakContainer>;
- ~WeakContainer();
- base::ThreadChecker checker_;
- __unsafe_unretained id object_;
-};
-
-} // namespace base
-
-// Sentinel for observing the object contained in the weak pointer. The object
-// will be deleted when the weak object is deleted and will notify its
-// container.
-@interface CRBWeakNSProtocolSentinel : NSObject
-// Return the only associated container for this object. There can be only one.
-// Will return null if object is nil .
-+ (scoped_refptr<base::WeakContainer>)containerForObject:(id)object;
-@end
-
-namespace base {
-
-// Base class for all WeakNSObject derivatives.
-template <typename NST>
-class WeakNSProtocol {
- public:
- explicit WeakNSProtocol(NST object = nil) {
- container_ = [CRBWeakNSProtocolSentinel containerForObject:object];
- }
-
- WeakNSProtocol(const WeakNSProtocol<NST>& that) {
- // A WeakNSProtocol object can be copied on one thread and used on
- // another.
- checker_.DetachFromThread();
- container_ = that.container_;
- }
-
- ~WeakNSProtocol() {
- // A WeakNSProtocol object can be used on one thread and released on
- // another. This is not the case for the contained object.
- checker_.DetachFromThread();
- }
-
- void reset(NST object = nil) {
- DCHECK(checker_.CalledOnValidThread());
- container_ = [CRBWeakNSProtocolSentinel containerForObject:object];
- }
-
- NST get() const {
- DCHECK(checker_.CalledOnValidThread());
- if (!container_.get())
- return nil;
- return container_->object();
- }
-
- WeakNSProtocol& operator=(const WeakNSProtocol<NST>& that) {
- // A WeakNSProtocol object can be copied on one thread and used on
- // another.
- checker_.DetachFromThread();
- container_ = that.container_;
- return *this;
- }
-
- bool operator==(NST that) const {
- DCHECK(checker_.CalledOnValidThread());
- return get() == that;
- }
-
- bool operator!=(NST that) const {
- DCHECK(checker_.CalledOnValidThread());
- return get() != that;
- }
-
- operator NST() const {
- DCHECK(checker_.CalledOnValidThread());
- return get();
- }
-
- private:
- // Refecounted reference to the container tracking the ObjectiveC object this
- // class encapsulates.
- scoped_refptr<base::WeakContainer> container_;
- base::ThreadChecker checker_;
-};
-
-// Free functions
-template <class NST>
-bool operator==(NST p1, const WeakNSProtocol<NST>& p2) {
- return p1 == p2.get();
-}
-
-template <class NST>
-bool operator!=(NST p1, const WeakNSProtocol<NST>& p2) {
- return p1 != p2.get();
-}
-
-template <typename NST>
-class WeakNSObject : public WeakNSProtocol<NST*> {
- public:
- explicit WeakNSObject(NST* object = nil) : WeakNSProtocol<NST*>(object) {}
-
- WeakNSObject(const WeakNSObject<NST>& that) : WeakNSProtocol<NST*>(that) {}
-
- WeakNSObject& operator=(const WeakNSObject<NST>& that) {
- WeakNSProtocol<NST*>::operator=(that);
- return *this;
- }
-};
-
-// Specialization to make WeakNSObject<id> work.
-template <>
-class WeakNSObject<id> : public WeakNSProtocol<id> {
- public:
- explicit WeakNSObject(id object = nil) : WeakNSProtocol<id>(object) {}
-
- WeakNSObject(const WeakNSObject<id>& that) : WeakNSProtocol<id>(that) {}
-
- WeakNSObject& operator=(const WeakNSObject<id>& that) {
- WeakNSProtocol<id>::operator=(that);
- return *this;
- }
-};
-
-} // namespace base
-
-#endif // BASE_IOS_WEAK_NSOBJECT_H_
diff --git a/base/ios/weak_nsobject.mm b/base/ios/weak_nsobject.mm
deleted file mode 100644
index c017b1d..0000000
--- a/base/ios/weak_nsobject.mm
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/ios/weak_nsobject.h"
-
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/mac/scoped_nsobject.h"
-
-namespace {
-// The key needed by objc_setAssociatedObject.
-char sentinelObserverKey_;
-}
-
-namespace base {
-
-WeakContainer::WeakContainer(id object) : object_(object) {}
-
-WeakContainer::~WeakContainer() {}
-
-} // namespace base
-
-@interface CRBWeakNSProtocolSentinel ()
-// Container to notify on dealloc.
-@property(readonly, assign) scoped_refptr<base::WeakContainer> container;
-// Designed initializer.
-- (id)initWithContainer:(scoped_refptr<base::WeakContainer>)container;
-@end
-
-@implementation CRBWeakNSProtocolSentinel
-
-@synthesize container = container_;
-
-+ (scoped_refptr<base::WeakContainer>)containerForObject:(id)object {
- if (object == nil)
- return nullptr;
- // The autoreleasePool is needed here as the call to objc_getAssociatedObject
- // returns an autoreleased object which is better released sooner than later.
- base::mac::ScopedNSAutoreleasePool pool;
- CRBWeakNSProtocolSentinel* sentinel =
- objc_getAssociatedObject(object, &sentinelObserverKey_);
- if (!sentinel) {
- base::scoped_nsobject<CRBWeakNSProtocolSentinel> newSentinel(
- [[CRBWeakNSProtocolSentinel alloc]
- initWithContainer:new base::WeakContainer(object)]);
- sentinel = newSentinel;
- objc_setAssociatedObject(object, &sentinelObserverKey_, sentinel,
- OBJC_ASSOCIATION_RETAIN);
- // The retain count is 2. One retain is due to the alloc, the other to the
- // association with the weak object.
- DCHECK_EQ(2u, [sentinel retainCount]);
- }
- return [sentinel container];
-}
-
-- (id)initWithContainer:(scoped_refptr<base::WeakContainer>)container {
- DCHECK(container.get());
- self = [super init];
- if (self)
- container_ = container;
- return self;
-}
-
-- (void)dealloc {
- self.container->nullify();
- [super dealloc];
-}
-
-@end
diff --git a/base/ios/weak_nsobject_unittest.mm b/base/ios/weak_nsobject_unittest.mm
deleted file mode 100644
index ba85217..0000000
--- a/base/ios/weak_nsobject_unittest.mm
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/bind.h"
-#include "base/ios/weak_nsobject.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace {
-
-TEST(WeakNSObjectTest, WeakNSObject) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- EXPECT_TRUE(w1);
- p1.reset();
- EXPECT_FALSE(w1);
-}
-
-TEST(WeakNSObjectTest, MultipleWeakNSObject) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- WeakNSObject<NSObject> w2(w1);
- EXPECT_TRUE(w1);
- EXPECT_TRUE(w2);
- EXPECT_TRUE(w1.get() == w2.get());
- p1.reset();
- EXPECT_FALSE(w1);
- EXPECT_FALSE(w2);
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectDies) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- {
- WeakNSObject<NSObject> w1(p1);
- EXPECT_TRUE(w1);
- }
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectReset) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- EXPECT_TRUE(w1);
- w1.reset();
- EXPECT_FALSE(w1);
- EXPECT_TRUE(p1);
- EXPECT_TRUE([p1 description]);
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectResetWithObject) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- scoped_nsobject<NSObject> p2([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- EXPECT_TRUE(w1);
- w1.reset(p2);
- EXPECT_TRUE(w1);
- EXPECT_TRUE([p1 description]);
- EXPECT_TRUE([p2 description]);
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectEmpty) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1;
- EXPECT_FALSE(w1);
- w1.reset(p1);
- EXPECT_TRUE(w1);
- p1.reset();
- EXPECT_FALSE(w1);
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectCopy) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- WeakNSObject<NSObject> w2(w1);
- EXPECT_TRUE(w1);
- EXPECT_TRUE(w2);
- p1.reset();
- EXPECT_FALSE(w1);
- EXPECT_FALSE(w2);
-}
-
-TEST(WeakNSObjectTest, WeakNSObjectAssignment) {
- scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
- WeakNSObject<NSObject> w1(p1);
- WeakNSObject<NSObject> w2;
- EXPECT_FALSE(w2);
- w2 = w1;
- EXPECT_TRUE(w1);
- EXPECT_TRUE(w2);
- p1.reset();
- EXPECT_FALSE(w1);
- EXPECT_FALSE(w2);
-}
-
-// Touches |weak_data| by increasing its length by 1. Used to check that the
-// weak object can be dereferenced.
-void TouchWeakData(const WeakNSObject<NSMutableData>& weak_data) {
- if (!weak_data)
- return;
- [weak_data increaseLengthBy:1];
-}
-
-// Makes a copy of |weak_object| on the current thread and posts a task to touch
-// the weak object on its original thread.
-void CopyWeakNSObjectAndPost(const WeakNSObject<NSMutableData>& weak_object,
- scoped_refptr<SingleThreadTaskRunner> runner) {
- // Copy using constructor.
- WeakNSObject<NSMutableData> weak_copy1(weak_object);
- runner->PostTask(FROM_HERE, Bind(&TouchWeakData, weak_copy1));
- // Copy using assignment operator.
- WeakNSObject<NSMutableData> weak_copy2 = weak_object;
- runner->PostTask(FROM_HERE, Bind(&TouchWeakData, weak_copy2));
-}
-
-// Tests that the weak object can be copied on a different thread.
-TEST(WeakNSObjectTest, WeakNSObjectCopyOnOtherThread) {
- MessageLoop loop;
- Thread other_thread("WeakNSObjectCopyOnOtherThread");
- other_thread.Start();
-
- scoped_nsobject<NSMutableData> data([[NSMutableData alloc] init]);
- WeakNSObject<NSMutableData> weak(data);
-
- scoped_refptr<SingleThreadTaskRunner> runner = loop.task_runner();
- other_thread.task_runner()->PostTask(
- FROM_HERE, Bind(&CopyWeakNSObjectAndPost, weak, runner));
- other_thread.Stop();
- RunLoop().RunUntilIdle();
-
- // Check that TouchWeakData was called and the object touched twice.
- EXPECT_EQ(2u, [data length]);
-}
-
-} // namespace
-} // namespace base
diff --git a/base/message_loop/message_pump_io_ios.cc b/base/message_loop/message_pump_io_ios.cc
deleted file mode 100644
index 9b43e8e..0000000
--- a/base/message_loop/message_pump_io_ios.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-// Copyright 2012 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.
-
-#include "base/message_loop/message_pump_io_ios.h"
-
-namespace base {
-
-MessagePumpIOSForIO::FdWatchController::FdWatchController(
- const Location& from_here)
- : FdWatchControllerInterface(from_here) {}
-
-MessagePumpIOSForIO::FdWatchController::~FdWatchController() {
- StopWatchingFileDescriptor();
-}
-
-bool MessagePumpIOSForIO::FdWatchController::StopWatchingFileDescriptor() {
- if (fdref_ == NULL)
- return true;
-
- CFFileDescriptorDisableCallBacks(fdref_.get(), callback_types_);
- if (pump_)
- pump_->RemoveRunLoopSource(fd_source_);
- fd_source_.reset();
- fdref_.reset();
- callback_types_ = 0;
- pump_.reset();
- watcher_ = NULL;
- return true;
-}
-
-void MessagePumpIOSForIO::FdWatchController::Init(CFFileDescriptorRef fdref,
- CFOptionFlags callback_types,
- CFRunLoopSourceRef fd_source,
- bool is_persistent) {
- DCHECK(fdref);
- DCHECK(!fdref_.is_valid());
-
- is_persistent_ = is_persistent;
- fdref_.reset(fdref);
- callback_types_ = callback_types;
- fd_source_.reset(fd_source);
-}
-
-void MessagePumpIOSForIO::FdWatchController::OnFileCanReadWithoutBlocking(
- int fd,
- MessagePumpIOSForIO* pump) {
- DCHECK(callback_types_ & kCFFileDescriptorReadCallBack);
- watcher_->OnFileCanReadWithoutBlocking(fd);
-}
-
-void MessagePumpIOSForIO::FdWatchController::OnFileCanWriteWithoutBlocking(
- int fd,
- MessagePumpIOSForIO* pump) {
- DCHECK(callback_types_ & kCFFileDescriptorWriteCallBack);
- watcher_->OnFileCanWriteWithoutBlocking(fd);
-}
-
-MessagePumpIOSForIO::MessagePumpIOSForIO() : weak_factory_(this) {
-}
-
-MessagePumpIOSForIO::~MessagePumpIOSForIO() {
-}
-
-bool MessagePumpIOSForIO::WatchFileDescriptor(int fd,
- bool persistent,
- int mode,
- FdWatchController* controller,
- FdWatcher* delegate) {
- DCHECK_GE(fd, 0);
- DCHECK(controller);
- DCHECK(delegate);
- DCHECK(mode == WATCH_READ || mode == WATCH_WRITE || mode == WATCH_READ_WRITE);
-
- // WatchFileDescriptor should be called on the pump thread. It is not
- // threadsafe, and your watcher may never be registered.
- DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread());
-
- CFFileDescriptorContext source_context = {0};
- source_context.info = controller;
-
- CFOptionFlags callback_types = 0;
- if (mode & WATCH_READ) {
- callback_types |= kCFFileDescriptorReadCallBack;
- }
- if (mode & WATCH_WRITE) {
- callback_types |= kCFFileDescriptorWriteCallBack;
- }
-
- CFFileDescriptorRef fdref = controller->fdref_.get();
- if (fdref == NULL) {
- base::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
- CFFileDescriptorCreate(
- kCFAllocatorDefault, fd, false, HandleFdIOEvent, &source_context));
- if (scoped_fdref == NULL) {
- NOTREACHED() << "CFFileDescriptorCreate failed";
- return false;
- }
-
- CFFileDescriptorEnableCallBacks(scoped_fdref, callback_types);
-
- // TODO(wtc): what should the 'order' argument be?
- base::ScopedCFTypeRef<CFRunLoopSourceRef> scoped_fd_source(
- CFFileDescriptorCreateRunLoopSource(
- kCFAllocatorDefault, scoped_fdref, 0));
- if (scoped_fd_source == NULL) {
- NOTREACHED() << "CFFileDescriptorCreateRunLoopSource failed";
- return false;
- }
- CFRunLoopAddSource(run_loop(), scoped_fd_source, kCFRunLoopCommonModes);
-
- // Transfer ownership of scoped_fdref and fd_source to controller.
- controller->Init(scoped_fdref.release(), callback_types,
- scoped_fd_source.release(), persistent);
- } else {
- // It's illegal to use this function to listen on 2 separate fds with the
- // same |controller|.
- if (CFFileDescriptorGetNativeDescriptor(fdref) != fd) {
- NOTREACHED() << "FDs don't match: "
- << CFFileDescriptorGetNativeDescriptor(fdref)
- << " != " << fd;
- return false;
- }
- if (persistent != controller->is_persistent_) {
- NOTREACHED() << "persistent doesn't match";
- return false;
- }
-
- // Combine old/new event masks.
- CFFileDescriptorDisableCallBacks(fdref, controller->callback_types_);
- controller->callback_types_ |= callback_types;
- CFFileDescriptorEnableCallBacks(fdref, controller->callback_types_);
- }
-
- controller->set_watcher(delegate);
- controller->set_pump(weak_factory_.GetWeakPtr());
-
- return true;
-}
-
-void MessagePumpIOSForIO::RemoveRunLoopSource(CFRunLoopSourceRef source) {
- CFRunLoopRemoveSource(run_loop(), source, kCFRunLoopCommonModes);
-}
-
-// static
-void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref,
- CFOptionFlags callback_types,
- void* context) {
- FdWatchController* controller = static_cast<FdWatchController*>(context);
- DCHECK_EQ(fdref, controller->fdref_.get());
-
- // Ensure that |fdref| will remain live for the duration of this function
- // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is
- // called, either of which will cause |fdref| to be released.
- ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
- fdref, base::scoped_policy::RETAIN);
-
- int fd = CFFileDescriptorGetNativeDescriptor(fdref);
- MessagePumpIOSForIO* pump = controller->pump().get();
- DCHECK(pump);
- if (callback_types & kCFFileDescriptorWriteCallBack)
- controller->OnFileCanWriteWithoutBlocking(fd, pump);
-
- // Perform the read callback only if the file descriptor has not been
- // invalidated in the write callback. As |FdWatchController| invalidates
- // its file descriptor on destruction, the file descriptor being valid also
- // guarantees that |controller| has not been deleted.
- if (callback_types & kCFFileDescriptorReadCallBack &&
- CFFileDescriptorIsValid(fdref)) {
- DCHECK_EQ(fdref, controller->fdref_.get());
- controller->OnFileCanReadWithoutBlocking(fd, pump);
- }
-
- // Re-enable callbacks after the read/write if the file descriptor is still
- // valid and the controller is persistent.
- if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) {
- DCHECK_EQ(fdref, controller->fdref_.get());
- CFFileDescriptorEnableCallBacks(fdref, callback_types);
- }
-}
-
-} // namespace base
diff --git a/base/message_loop/message_pump_io_ios.h b/base/message_loop/message_pump_io_ios.h
deleted file mode 100644
index b390544..0000000
--- a/base/message_loop/message_pump_io_ios.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2012 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 BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
-
-#include "base/base_export.h"
-#include "base/mac/scoped_cffiledescriptorref.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_pump_mac.h"
-#include "base/message_loop/watchable_io_message_pump_posix.h"
-#include "base/threading/thread_checker.h"
-
-namespace base {
-
-// This file introduces a class to monitor sockets and issue callbacks when
-// sockets are ready for I/O on iOS.
-class BASE_EXPORT MessagePumpIOSForIO : public MessagePumpNSRunLoop,
- public WatchableIOMessagePumpPosix {
- public:
- class FdWatchController : public FdWatchControllerInterface {
- public:
- explicit FdWatchController(const Location& from_here);
-
- // Implicitly calls StopWatchingFileDescriptor.
- ~FdWatchController() override;
-
- // FdWatchControllerInterface:
- bool StopWatchingFileDescriptor() override;
-
- private:
- friend class MessagePumpIOSForIO;
- friend class MessagePumpIOSForIOTest;
-
- // Called by MessagePumpIOSForIO, ownership of |fdref| and |fd_source|
- // is transferred to this object.
- void Init(CFFileDescriptorRef fdref,
- CFOptionFlags callback_types,
- CFRunLoopSourceRef fd_source,
- bool is_persistent);
-
- void set_pump(base::WeakPtr<MessagePumpIOSForIO> pump) { pump_ = pump; }
- const base::WeakPtr<MessagePumpIOSForIO>& pump() const { return pump_; }
-
- void set_watcher(FdWatcher* watcher) { watcher_ = watcher; }
-
- void OnFileCanReadWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
- void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
-
- bool is_persistent_ = false; // false if this event is one-shot.
- base::mac::ScopedCFFileDescriptorRef fdref_;
- CFOptionFlags callback_types_ = 0;
- base::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_;
- base::WeakPtr<MessagePumpIOSForIO> pump_;
- FdWatcher* watcher_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(FdWatchController);
- };
-
- MessagePumpIOSForIO();
- ~MessagePumpIOSForIO() override;
-
- bool WatchFileDescriptor(int fd,
- bool persistent,
- int mode,
- FdWatchController* controller,
- FdWatcher* delegate);
-
- void RemoveRunLoopSource(CFRunLoopSourceRef source);
-
- private:
- friend class MessagePumpIOSForIOTest;
-
- static void HandleFdIOEvent(CFFileDescriptorRef fdref,
- CFOptionFlags callback_types,
- void* context);
-
- ThreadChecker watch_file_descriptor_caller_checker_;
-
- base::WeakPtrFactory<MessagePumpIOSForIO> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(MessagePumpIOSForIO);
-};
-
-} // namespace base
-
-#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_IO_IOS_H_
diff --git a/base/native_library_ios.mm b/base/native_library_ios.mm
deleted file mode 100644
index dbcafb4..0000000
--- a/base/native_library_ios.mm
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2015 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.
-
-#include "base/native_library.h"
-
-#include "base/logging.h"
-
-#include "base/strings/string_util.h"
-
-namespace base {
-
-std::string NativeLibraryLoadError::ToString() const {
- return message;
-}
-
-NativeLibrary LoadNativeLibraryWithOptions(const base::FilePath& library_path,
- const NativeLibraryOptions& options,
- NativeLibraryLoadError* error) {
- NOTIMPLEMENTED();
- if (error)
- error->message = "Not implemented.";
- return nullptr;
-}
-
-void UnloadNativeLibrary(NativeLibrary library) {
- NOTIMPLEMENTED();
- DCHECK(!library);
-}
-
-void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- StringPiece name) {
- NOTIMPLEMENTED();
- return nullptr;
-}
-
-std::string GetNativeLibraryName(StringPiece name) {
- DCHECK(IsStringASCII(name));
- return name.as_string();
-}
-
-std::string GetLoadableModuleName(StringPiece name) {
- return GetNativeLibraryName(name);
-}
-
-} // namespace base
diff --git a/base/power_monitor/power_monitor_device_source_ios.mm b/base/power_monitor/power_monitor_device_source_ios.mm
deleted file mode 100644
index 3e86b2e..0000000
--- a/base/power_monitor/power_monitor_device_source_ios.mm
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/power_monitor/power_monitor_device_source.h"
-
-#import <UIKit/UIKit.h>
-
-namespace base {
-
-bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() {
- NOTIMPLEMENTED();
- return false;
-}
-
-void PowerMonitorDeviceSource::PlatformInit() {
- NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- id foreground =
- [nc addObserverForName:UIApplicationWillEnterForegroundNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification* notification) {
- ProcessPowerEvent(RESUME_EVENT);
- }];
- id background =
- [nc addObserverForName:UIApplicationDidEnterBackgroundNotification
- object:nil
- queue:nil
- usingBlock:^(NSNotification* notification) {
- ProcessPowerEvent(SUSPEND_EVENT);
- }];
- notification_observers_.push_back(foreground);
- notification_observers_.push_back(background);
-}
-
-void PowerMonitorDeviceSource::PlatformDestroy() {
- NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- for (std::vector<id>::iterator it = notification_observers_.begin();
- it != notification_observers_.end(); ++it) {
- [nc removeObserver:*it];
- }
- notification_observers_.clear();
-}
-
-} // namespace base
diff --git a/base/process/launch_ios.cc b/base/process/launch_ios.cc
deleted file mode 100644
index 3c700f8..0000000
--- a/base/process/launch_ios.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/process/launch.h"
-
-namespace base {
-
-void RaiseProcessToHighPriority() {
- // Impossible on iOS. Do nothing.
-}
-
-} // namespace base
diff --git a/base/process/process_metrics_ios.cc b/base/process/process_metrics_ios.cc
deleted file mode 100644
index 83fc3d6..0000000
--- a/base/process/process_metrics_ios.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright (c) 2013 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.
-
-#include "base/process/process_metrics.h"
-
-#include <limits.h>
-#include <mach/task.h>
-#include <stddef.h>
-
-#include "base/logging.h"
-#include "base/mac/scoped_mach_port.h"
-#include "base/memory/ptr_util.h"
-#include "base/numerics/safe_conversions.h"
-
-namespace base {
-
-ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
-
-ProcessMetrics::~ProcessMetrics() {}
-
-// static
-std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
- ProcessHandle process) {
- return WrapUnique(new ProcessMetrics(process));
-}
-
-TimeDelta ProcessMetrics::GetCumulativeCPUUsage() {
- NOTIMPLEMENTED();
- return TimeDelta();
-}
-
-size_t GetMaxFds() {
- static const rlim_t kSystemDefaultMaxFds = 256;
- rlim_t max_fds;
- struct rlimit nofile;
- if (getrlimit(RLIMIT_NOFILE, &nofile)) {
- // Error case: Take a best guess.
- max_fds = kSystemDefaultMaxFds;
- } else {
- max_fds = nofile.rlim_cur;
- }
-
- if (max_fds > INT_MAX)
- max_fds = INT_MAX;
-
- return static_cast<size_t>(max_fds);
-}
-
-void IncreaseFdLimitTo(unsigned int max_descriptors) {
- // Unimplemented.
-}
-
-size_t GetPageSize() {
- return getpagesize();
-}
-
-// Bytes committed by the system.
-size_t GetSystemCommitCharge() {
- NOTIMPLEMENTED();
- return 0;
-}
-
-bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
- struct host_basic_info hostinfo;
- mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
- base::mac::ScopedMachSendRight host(mach_host_self());
- int result = host_info(host.get(), HOST_BASIC_INFO,
- reinterpret_cast<host_info_t>(&hostinfo), &count);
- if (result != KERN_SUCCESS)
- return false;
-
- DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
- meminfo->total = static_cast<int>(hostinfo.max_mem / 1024);
-
- vm_statistics64_data_t vm_info;
- count = HOST_VM_INFO64_COUNT;
-
- if (host_statistics64(host.get(), HOST_VM_INFO64,
- reinterpret_cast<host_info64_t>(&vm_info),
- &count) != KERN_SUCCESS) {
- return false;
- }
- DCHECK_EQ(HOST_VM_INFO64_COUNT, count);
-
- // Check that PAGE_SIZE is divisible by 1024 (2^10).
- CHECK_EQ(PAGE_SIZE, (PAGE_SIZE >> 10) << 10);
- meminfo->free = saturated_cast<int>(
- PAGE_SIZE / 1024 * (vm_info.free_count - vm_info.speculative_count));
- meminfo->speculative =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.speculative_count);
- meminfo->file_backed =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.external_page_count);
- meminfo->purgeable =
- saturated_cast<int>(PAGE_SIZE / 1024 * vm_info.purgeable_count);
-
- return true;
-}
-
-} // namespace base
diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm
deleted file mode 100644
index 60a7531..0000000
--- a/base/sys_info_ios.mm
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/sys_info.h"
-
-#include <mach/mach.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <sys/sysctl.h>
-#include <sys/types.h>
-#import <UIKit/UIKit.h>
-
-#include "base/logging.h"
-#include "base/mac/scoped_mach_port.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/macros.h"
-#include "base/process/process_metrics.h"
-#include "base/strings/sys_string_conversions.h"
-
-namespace base {
-
-namespace {
-
-// Queries sysctlbyname() for the given key and returns the value from the
-// system or the empty string on failure.
-std::string GetSysctlValue(const char* key_name) {
- char value[256];
- size_t len = arraysize(value);
- if (sysctlbyname(key_name, &value, &len, nullptr, 0) == 0) {
- DCHECK_GE(len, 1u);
- DCHECK_EQ('\0', value[len - 1]);
- return std::string(value, len - 1);
- }
- return std::string();
-}
-
-} // namespace
-
-// static
-std::string SysInfo::OperatingSystemName() {
- static dispatch_once_t get_system_name_once;
- static std::string* system_name;
- dispatch_once(&get_system_name_once, ^{
- base::mac::ScopedNSAutoreleasePool pool;
- system_name = new std::string(
- SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
- });
- // Examples of returned value: 'iPhone OS' on iPad 5.1.1
- // and iPhone 5.1.1.
- return *system_name;
-}
-
-// static
-std::string SysInfo::OperatingSystemVersion() {
- static dispatch_once_t get_system_version_once;
- static std::string* system_version;
- dispatch_once(&get_system_version_once, ^{
- base::mac::ScopedNSAutoreleasePool pool;
- system_version = new std::string(
- SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
- });
- return *system_version;
-}
-
-// static
-void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
- int32_t* minor_version,
- int32_t* bugfix_version) {
- base::mac::ScopedNSAutoreleasePool pool;
- std::string system_version = OperatingSystemVersion();
- if (!system_version.empty()) {
- // Try to parse out the version numbers from the string.
- int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
- minor_version, bugfix_version);
- if (num_read < 1)
- *major_version = 0;
- if (num_read < 2)
- *minor_version = 0;
- if (num_read < 3)
- *bugfix_version = 0;
- }
-}
-
-// static
-int64_t SysInfo::AmountOfPhysicalMemoryImpl() {
- struct host_basic_info hostinfo;
- mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
- base::mac::ScopedMachSendRight host(mach_host_self());
- int result = host_info(host.get(),
- HOST_BASIC_INFO,
- reinterpret_cast<host_info_t>(&hostinfo),
- &count);
- if (result != KERN_SUCCESS) {
- NOTREACHED();
- return 0;
- }
- DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
- return static_cast<int64_t>(hostinfo.max_mem);
-}
-
-// static
-int64_t SysInfo::AmountOfAvailablePhysicalMemoryImpl() {
- SystemMemoryInfoKB info;
- if (!GetSystemMemoryInfo(&info))
- return 0;
- // We should add inactive file-backed memory also but there is no such
- // information from iOS unfortunately.
- return static_cast<int64_t>(info.free + info.speculative) * 1024;
-}
-
-// static
-std::string SysInfo::CPUModelName() {
- return GetSysctlValue("machdep.cpu.brand_string");
-}
-
-// static
-std::string SysInfo::HardwareModelName() {
-#if TARGET_OS_SIMULATOR
- // On the simulator, "hw.machine" returns "i386" or "x86_64" which doesn't
- // match the expected format, so supply a fake string here.
- return "Simulator1,1";
-#else
- // Note: This uses "hw.machine" instead of "hw.model" like the Mac code,
- // because "hw.model" doesn't always return the right string on some devices.
- return GetSysctlValue("hw.machine");
-#endif
-}
-
-} // namespace base
diff --git a/base/test/ios/OWNERS b/base/test/ios/OWNERS
deleted file mode 100644
index 40a68c7..0000000
--- a/base/test/ios/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-rohitrao@chromium.org
diff --git a/base/test/ios/wait_util.h b/base/test/ios/wait_util.h
deleted file mode 100644
index e0c4c27..0000000
--- a/base/test/ios/wait_util.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2014 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 BASE_TEST_IOS_WAIT_UTIL_H_
-#define BASE_TEST_IOS_WAIT_UTIL_H_
-
-#include "base/ios/block_types.h"
-#include "base/time/time.h"
-
-namespace base {
-namespace test {
-namespace ios {
-
-// Runs |action| if non-nil. Then, until either |condition| is true or |timeout|
-// expires, repetitively runs the current NSRunLoop and the current MessageLoop
-// (if |run_message_loop| is true). |condition| may be nil if there is no
-// condition to wait for; the NSRunLoop and current MessageLoop will be run run
-// until |timeout| expires. DCHECKs if |condition| is non-nil and |timeout|
-// expires before |condition| becomes true. If |timeout| is zero, a reasonable
-// default is used. Returns the time spent in the function.
-// DEPRECATED - Do not use in new code. http://crbug.com/784735
-TimeDelta TimeUntilCondition(ProceduralBlock action,
- ConditionBlock condition,
- bool run_message_loop,
- TimeDelta timeout);
-
-// Same as TimeUntilCondition, but doesn't run an action.
-// DEPRECATED - Do not use in new code. http://crbug.com/784735
-void WaitUntilCondition(ConditionBlock condition,
- bool run_message_loop,
- TimeDelta timeout);
-// DEPRECATED - Do not use in new code. http://crbug.com/784735
-void WaitUntilCondition(ConditionBlock condition);
-
-// Lets the run loop of the current thread process other messages
-// within the given maximum delay. This method may return before max_delay
-// elapsed.
-void SpinRunLoopWithMaxDelay(TimeDelta max_delay);
-
-// Lets the run loop of the current thread process other messages
-// within the given minimum delay. This method returns after |min_delay|
-// elapsed.
-void SpinRunLoopWithMinDelay(TimeDelta min_delay);
-
-} // namespace ios
-} // namespace test
-} // namespace base
-
-#endif // BASE_TEST_IOS_WAIT_UTIL_H_
diff --git a/base/test/ios/wait_util.mm b/base/test/ios/wait_util.mm
deleted file mode 100644
index 39a4115..0000000
--- a/base/test/ios/wait_util.mm
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 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 "base/test/ios/wait_util.h"
-
-#import <Foundation/Foundation.h>
-
-#include "base/logging.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/run_loop.h"
-#include "base/test/test_timeouts.h"
-#include "base/timer/elapsed_timer.h"
-
-namespace base {
-namespace test {
-namespace ios {
-
-TimeDelta TimeUntilCondition(ProceduralBlock action,
- ConditionBlock condition,
- bool run_message_loop,
- TimeDelta timeout) {
- ElapsedTimer timer;
- if (action)
- action();
- if (timeout.is_zero())
- timeout = TestTimeouts::action_timeout();
- const TimeDelta spin_delay(TimeDelta::FromMilliseconds(10));
- bool condition_evaluation_result = false;
- while (timer.Elapsed() < timeout &&
- (!condition || !(condition_evaluation_result = condition()))) {
- SpinRunLoopWithMaxDelay(spin_delay);
- if (run_message_loop)
- RunLoop().RunUntilIdle();
- }
- const TimeDelta elapsed = timer.Elapsed();
- // If DCHECK is ever hit, check if |action| is doing something that is
- // taking an unreasonably long time, or if |condition| does not come
- // true quickly enough. Increase |timeout| only if necessary.
- DCHECK(!condition || condition_evaluation_result);
- return elapsed;
-}
-
-void WaitUntilCondition(ConditionBlock condition,
- bool run_message_loop,
- TimeDelta timeout) {
- TimeUntilCondition(nil, condition, run_message_loop, timeout);
-}
-
-void WaitUntilCondition(ConditionBlock condition) {
- WaitUntilCondition(condition, false, TimeDelta());
-}
-
-void SpinRunLoopWithMaxDelay(TimeDelta max_delay) {
- scoped_nsobject<NSDate> beforeDate(
- [[NSDate alloc] initWithTimeIntervalSinceNow:max_delay.InSecondsF()]);
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
- beforeDate:beforeDate];
-}
-
-void SpinRunLoopWithMinDelay(TimeDelta min_delay) {
- ElapsedTimer timer;
- while (timer.Elapsed() < min_delay) {
- SpinRunLoopWithMaxDelay(TimeDelta::FromMilliseconds(10));
- }
-}
-
-} // namespace ios
-} // namespace test
-} // namespace base
diff --git a/base/test/launcher/unit_test_launcher_ios.cc b/base/test/launcher/unit_test_launcher_ios.cc
deleted file mode 100644
index 0bb31f7..0000000
--- a/base/test/launcher/unit_test_launcher_ios.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/test/launcher/unit_test_launcher.h"
-
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/logging.h"
-#include "base/mac/foundation_util.h"
-#include "base/test/gtest_util.h"
-#include "base/test/test_switches.h"
-
-namespace base {
-
-int LaunchUnitTests(int argc,
- char** argv,
- RunTestSuiteCallback run_test_suite) {
- CHECK(CommandLine::InitializedForCurrentProcess() ||
- CommandLine::Init(argc, argv));
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kTestLauncherListTests)) {
- FilePath list_path(command_line->GetSwitchValuePath(
- switches::kTestLauncherListTests));
- if (WriteCompiledInTestsToFile(list_path)) {
- return 0;
- } else {
- LOG(ERROR) << "Failed to write list of tests.";
- return 1;
- }
- } else if (command_line->HasSwitch(
- switches::kTestLauncherPrintWritablePath)) {
- fprintf(stdout, "%s", mac::GetUserLibraryPath().value().c_str());
- fflush(stdout);
- return 0;
- }
-
- return std::move(run_test_suite).Run();
-}
-
-} // namespace base
diff --git a/base/test/test_listener_ios.h b/base/test/test_listener_ios.h
deleted file mode 100644
index c312250..0000000
--- a/base/test/test_listener_ios.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2012 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 BASE_TEST_TEST_LISTENER_IOS_H_
-#define BASE_TEST_TEST_LISTENER_IOS_H_
-
-namespace base {
-namespace test_listener_ios {
-
-// Register an IOSRunLoopListener.
-void RegisterTestEndListener();
-
-} // namespace test_listener_ios
-} // namespace base
-
-#endif // BASE_TEST_TEST_LISTENER_IOS_H_
diff --git a/base/test/test_listener_ios.mm b/base/test/test_listener_ios.mm
deleted file mode 100644
index 12cf5bb..0000000
--- a/base/test/test_listener_ios.mm
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/test/test_listener_ios.h"
-
-#import <Foundation/Foundation.h>
-
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-// The iOS watchdog timer will kill an app that doesn't spin the main event
-// loop often enough. This uses a Gtest TestEventListener to spin the current
-// loop after each test finishes. However, if any individual test takes too
-// long, it is still possible that the app will get killed.
-
-namespace {
-
-class IOSRunLoopListener : public testing::EmptyTestEventListener {
- public:
- virtual void OnTestEnd(const testing::TestInfo& test_info);
-};
-
-void IOSRunLoopListener::OnTestEnd(const testing::TestInfo& test_info) {
- base::mac::ScopedNSAutoreleasePool scoped_pool;
-
- // At the end of the test, spin the default loop for a moment.
- NSDate* stop_date = [NSDate dateWithTimeIntervalSinceNow:0.001];
- [[NSRunLoop currentRunLoop] runUntilDate:stop_date];
-}
-
-} // namespace
-
-
-namespace base {
-namespace test_listener_ios {
-
-void RegisterTestEndListener() {
- testing::TestEventListeners& listeners =
- testing::UnitTest::GetInstance()->listeners();
- listeners.Append(new IOSRunLoopListener);
-}
-
-} // namespace test_listener_ios
-} // namespace base
diff --git a/base/test/test_support_ios.h b/base/test/test_support_ios.h
deleted file mode 100644
index c71cf0d..0000000
--- a/base/test/test_support_ios.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2012 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 BASE_TEST_TEST_SUPPORT_IOS_H_
-#define BASE_TEST_TEST_SUPPORT_IOS_H_
-
-#include "base/test/test_suite.h"
-
-namespace base {
-
-// Inits the message loop for tests on iOS.
-void InitIOSTestMessageLoop();
-
-// Inits the run hook for tests on iOS.
-void InitIOSRunHook(TestSuite* suite, int argc, char* argv[]);
-
-// Launches an iOS app that runs the tests in the suite passed to
-// InitIOSRunHook.
-void RunTestsFromIOSApp();
-
-} // namespace base
-
-#endif // BASE_TEST_TEST_SUPPORT_IOS_H_
diff --git a/base/test/test_support_ios.mm b/base/test/test_support_ios.mm
deleted file mode 100644
index 03c7631..0000000
--- a/base/test/test_support_ios.mm
+++ /dev/null
@@ -1,219 +0,0 @@
-// Copyright (c) 2012 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 <UIKit/UIKit.h>
-
-#include "base/debug/debugger.h"
-#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_pump_default.h"
-#include "base/test/test_suite.h"
-#include "testing/coverage_util_ios.h"
-
-// Springboard will kill any iOS app that fails to check in after launch within
-// a given time. Starting a UIApplication before invoking TestSuite::Run
-// prevents this from happening.
-
-// InitIOSRunHook saves the TestSuite and argc/argv, then invoking
-// RunTestsFromIOSApp calls UIApplicationMain(), providing an application
-// delegate class: ChromeUnitTestDelegate. The delegate implements
-// application:didFinishLaunchingWithOptions: to invoke the TestSuite's Run
-// method.
-
-// Since the executable isn't likely to be a real iOS UI, the delegate puts up a
-// window displaying the app name. If a bunch of apps using MainHook are being
-// run in a row, this provides an indication of which one is currently running.
-
-static base::TestSuite* g_test_suite = NULL;
-static int g_argc;
-static char** g_argv;
-
-@interface UIApplication (Testing)
-- (void)_terminateWithStatus:(int)status;
-@end
-
-#if TARGET_IPHONE_SIMULATOR
-// Xcode 6 introduced behavior in the iOS Simulator where the software
-// keyboard does not appear if a hardware keyboard is connected. The following
-// declaration allows this behavior to be overriden when the app starts up.
-@interface UIKeyboardImpl
-+ (instancetype)sharedInstance;
-- (void)setAutomaticMinimizationEnabled:(BOOL)enabled;
-- (void)setSoftwareKeyboardShownByTouch:(BOOL)enabled;
-@end
-#endif // TARGET_IPHONE_SIMULATOR
-
-@interface ChromeUnitTestDelegate : NSObject {
- base::scoped_nsobject<UIWindow> _window;
-}
-- (void)runTests;
-@end
-
-@implementation ChromeUnitTestDelegate
-
-- (BOOL)application:(UIApplication *)application
- didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
-#if TARGET_IPHONE_SIMULATOR
- // Xcode 6 introduced behavior in the iOS Simulator where the software
- // keyboard does not appear if a hardware keyboard is connected. The following
- // calls override this behavior by ensuring that the software keyboard is
- // always shown.
- [[UIKeyboardImpl sharedInstance] setAutomaticMinimizationEnabled:NO];
- [[UIKeyboardImpl sharedInstance] setSoftwareKeyboardShownByTouch:YES];
-#endif // TARGET_IPHONE_SIMULATOR
-
- CGRect bounds = [[UIScreen mainScreen] bounds];
-
- // Yes, this is leaked, it's just to make what's running visible.
- _window.reset([[UIWindow alloc] initWithFrame:bounds]);
- [_window setBackgroundColor:[UIColor whiteColor]];
- [_window makeKeyAndVisible];
-
- // Add a label with the app name.
- UILabel* label = [[[UILabel alloc] initWithFrame:bounds] autorelease];
- label.text = [[NSProcessInfo processInfo] processName];
- label.textAlignment = NSTextAlignmentCenter;
- [_window addSubview:label];
-
- // An NSInternalInconsistencyException is thrown if the app doesn't have a
- // root view controller. Set an empty one here.
- [_window setRootViewController:[[[UIViewController alloc] init] autorelease]];
-
- if ([self shouldRedirectOutputToFile])
- [self redirectOutput];
-
- // Queue up the test run.
- [self performSelector:@selector(runTests)
- withObject:nil
- afterDelay:0.1];
- return YES;
-}
-
-// Returns true if the gtest output should be redirected to a file, then sent
-// to NSLog when compleete. This redirection is used because gtest only writes
-// output to stdout, but results must be written to NSLog in order to show up in
-// the device log that is retrieved from the device by the host.
-- (BOOL)shouldRedirectOutputToFile {
-#if !TARGET_IPHONE_SIMULATOR
- return !base::debug::BeingDebugged();
-#endif // TARGET_IPHONE_SIMULATOR
- return NO;
-}
-
-// Returns the path to the directory to store gtest output files.
-- (NSString*)outputPath {
- NSArray* searchPath =
- NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
- NSUserDomainMask,
- YES);
- CHECK([searchPath count] > 0) << "Failed to get the Documents folder";
- return [searchPath objectAtIndex:0];
-}
-
-// Returns the path to file that stdout is redirected to.
-- (NSString*)stdoutPath {
- return [[self outputPath] stringByAppendingPathComponent:@"stdout.log"];
-}
-
-// Returns the path to file that stderr is redirected to.
-- (NSString*)stderrPath {
- return [[self outputPath] stringByAppendingPathComponent:@"stderr.log"];
-}
-
-// Redirects stdout and stderr to files in the Documents folder in the app's
-// sandbox.
-- (void)redirectOutput {
- freopen([[self stdoutPath] UTF8String], "w+", stdout);
- freopen([[self stderrPath] UTF8String], "w+", stderr);
-}
-
-// Reads the redirected gtest output from a file and writes it to NSLog.
-- (void)writeOutputToNSLog {
- // Close the redirected stdout and stderr files so that the content written to
- // NSLog doesn't end up in these files.
- fclose(stdout);
- fclose(stderr);
- for (NSString* path in @[ [self stdoutPath], [self stderrPath]]) {
- NSString* content = [NSString stringWithContentsOfFile:path
- encoding:NSUTF8StringEncoding
- error:NULL];
- NSArray* lines = [content componentsSeparatedByCharactersInSet:
- [NSCharacterSet newlineCharacterSet]];
-
- NSLog(@"Writing contents of %@ to NSLog", path);
- for (NSString* line in lines) {
- NSLog(@"%@", line);
- }
- }
-}
-
-- (void)runTests {
- coverage_util::ConfigureCoverageReportPath();
-
- int exitStatus = g_test_suite->Run();
-
- if ([self shouldRedirectOutputToFile])
- [self writeOutputToNSLog];
-
- // If a test app is too fast, it will exit before Instruments has has a
- // a chance to initialize and no test results will be seen.
- // TODO(crbug.com/137010): Figure out how much time is actually needed, and
- // sleep only to make sure that much time has elapsed since launch.
- [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
- _window.reset();
-
- // Use the hidden selector to try and cleanly take down the app (otherwise
- // things can think the app crashed even on a zero exit status).
- UIApplication* application = [UIApplication sharedApplication];
- [application _terminateWithStatus:exitStatus];
-
- exit(exitStatus);
-}
-
-@end
-
-namespace {
-
-std::unique_ptr<base::MessagePump> CreateMessagePumpForUIForTests() {
- // A default MessagePump will do quite nicely in tests.
- return std::unique_ptr<base::MessagePump>(new base::MessagePumpDefault());
-}
-
-} // namespace
-
-namespace base {
-
-void InitIOSTestMessageLoop() {
- MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIForTests);
-}
-
-void InitIOSRunHook(TestSuite* suite, int argc, char* argv[]) {
- g_test_suite = suite;
- g_argc = argc;
- g_argv = argv;
-}
-
-void RunTestsFromIOSApp() {
- // When TestSuite::Run is invoked it calls RunTestsFromIOSApp(). On the first
- // invocation, this method fires up an iOS app via UIApplicationMain. Since
- // UIApplicationMain does not return until the app exits, control does not
- // return to the initial TestSuite::Run invocation, so the app invokes
- // TestSuite::Run a second time and since |ran_hook| is true at this point,
- // this method is a no-op and control returns to TestSuite:Run so that test
- // are executed. Once the app exits, RunTestsFromIOSApp calls exit() so that
- // control is not returned to the initial invocation of TestSuite::Run.
- static bool ran_hook = false;
- if (!ran_hook) {
- ran_hook = true;
- mac::ScopedNSAutoreleasePool pool;
- int exit_status = UIApplicationMain(g_argc, g_argv, nil,
- @"ChromeUnitTestDelegate");
- exit(exit_status);
- }
-}
-
-} // namespace base