<commit_before>//
//  HTTPDownloader.swift
//  KeymanEngine
//
//  Created by <NAME> on 2017-09-15.
//  Copyright © 2017 SIL International. All rights reserved.
//

import Foundation

protocol HTTPDownloadDelegate: class {
  func downloadRequestStarted(_ request: HTTPDownloadRequest)
  func downloadRequestFinished(_ request: HTTPDownloadRequest)
  func downloadRequestFailed(_ request: HTTPDownloadRequest)
  func downloadQueueFinished(_ queue: HTTPDownloader)
  func downloadQueueCancelled(_ queue: HTTPDownloader)
}

class HTTPDownloader: NSObject {
  var queue: [HTTPDownloadRequest] = []
  // TODO: Make unowned
  weak var handler: HTTPDownloadDelegate?
  var currentRequest: HTTPDownloadRequest?
  var downloadSession: URLSession!
  public var userInfo: [String: Any] = [:]

  init(_ handler: HTTPDownloadDelegate?) {
    super.init()
    self.handler = handler

    let config = URLSessionConfiguration.default
    downloadSession = URLSession(configuration: config)
  }

  func addRequest(_ request: HTTPDownloadRequest) {
    queue.append(request)
  }

  func popRequest() -> HTTPDownloadRequest? {
    if queue.isEmpty {
      return nil
    }
    return queue.remove(at: 0)
  }

  // Starts the queue.  The queue is managed via event messages in order to process them sequentially.
  func run() {
    if !queue.isEmpty {
      runRequest()
    }
  }

  // Runs the next step in the queue, if appropriate.
  func runRequest() {
    // Perhaps more of an 'if', relying on 'completed' messages to continue the loop?
    if !queue.isEmpty {<commit_msg>change(ios): Uses default .shared URLSession<commit_after>//
//  HTTPDownloader.swift
//  KeymanEngine
//
//  Created by <NAME> on 2017-09-15.
//  Copyright © 2017 SIL International. All rights reserved.
//

import Foundation

protocol HTTPDownloadDelegate: class {
  func downloadRequestStarted(_ request: HTTPDownloadRequest)
  func downloadRequestFinished(_ request: HTTPDownloadRequest)
  func downloadRequestFailed(_ request: HTTPDownloadRequest)
  func downloadQueueFinished(_ queue: HTTPDownloader)
  func downloadQueueCancelled(_ queue: HTTPDownloader)
}

class HTTPDownloader: NSObject {
  var queue: [HTTPDownloadRequest] = []
  // TODO: Make unowned
  weak var handler: HTTPDownloadDelegate?
  var currentRequest: HTTPDownloadRequest?
  var downloadSession: URLSession!
  public var userInfo: [String: Any] = [:]

  init(_ handler: HTTPDownloadDelegate?) {
    super.init()
    self.handler = handler
    downloadSession = URLSession.shared
  }

  func addRequest(_ request: HTTPDownloadRequest) {
    queue.append(request)
  }

  func popRequest() -> HTTPDownloadRequest? {
    if queue.isEmpty {
      return nil
    }
    return queue.remove(at: 0)
  }

  // Starts the queue.  The queue is managed via event messages in order to process them sequentially.
  func run() {
    if !queue.isEmpty {
      runRequest()
    }
  }

  // Runs the next step in the queue, if appropriate.
  func runRequest() {
    // Perhaps more of an 'if', relying on 'completed' messages to continue the loop?
    if !queue.isEmpty {
{'fraction_non_alphanumeric': 0.09076175040518639, 'fraction_numerical': 0.008427876823338737, 'mean_word_length': 3.689969604863222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2272697', 'n_tokens_mistral': 895, 'n_tokens_neox': 927, 'n_words': 278}