1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h" 6 7#include "flutter/lib/ui/plugins/callback_cache.h" 8 9@implementation FlutterCallbackInformation 10@end 11 12@implementation FlutterCallbackCache 13 14+ (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle { 15 auto info = flutter::DartCallbackCache::GetCallbackInformation(handle); 16 if (info == nullptr) { 17 return nil; 18 } 19 FlutterCallbackInformation* new_info = [[FlutterCallbackInformation alloc] init]; 20 new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()]; 21 new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()]; 22 new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()]; 23 return new_info; 24} 25 26+ (void)setCachePath:(NSString*)path { 27 assert(path != nil); 28 flutter::DartCallbackCache::SetCachePath([path UTF8String]); 29 NSString* cache_path = 30 [NSString stringWithUTF8String:flutter::DartCallbackCache::GetCachePath().c_str()]; 31 // Set the "Do Not Backup" flag to ensure that the cache isn't moved off disk in 32 // low-memory situations. 33 if (![[NSFileManager defaultManager] fileExistsAtPath:cache_path]) { 34 [[NSFileManager defaultManager] createFileAtPath:cache_path contents:nil attributes:nil]; 35 NSError* error = nil; 36 NSURL* URL = [NSURL fileURLWithPath:cache_path]; 37 BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES] 38 forKey:NSURLIsExcludedFromBackupKey 39 error:&error]; 40 if (!success) { 41 NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); 42 } 43 } 44} 45 46@end 47