<commit_before>// Copyright (c) 2006-2008 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 CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__
#define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__

#include <string>
#include <vector>

#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/ipc_message.h"
#include "chrome/common/ipc_message_utils.h"
#include "chrome/test/automation/automation_handle_tracker.h"

// The purpose of this class is to act as a searializable version of
// AutocompleteMatch. The reason for this class is because we don't want to
// searialize all elements of AutocompleteMatch and we want some data from the
// autocomplete provider without the hassle of serializing it.
struct AutocompleteMatchData {
 public:
  AutocompleteMatchData() {}
  explicit AutocompleteMatchData(const AutocompleteMatch& match)
    : contents(match.contents),
      deletable(match.deletable),
      description(match.description),
      destination_url(match.destination_url),
      fill_into_edit(match.fill_into_edit),
      inline_autocomplete_offset(match.inline_autocomplete_offset),
      is_history_what_you_typed_match(match.is_history_what_you_typed_match),
      provider_name(match.provider->name()),
      relevance(match.relevance),
      starred(match.starred) {
    switch (match.type) {
      case AutocompleteMatch::URL:
        str_type = L"URL";
        break;
      case AutocompleteMatch::KEYWORD:
        str_type = L"KEYWORD";
        break;
      case AutocompleteMatch::SEARCH:
        str_type = L"SEARCH";
        break;
      case AutocompleteMatch::HISTORY_SEARCH:
        str_type = L"HISTORY";
        break;
      default:
        NOTREACHED();
    }
  }
  std::wstring contents;
  bool deletable;
  std::wstring description;
  std::wstring destination_url;
  std::wstring fill_into_edit;
  size_t inline_autocomplete_offset;
  bool is_history_what_you_typed_match;
  std::string provider_name;
  int relevance;
  bool starred;
  std::wstring str_type;
};
typedef std::vector<AutocompleteMatchData> Matches;

namespace IPC {

template <>
struct ParamTraits<AutocompleteMatchData> {
  typedef AutocompleteMatchData param_type;
  static void Write(Message* m, const param_type& p) {
    m->WriteWString(p.contents);
    m->WriteBool(p.deletable);
    m->WriteWString(p.description);
    m->WriteWString(p.destination_url);
    m->WriteWString(p.fill_into_edit);
    m->WriteSize(p.inline_autocomplete_offset);
    m->WriteBool(p.is_history_what_you_typed_match);
    m->WriteString(p.provider_name);
    m->WriteInt(p.relevance);
    m->WriteBool(p.starred);
    m->WriteWString(p.str_type);
  }

  static bool Read(const Message* m, void** iter, param_type* r) {
    return m->ReadWString(iter, &r->contents) &&
           m->ReadBool(iter, &r->deletable) &&
           m->ReadWString(iter, &r->description) &&
           m->ReadWString(iter, &r->destination_url) &&
           m->ReadWString(iter, &r->fill_into_edit) &&
           m->ReadSize(iter, &r->inline_autocomplete_offset) &&
           m->ReadBool(iter, &r->is_history_what_you_typed_match) &&
           m->ReadString(iter, &r->provider_name) &&
           m->ReadInt(iter, &r->relevance) &&
           m->ReadBool(iter, &r->starred) &&
           m->ReadWString(iter, &r->str_type);
  }

  static void Log(const param_type& p, std::wstring* l) {
    std::wstring provider_name_wide = UTF8ToWide(p.provider_name);
    l->append(StringPrintf(L"[%ls %ls %ls %ls %ls %d %ls %ls %d %ls %ls]",
        p.contents,
        p.deletable ? L"true" : L"false",
        p.description,
        p.destination_url,
        p.fill_into_edit,
        p.inline_autocomplete_offset,
        p.is_history_what_you_typed_match ? L"true" : L"false",
        provider_name_wide,
        p.relevance,
        p.starred ? L"true" : L"false",
        p.str_type));
  }
};
}  // namespace IPC

class AutocompleteEditProxy : public AutomationResourceProxy {
 public:
  AutocompleteEditProxy(AutomationMessageSender* sender,
                        AutomationHandleTracker* tracker,
                        int handle)
      : AutomationResourceProxy(tracker, sender, handle) {}
  virtual ~AutocompleteEditProxy() {}

