<commit_before>// Copyright (c) 2011 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 "ppapi/proxy/ppb_flash_net_connector_proxy.h"

#include <algorithm>

#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"

namespace pp {
namespace proxy {

std::string NetAddressToString(const PP_Flash_NetAddress& addr) {
  return std::string(addr.data, std::min(static_cast<size_t>(addr.size),
                                         sizeof(addr.data)));
}

void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) {
  addr->size = std::min(str.size(), sizeof(addr->data));
  memcpy(addr->data, str.data(), addr->size);
}

class FlashNetConnector : public PluginResource {
 public:
  FlashNetConnector(const HostResource& resource)
      : PluginResource(resource),
        callback_(PP_BlockUntilComplete()),
        local_addr_out_(NULL),
        remote_addr_out_(NULL) {
  }
  ~FlashNetConnector() {
    if (callback_.func)
      PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
  }

  // Resource overrides.<commit_msg>Don't re-enter when destroying FlashNetConnector<commit_after>// Copyright (c) 2011 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 "ppapi/proxy/ppb_flash_net_connector_proxy.h"

#include <algorithm>

#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"

namespace pp {
namespace proxy {

std::string NetAddressToString(const PP_Flash_NetAddress& addr) {
  return std::string(addr.data, std::min(static_cast<size_t>(addr.size),
                                         sizeof(addr.data)));
}

void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) {
  addr->size = std::min(str.size(), sizeof(addr->data));
  memcpy(addr->data, str.data(), addr->size);
}

class AbortCallbackTask : public Task {
 public:
  AbortCallbackTask(PP_CompletionCallback callback)
      : callback_(callback) {}

  virtual void Run() {
    PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
  }

 private:
  PP_CompletionCallback callback_;
};

class FlashNetConnector : public PluginResource {
 public:
  FlashNetConnector(const HostResource& resource)
      : PluginResource(resource),
        callback_(PP_BlockUntilComplete()),
        local_addr_out_(NULL),
        remote_addr_out_(NULL) {
  }
  ~FlashNetConnector() {
    if (callback_.func) {
      MessageLoop::current()->PostTask(FROM_HERE,
                                       new AbortCallbackTask(callback_));
    }
  }

  // Resource overrides.
{'fraction_non_alphanumeric': 0.11914893617021277, 'fraction_numerical': 0.002618657937806874, 'mean_word_length': 4.018062397372742, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5098010', 'n_tokens_mistral': 963, 'n_tokens_neox': 944, 'n_words': 196}