<commit_before>/*
 * Copyright (c) 2009, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 
 */

#include <locale.h>
#include <glib/gi18n.h>
#include <clutter/clutter.h>
#include <clutter/x11/clutter-x11.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <mx/mx.h>
#include <moblin-panel/mpl-panel-clutter.h>
#include <moblin-panel/mpl-panel-common.h>
#include "moblin-netbook-netpanel.h"
#include "chrome-profile-provider.h"

#include <config.h>

// chrome header
#include "app/app_paths.h"
#include "app/resource_bundle.h"
#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/i18n/icu_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_vector.h"
#include "base/string_util.h"
#include "base/command_line.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/user_data_manager.h"

static void
_client_set_size_cb (MplPanelClient *client,
                     guint           width,
                     guint           height,
                     gpointer        userdata)
{
  g_debug (G_STRLOC ": %d %d", width, height);
  clutter_actor_set_size ((ClutterActor *)userdata,
                          width,
                          height);
}

static gboolean
stage_button_press_event (ClutterStage          *stage,
                          ClutterEvent          *event,
                          MoblinNetbookNetpanel *netpanel)
{
  moblin_netbook_netpanel_button_press (netpanel);
  return TRUE;
}

static gboolean
stage_delete_event (ClutterStage *stage,
                    ClutterEvent *event,
                    gpointer* userdata)
{
  MessageLoopForUI::current()->Quit();
  return TRUE;
}


static gboolean standalone = FALSE;

static GOptionEntry entries[] = {
  {"standalone", 's', 0, G_OPTION_ARG_NONE, &standalone, "Do not embed into the mutter-moblin panel", NULL}
};

#define CHROME_EXE_PATH "/opt/google/chrome/"
#define CHROME_BUNDLE_PATH CHROME_EXE_PATH "/chrome.pak"
#define CHROME_LOCALE_PATH CHROME_EXE_PATH "/locales"

#define CHROMIUM_EXE_PATH "/usr/lib/chromium-browser/"
#define CHROMIUM_BUNDLE_PATH CHROMIUM_EXE_PATH "/chrome.pak"
#define CHROMIUM_LOCALE_PATH CHROMIUM_EXE_PATH "/locales"

int
main (int    argc,
      char **argv)
{
  MplPanelClient *client;
  ClutterActor *stage;
  MoblinNetbookNetpanel *netpanel;
  GOptionContext *context;
  std::string browser_name;
  GError *error = NULL;

  // Init chrome environment variables
  base::AtExitManager at_exit_manager;
  CommandLine::Init(argc, argv);
  CommandLine* cmd_line = CommandLine::ForCurrentProcess();

  chrome::RegisterPathProvider();
  app::RegisterPathProvider();

  if(g_file_test (CHROME_BUNDLE_PATH, G_FILE_TEST_EXISTS)
     && g_file_test (CHROME_LOCALE_PATH, G_FILE_TEST_EXISTS)) {
    FilePath bundle_path(CHROME_BUNDLE_PATH);
    FilePath locale_path(CHROME_LOCALE_PATH);
    ResourceBundle::InitSharedInstance(L"en-US", bundle_path, locale_path);
    browser_name = "google-chrome";
  }
  else if (g_file_test (CHROMIUM_BUNDLE_PATH, G_FILE_TEST_EXISTS)
     && g_file_test (CHROMIUM_LOCALE_PATH, G_FILE_TEST_EXISTS)) {
    FilePath bundle_path(CHROMIUM_BUNDLE_PATH);
    FilePath locale_path(CHROMIUM_LOCALE_PATH);
    ResourceBundle::InitSharedInstance(L"en-US", bundle_path, locale_path);
    browser_name = "chromium";
  }
  else {
    g_warning("Chrome or Chromium browser is not installed\n");
  }

  g_thread_init(NULL);
  g_type_init();

  MessageLoop main_message_loop(MessageLoop::TYPE_UI);

  scoped_ptr<BrowserProcessImpl> browser_process;
  browser_process.reset(new BrowserProcessImpl(*cmd_line));

  ChromeThread main_thread(ChromeThread::UI, MessageLoop::current());

  PrefService* local_state = browser_process->local_state();
  local_state->RegisterStringPref(prefs::kApplicationLocale, L"");

  scoped_ptr<UserDataManager> user_data_manager(UserDataManager::Create());

  // Initialize the prefs of the local state.
  browser::RegisterLocalState(local_state);
  g_browser_process->SetApplicationLocale("en-US");

  // Create the child threads.  We need to do this since ChromeThread::PostTask
  // silently deletes a posted task if the target message loop isn't created.
  browser_process->db_thread();
  browser_process->file_thread();
  browser_process->io_thread();

  // XXX: have to init chrome profile prover after thread creation
  // Init chrome profile provider
  ChromeProfileProvider::GetInstance()->Initialize(browser_name.c_str());

  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  context = g_option_context_new ("- mutter-moblin myzone panel");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, clutter_get_option_group_without_init ());
  g_option_context_add_group (context, gtk_get_option_group (FALSE));
  if (!g_option_context_parse (context, &argc, &argv, &error))
  {
    g_critical (G_STRLOC ": Error parsing option: %s", error->message);
    g_clear_error (&error);
  }

  g_option_context_free (context);

  MPL_PANEL_CLUTTER_INIT_WITH_GTK (&argc, &argv);
<commit_msg>enable process_launcher_thread for ac complete<commit_after>/*
 * Copyright (c) 2009, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 
 */