  // All these functions return true if the autocomplete edit is valid and<commit_msg>Omnibox metrics logging patch splitout, part 4: Reorder fields of AutocompleteMatchData to correspond to the order in AutocompleteMatch.<commit_after>// Copyright (c) 2006-2008 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 CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__
#define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H__

#include <string>
#include <vector>

#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/ipc_message.h"
#include "chrome/common/ipc_message_utils.h"
#include "chrome/test/automation/automation_handle_tracker.h"

// The purpose of this class is to act as a serializable version of
// AutocompleteMatch. The reason for this class is because we don't want to
// serialize all elements of AutocompleteMatch and we want some data from the
// autocomplete provider without the hassle of serializing it.
struct AutocompleteMatchData {
 public:
  AutocompleteMatchData() {}
  explicit AutocompleteMatchData(const AutocompleteMatch& match)
    : provider_name(match.provider->name()),
      relevance(match.relevance),
      deletable(match.deletable),
      fill_into_edit(match.fill_into_edit),
      inline_autocomplete_offset(match.inline_autocomplete_offset),
      destination_url(match.destination_url),
      contents(match.contents),
      description(match.description),
      is_history_what_you_typed_match(match.is_history_what_you_typed_match),
      starred(match.starred) {
    switch (match.type) {
      case AutocompleteMatch::URL:
        type = "URL";
        break;
      case AutocompleteMatch::KEYWORD:
        type = "KEYWORD";
        break;
      case AutocompleteMatch::SEARCH:
        type = "SEARCH";
        break;
      case AutocompleteMatch::HISTORY_SEARCH:
        type = "HISTORY";
        break;
      default:
        NOTREACHED();
    }
  }

  std::string provider_name;
  int relevance;
  bool deletable;
  std::wstring fill_into_edit;
  size_t inline_autocomplete_offset;
  std::wstring destination_url;
  std::wstring contents;
  std::wstring description;
  bool is_history_what_you_typed_match;
  std::string type;
  bool starred;
};
typedef std::vector<AutocompleteMatchData> Matches;

namespace IPC {

template <>
struct ParamTraits<AutocompleteMatchData> {
  typedef AutocompleteMatchData param_type;
  static void Write(Message* m, const param_type& p) {
    m->WriteString(p.provider_name);
    m->WriteInt(p.relevance);
    m->WriteBool(p.deletable);
    m->WriteWString(p.fill_into_edit);
    m->WriteSize(p.inline_autocomplete_offset);
    m->WriteWString(p.destination_url);
    m->WriteWString(p.contents);
    m->WriteWString(p.description);
    m->WriteBool(p.is_history_what_you_typed_match);
    m->WriteString(p.type);
    m->WriteBool(p.starred);
  }

  static bool Read(const Message* m, void** iter, param_type* r) {
    return m->ReadString(iter, &r->provider_name) &&
           m->ReadInt(iter, &r->relevance) &&
           m->ReadBool(iter, &r->deletable) &&
           m->ReadWString(iter, &r->fill_into_edit) &&
           m->ReadSize(iter, &r->inline_autocomplete_offset) &&
           m->ReadWString(iter, &r->destination_url) &&
           m->ReadWString(iter, &r->contents) &&
           m->ReadWString(iter, &r->description) &&
           m->ReadBool(iter, &r->is_history_what_you_typed_match) &&
           m->ReadString(iter, &r->type) &&
           m->ReadBool(iter, &r->starred);
  }

  static void Log(const param_type& p, std::wstring* l) {
    l->append(StringPrintf(L"[%ls %d %ls %ls %d %ls %ls %ls %ls %ls %ls]",
        UTF8ToWide(p.provider_name),
        p.relevance,
        p.deletable ? L"true" : L"false",
        p.fill_into_edit,
        p.inline_autocomplete_offset,
        p.destination_url,
        p.contents,
        p.description,
        p.is_history_what_you_typed_match ? L"true" : L"false",
        UTF8ToWide(p.type),
        p.starred ? L"true" : L"false"));
  }
};
}  // namespace IPC

class AutocompleteEditProxy : public AutomationResourceProxy {
 public:
  AutocompleteEditProxy(AutomationMessageSender* sender,
                        AutomationHandleTracker* tracker,
                        int handle)
      : AutomationResourceProxy(tracker, sender, handle) {}
  virtual ~AutocompleteEditProxy() {}

  // All these functions return true if the autocomplete edit is valid and
{'fraction_non_alphanumeric': 0.11098566105904933, 'fraction_numerical': 0.002258100937111889, 'mean_word_length': 3.4964467005076143, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2883268', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2815, 'n_words': 579}