already_AddRefed<nsIPerformanceStats>
nsPerformanceSnapshot::ImportStats(JSContext* cx, const js::PerformanceData& performance, const uint64_t uid) {
  JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));

  if (!global) {
    // While it is possible for a compartment to have no global
    // (e.g. atoms), this compartment is not very interesting for us.
    return nullptr;
  }

  nsString groupId;
  GetGroupId(cx, uid, groupId);

  nsString addonId;
  GetAddonId(cx, global, addonId);

  nsString title;
  uint64_t windowId;
  GetWindowData(cx, title, &windowId);

  nsAutoString name;
  nsAutoCString cname;
  xpc::GetCurrentCompartmentName(cx, cname);
  name.Assign(NS_ConvertUTF8toUTF16(cname));

  bool isSystem = GetIsSystem(cx, global);

  nsCOMPtr<nsIPerformanceStats> result =
    new nsPerformanceStats(name, groupId, addonId, title, windowId, isSystem, performance);
  return result.forget();
}
already_AddRefed<nsIPerformanceStats>
nsPerformanceSnapshot::ImportStats(JSContext* cx, const js::PerformanceData& performance, const uint64_t uid, nsIPerformanceStats* parent) {
  if (performance.ticks == 0) {
    // Ignore compartments with no activity.
    return nullptr;
  }
  JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));

  if (!global) {
    // While it is possible for a compartment to have no global
    // (e.g. atoms), this compartment is not very interesting for us.
    return nullptr;
  }

  nsString groupId;
  GetGroupId(cx, uid, groupId);

  nsString addonId;
  GetAddonId(cx, global, addonId);

  nsString title;
  uint64_t windowId;
  GetWindowData(cx, title, &windowId);

  nsString name;
  GetName(cx, global, name);

  bool isSystem = GetIsSystem(cx, global);

  nsCOMPtr<nsIPerformanceStats> result =
    new nsPerformanceStats(name, parent, groupId, addonId, title, windowId, mProcessId, isSystem, performance);
  return result.forget();
}
Beispiel #3
0
bool FdoSmPhOdbcOwner::Add()
{
    FdoSmPhOdbcMgrP mgr = GetManager()->SmartCast<FdoSmPhOdbcMgr>();
    GdbiConnection* gdbiConn = mgr->GetGdbiConnection();

    FdoStringP sqlStmt = FdoStringP::Format(
        L"create database %ls",
        GetName()
    );

    // Create the owner (datastore)
    gdbiConn->ExecuteNonQuery( (const char*) sqlStmt );

    if ( GetHasMetaSchema() ) {
        FdoStringsP keywords = FdoStringCollection::Create();
        keywords->Add( rdbi_vndr_name(mgr->GetRdbiContext()) );
        keywords->Add( L"SQLServer" );

        // The following keywords cause the long transaction and locking
        // system properties to be added and inherited by each class table.
        if ( GetLtMode() == FdoMode )
            keywords->Add( L"FdoLt" );

        if ( GetLckMode() == FdoMode )
            keywords->Add( L"FdoLock" );

        // Switch to newly created owner and add the MetaSchema

        SetCurrent();

        try {
            AddMetaSchema( keywords, GetIsSystem());
        }
        catch ( ... ) {
            try {
                FdoSmPhOwnerP prevOwner = mgr->FindOwner();
                
                if ( prevOwner )
                    prevOwner->SetCurrent();
            }
            catch (...) {
            }
            throw;
        }

        // Switch back to default owner
        FdoSmPhOwnerP prevOwner = mgr->FindOwner();
                
        if ( prevOwner && FdoStringP(prevOwner->GetName()).GetLength() != 0)
            prevOwner->SetCurrent();

        //TODO: spatial handling?
    }
    
    return true;
}
Beispiel #4
0
bool FdoSmPhPostGisOwner::Add()
{
    FdoSmPhPostGisMgrP mgr(GetManager()->SmartCast<FdoSmPhPostGisMgr>());

    GdbiConnection* gdbiConn = NULL;
    gdbiConn = mgr->GetGdbiConnection();

    FdoStringP sqlStmt = FdoStringP::Format(
    L"CREATE DATABASE %ls TEMPLATE template_postgis_20 ENCODING 'UTF8'", static_cast<FdoString*>(GetDbName()));
    try
    {
        gdbiConn->ExecuteNonQuery(static_cast<const char*>(sqlStmt), true);
    }
    catch(...)
    {
        // On error, try old template
        sqlStmt = FdoStringP::Format(
        L"CREATE DATABASE %ls TEMPLATE template_postgis ENCODING 'UTF8'", static_cast<FdoString*>(GetDbName()));

        gdbiConn->ExecuteNonQuery(static_cast<const char*>(sqlStmt), true);
    }

    // Put datastore description into the database comments. 
    // While listing datastores, it is not easy to look into each 
    // database to find out if it has metaschema, and to extract the
    // description. Putting description in the database comments makes
    // it more readily available in this case.
    //
    // Another benefit is that descriptions, for datastores without metaschema,
    // can be persisted.

    FdoStringP description;

    // Encode whether the datastore has metaschema into the description.
    if ( GetHasMetaSchema() )
        description = FdoStringP(L"FDO Enabled: ") + GetDescription();
    else
        description = GetDescription();

    if ( description != L"" ) 
    {
        sqlStmt = FdoStringP::Format(
            L"comment on database \"%ls\" is %ls",
            GetName(),
            (FdoString*) mgr->FormatSQLVal(description, FdoSmPhColType_String)
        );
      
        gdbiConn->ExecuteNonQuery( (const char*) sqlStmt );
    }

    if (GetHasMetaSchema())
    {
        FdoStringsP keywords(FdoStringCollection::Create());
        keywords->Add(rdbi_vndr_name(mgr->GetRdbiContext()));
        keywords->Add(L"PostGIS" );

        // Switch to newly created owner and add the MetaSchema
        SetCurrent();

        try
        {
            AddMetaSchema(keywords, GetIsSystem());
        }
        catch (...)
        {
            try
            {
                // On error, switch back to default owner
                FdoSmPhOwnerP prevOwner(mgr->FindOwner());                
                if (prevOwner)
                    prevOwner->SetCurrent();
            }
            catch (...)
            {
                // Skip forward
            }
            throw;
        }
		
		if (!GetIsSystem())
        {
			SetOptions();
        }

        // Switch back to default owner
        FdoSmPhOwnerP prevOwner(mgr->FindOwner());
        if (prevOwner)
            prevOwner->SetCurrent();
    }
    
    return true;
}