FlutterCallbackCache.mm 1.8 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h"
6 7 8 9 10 11 12 13 14

#include "flutter/lib/ui/plugins/callback_cache.h"

@implementation FlutterCallbackInformation
@end

@implementation FlutterCallbackCache

+ (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle {
15
  auto info = flutter::DartCallbackCache::GetCallbackInformation(handle);
16 17 18 19 20 21 22 23 24 25
  if (info == nullptr) {
    return nil;
  }
  FlutterCallbackInformation* new_info = [[FlutterCallbackInformation alloc] init];
  new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()];
  new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()];
  new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()];
  return new_info;
}

26 27
+ (void)setCachePath:(NSString*)path {
  assert(path != nil);
28
  flutter::DartCallbackCache::SetCachePath([path UTF8String]);
29
  NSString* cache_path =
30
      [NSString stringWithUTF8String:flutter::DartCallbackCache::GetCachePath().c_str()];
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  // Set the "Do Not Backup" flag to ensure that the cache isn't moved off disk in
  // low-memory situations.
  if (![[NSFileManager defaultManager] fileExistsAtPath:cache_path]) {
    [[NSFileManager defaultManager] createFileAtPath:cache_path contents:nil attributes:nil];
    NSError* error = nil;
    NSURL* URL = [NSURL fileURLWithPath:cache_path];
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES]
                                  forKey:NSURLIsExcludedFromBackupKey
                                   error:&error];
    if (!success) {
      NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
  }
}

@end