#include <locale.h>
#include <glib/gi18n.h>
#include <clutter/clutter.h>
#include <clutter/x11/clutter-x11.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <mx/mx.h>
#include <moblin-panel/mpl-panel-clutter.h>
#include <moblin-panel/mpl-panel-common.h>
#include "moblin-netbook-netpanel.h"
#include "chrome-profile-provider.h"

#include <config.h>

// chrome header
#include "app/app_paths.h"
#include "app/resource_bundle.h"
#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/i18n/icu_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_vector.h"
#include "base/string_util.h"
#include "base/command_line.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/user_data_manager.h"

static void
_client_set_size_cb (MplPanelClient *client,
                     guint           width,
                     guint           height,
                     gpointer        userdata)
{
  g_debug (G_STRLOC ": %d %d", width, height);
  clutter_actor_set_size ((ClutterActor *)userdata,
                          width,
                          height);
}

static gboolean
stage_button_press_event (ClutterStage          *stage,
                          ClutterEvent          *event,
                          MoblinNetbookNetpanel *netpanel)
{
  moblin_netbook_netpanel_button_press (netpanel);
  return TRUE;
}

static gboolean
stage_delete_event (ClutterStage *stage,
                    ClutterEvent *event,
                    gpointer* userdata)
{
  MessageLoopForUI::current()->Quit();
  return TRUE;
}


static gboolean standalone = FALSE;

static GOptionEntry entries[] = {
  {"standalone", 's', 0, G_OPTION_ARG_NONE, &standalone, "Do not embed into the mutter-moblin panel", NULL}
};

#define CHROME_EXE_PATH "/opt/google/chrome/"
#define CHROME_BUNDLE_PATH CHROME_EXE_PATH "/chrome.pak"
#define CHROME_LOCALE_PATH CHROME_EXE_PATH "/locales"

#define CHROMIUM_EXE_PATH "/usr/lib/chromium-browser/"
#define CHROMIUM_BUNDLE_PATH CHROMIUM_EXE_PATH "/chrome.pak"
#define CHROMIUM_LOCALE_PATH CHROMIUM_EXE_PATH "/locales"

int
main (int    argc,
      char **argv)
{
  MplPanelClient *client;
  ClutterActor *stage;
  MoblinNetbookNetpanel *netpanel;
  GOptionContext *context;
  std::string browser_name;
  GError *error = NULL;

  // Init chrome environment variables
  base::AtExitManager at_exit_manager;
  CommandLine::Init(argc, argv);
  CommandLine* cmd_line = CommandLine::ForCurrentProcess();

  chrome::RegisterPathProvider();
  app::RegisterPathProvider();

  if(g_file_test (CHROME_BUNDLE_PATH, G_FILE_TEST_EXISTS)
     && g_file_test (CHROME_LOCALE_PATH, G_FILE_TEST_EXISTS)) {
    FilePath bundle_path(CHROME_BUNDLE_PATH);
    FilePath locale_path(CHROME_LOCALE_PATH);
    ResourceBundle::InitSharedInstance(L"en-US", bundle_path, locale_path);
    browser_name = "google-chrome";
  }
  else if (g_file_test (CHROMIUM_BUNDLE_PATH, G_FILE_TEST_EXISTS)
     && g_file_test (CHROMIUM_LOCALE_PATH, G_FILE_TEST_EXISTS)) {
    FilePath bundle_path(CHROMIUM_BUNDLE_PATH);
    FilePath locale_path(CHROMIUM_LOCALE_PATH);
    ResourceBundle::InitSharedInstance(L"en-US", bundle_path, locale_path);
    browser_name = "chromium";
  }
  else {
    g_warning("Chrome or Chromium browser is not installed\n");
  }

  g_thread_init(NULL);
  g_type_init();

  MessageLoop main_message_loop(MessageLoop::TYPE_UI);

  scoped_ptr<BrowserProcessImpl> browser_process;
  browser_process.reset(new BrowserProcessImpl(*cmd_line));

  ChromeThread main_thread(ChromeThread::UI, MessageLoop::current());

  PrefService* local_state = browser_process->local_state();
  local_state->RegisterStringPref(prefs::kApplicationLocale, L"");

  scoped_ptr<UserDataManager> user_data_manager(UserDataManager::Create());

  // Initialize the prefs of the local state.
  browser::RegisterLocalState(local_state);
  g_browser_process->SetApplicationLocale("en-US");

  // Create the child threads.  We need to do this since ChromeThread::PostTask
  // silently deletes a posted task if the target message loop isn't created.
  browser_process->db_thread();
  browser_process->file_thread();
  browser_process->process_launcher_thread();
  browser_process->io_thread();

  // XXX: have to init chrome profile prover after thread creation
  // Init chrome profile provider
  ChromeProfileProvider::GetInstance()->Initialize(browser_name.c_str());

  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  context = g_option_context_new ("- mutter-moblin myzone panel");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, clutter_get_option_group_without_init ());
  g_option_context_add_group (context, gtk_get_option_group (FALSE));
  if (!g_option_context_parse (context, &argc, &argv, &error))
  {
    g_critical (G_STRLOC ": Error parsing option: %s", error->message);
    g_clear_error (&error);
  }

  g_option_context_free (context);

  MPL_PANEL_CLUTTER_INIT_WITH_GTK (&argc, &argv);

{'fraction_non_alphanumeric': 0.10692734733285059, 'fraction_numerical': 0.004344677769732078, 'mean_word_length': 4.454146555506801, 'pattern_counts': {'":': 4, '<': 27, '<?xml version=': 0, '>': 46, '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': '4368100', 'n_tokens_mistral': 4191, 'n_tokens_neox': 4082, 'n_words': 915}