<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.

#include "chrome/browser/autocomplete/autocomplete_edit.h"

#include "base/basictypes.h"
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
#include "third_party/skia/include/core/SkBitmap.h"

///////////////////////////////////////////////////////////////////////////////
// AutocompleteEditModel

// A single AutocompleteController used solely for making synchronous calls.  We
// avoid using the popup's controller here because we don't want to interrupt
// in-progress queries or modify the popup state.  We don't need a controller
// for every edit because this will always be accessed on the main thread, so we
// won't have thread-safety problems.
static AutocompleteController* synchronous_controller = NULL;
static int synchronous_controller_refcount = 0;

AutocompleteEditModel::AutocompleteEditModel(
    AutocompleteEditView* view,
    AutocompleteEditController* controller,
    Profile* profile)
    : view_(view),
      controller_(controller),
      has_focus_(false),
      user_input_in_progress_(false),
      just_deleted_text_(false),
      has_temporary_text_(false),
      paste_state_(NONE),
      control_key_state_(UP),
      is_keyword_hint_(false),
      keyword_ui_state_(NORMAL),
      show_search_hint_(true),
      profile_(profile) {
  if (++synchronous_controller_refcount == 1) {
    // We don't have a controller yet, so create one.  No profile is set since
    // we'll set this before each call to the controller.
    synchronous_controller = new AutocompleteController(NULL);
  }
}

AutocompleteEditModel::~AutocompleteEditModel() {
  if (--synchronous_controller_refcount == 0)
    delete synchronous_controller;
}

void AutocompleteEditModel::SetPopupModel(AutocompletePopupModel* popup_model) {
  popup_ = popup_model;
  registrar_.Add(this,
      NotificationType::AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED,
      Source<AutocompleteController>(popup_->autocomplete_controller()));
}

void AutocompleteEditModel::SetProfile(Profile* profile) {
  DCHECK(profile);
  profile_ = profile;
  popup_->SetProfile(profile);
}

const AutocompleteEditModel::State
    AutocompleteEditModel::GetStateForTabSwitch() {
  // Like typing, switching tabs "accepts" the temporary text as the user
  // text, because it makes little sense to have temporary text when the<commit_msg>Coverity: Initialize the remaining members of AutocompleteEditModel.<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.

#include "chrome/browser/autocomplete/autocomplete_edit.h"

#include <string>

#include "base/basictypes.h"
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
#include "third_party/skia/include/core/SkBitmap.h"

///////////////////////////////////////////////////////////////////////////////
// AutocompleteEditModel

// A single AutocompleteController used solely for making synchronous calls.  We
// avoid using the popup's controller here because we don't want to interrupt
// in-progress queries or modify the popup state.  We don't need a controller
// for every edit because this will always be accessed on the main thread, so we
// won't have thread-safety problems.
static AutocompleteController* synchronous_controller = NULL;
static int synchronous_controller_refcount = 0;

AutocompleteEditModel::AutocompleteEditModel(
    AutocompleteEditView* view,
    AutocompleteEditController* controller,
    Profile* profile)
    : view_(view),
      popup_(NULL),
      controller_(controller),
      has_focus_(false),
      user_input_in_progress_(false),
      just_deleted_text_(false),
      has_temporary_text_(false),
      original_keyword_ui_state_(NORMAL),
      paste_state_(NONE),
      control_key_state_(UP),
      is_keyword_hint_(false),
      keyword_ui_state_(NORMAL),
      show_search_hint_(true),
      paste_and_go_transition_(PageTransition::TYPED),
      profile_(profile) {
  if (++synchronous_controller_refcount == 1) {
    // We don't have a controller yet, so create one.  No profile is set since
    // we'll set this before each call to the controller.
    synchronous_controller = new AutocompleteController(NULL);
  }
}

AutocompleteEditModel::~AutocompleteEditModel() {
  if (--synchronous_controller_refcount == 0)
    delete synchronous_controller;
}

void AutocompleteEditModel::SetPopupModel(AutocompletePopupModel* popup_model) {
  popup_ = popup_model;
  registrar_.Add(this,
      NotificationType::AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED,
      Source<AutocompleteController>(popup_->autocomplete_controller()));
}

void AutocompleteEditModel::SetProfile(Profile* profile) {
  DCHECK(profile);
  profile_ = profile;
  popup_->SetProfile(profile);
}

const AutocompleteEditModel::State
    AutocompleteEditModel::GetStateForTabSwitch() {
  // Like typing, switching tabs "accepts" the temporary text as the user
  // text, because it makes little sense to have temporary text when the
{'fraction_non_alphanumeric': 0.11785095320623917, 'fraction_numerical': 0.0034662045060658577, 'mean_word_length': 4.379661016949153, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '4884936', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1798, 'n_words': 446}