<commit_before>// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/application/browser/linux/installed_applications_root.h"

#include <algorithm>
#include <string>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "xwalk/application/browser/application_store.h"
#include "xwalk/dbus/property_exporter.h"
#include "xwalk/dbus/xwalk_service_name.h"
#include "xwalk/application/browser/linux/installed_application_object.h"

namespace {

// D-Bus Interface implemented by the root object of installed applications.
//
// Methods:
//
//   Install(string path) -> ObjectPath
//     Will install application at "path", that should be an absolute path to
//     the package file. If installation is successful, returns the ObjectPath
//     of the InstalledApplication object that represents it.
const char kInstalledApplicationsRootDBusInterface[] =
    "org.crosswalkproject.InstalledApplicationsRoot";

const char kInstalledApplicationsRootDBusError[] =
    "org.crosswalkproject.InstalledApplicationsRoot.Error";

const dbus::ObjectPath kInstalledApplicationsRootPath("/installed");

}  // namespace

namespace xwalk {
namespace application {

// TODO(cmarcelo): Extract the ObjectManager bits into an ObjectManager<T> class
// and make InstalledApplicationsRoot a subclass of
// ObjectManager<InstalledApplicationObject>. The interface for T expects a
// PropertyExporter to be available.
InstalledApplicationsRoot::InstalledApplicationsRoot(
    scoped_refptr<dbus::Bus> bus, ApplicationService* service)
    : weak_factory_(this),
      application_service_(service),
      bus_(bus) {
  application_service_->AddObserver(this);

  root_object_ = bus_->GetExportedObject(kInstalledApplicationsRootPath);
  root_object_->ExportMethod(
      "org.freedesktop.DBus.ObjectManager", "GetManagedObjects",
      base::Bind(&InstalledApplicationsRoot::OnGetManagedObjects,
                 weak_factory_.GetWeakPtr()),
      base::Bind(&InstalledApplicationsRoot::OnExported,
                 weak_factory_.GetWeakPtr()));

  root_object_->ExportMethod(
      kInstalledApplicationsRootDBusInterface, "Install",
      base::Bind(&InstalledApplicationsRoot::OnInstall,
                 weak_factory_.GetWeakPtr()),
      base::Bind(&InstalledApplicationsRoot::OnExported,
                 weak_factory_.GetWeakPtr()));

  CreateInitialObjects();
}

InstalledApplicationsRoot::~InstalledApplicationsRoot() {
  application_service_->RemoveObserver(this);
}

void InstalledApplicationsRoot::OnApplicationInstalled(
    const std::string& app_id) {
  scoped_refptr<const Application> app(
      application_service_->GetApplicationByID(app_id));
  installed_apps_.push_back(CreateObject(app));

  // TODO(cmarcelo): Emit InterfacesAdded() signal.
}
<commit_msg>[Applications][D-Bus] Emit InterfacesAdded signal when app is installed<commit_after>// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/application/browser/linux/installed_applications_root.h"

#include <algorithm>
#include <string>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "xwalk/application/browser/application_store.h"
#include "xwalk/dbus/property_exporter.h"
#include "xwalk/dbus/xwalk_service_name.h"
#include "xwalk/application/browser/linux/installed_application_object.h"

namespace {

// D-Bus Interface implemented by the root object of installed applications.
//
// Methods:
//
//   Install(string path) -> ObjectPath
//     Will install application at "path", that should be an absolute path to
//     the package file. If installation is successful, returns the ObjectPath
//     of the InstalledApplication object that represents it.
const char kInstalledApplicationsRootDBusInterface[] =
    "org.crosswalkproject.InstalledApplicationsRoot";

const char kInstalledApplicationsRootDBusError[] =
    "org.crosswalkproject.InstalledApplicationsRoot.Error";

const char kDBusObjectManagerInterface[] = "org.freedesktop.DBus.ObjectManager";

const dbus::ObjectPath kInstalledApplicationsRootPath("/installed");

}  // namespace

namespace xwalk {
namespace application {

// TODO(cmarcelo): Extract the ObjectManager bits into an ObjectManager<T> class
// and make InstalledApplicationsRoot a subclass of
// ObjectManager<InstalledApplicationObject>. The interface for T expects a
// PropertyExporter to be available.
InstalledApplicationsRoot::InstalledApplicationsRoot(
    scoped_refptr<dbus::Bus> bus, ApplicationService* service)
    : weak_factory_(this),
      application_service_(service),
      bus_(bus) {
  application_service_->AddObserver(this);

  root_object_ = bus_->GetExportedObject(kInstalledApplicationsRootPath);
  root_object_->ExportMethod(
      kDBusObjectManagerInterface, "GetManagedObjects",
      base::Bind(&InstalledApplicationsRoot::OnGetManagedObjects,
                 weak_factory_.GetWeakPtr()),
      base::Bind(&InstalledApplicationsRoot::OnExported,
                 weak_factory_.GetWeakPtr()));

  root_object_->ExportMethod(
      kInstalledApplicationsRootDBusInterface, "Install",
      base::Bind(&InstalledApplicationsRoot::OnInstall,
                 weak_factory_.GetWeakPtr()),
      base::Bind(&InstalledApplicationsRoot::OnExported,
                 weak_factory_.GetWeakPtr()));

  CreateInitialObjects();
}

InstalledApplicationsRoot::~InstalledApplicationsRoot() {
  application_service_->RemoveObserver(this);
}

void InstalledApplicationsRoot::OnApplicationInstalled(
    const std::string& app_id) {
  scoped_refptr<const Application> app(
      application_service_->GetApplicationByID(app_id));
  InstalledApplicationObject* object = CreateObject(app);

  installed_apps_.push_back(object);

  dbus::Signal interfaces_added(kDBusObjectManagerInterface, "InterfacesAdded");
  dbus::MessageWriter writer(&interfaces_added);
  writer.AppendObjectPath(object->path());

  object->AppendAllPropertiesToWriter(&writer);

  root_object_->SendSignal(&interfaces_added);
}

{'fraction_non_alphanumeric': 0.10218048702848957, 'fraction_numerical': 0.001273277096928219, 'mean_word_length': 5.13671875, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 32, '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': '5104027', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1698, 'n_words': 374}