User:Jminta/Account Manager Notes

From MozillaWiki
Jump to: navigation, search

Warning: These are simply random thoughts and are not any sort of prediction of what will come. Nor are they a commitment to make these kinds of changes in the near future.

The account manager currently serves several related functions:

  • Creates/Destroys nsIMsgAccount objects
  • Initializes nsIMsgAccount objects on startup
  • Provides a entry-point to the organization structure of TB's data objects.

This proposal aims to separate these three tasks, in order to make extending various parts of TB easier. Some renaming is intentional, in order to make it easier to break existing mental models about the code.

msgIDataStore

The msgIDataStore service is in charge of persisting data-objects across Thunderbird restarts. It is somewhat analogous to the session-store object in Firefox.

The msgIDataStore service initializes registered accounts on startup. While it does provide an access point to these datasources, it will generally not be used directly by front-end callers.

Note that this allows for temporary data-sources to be created and used within a TB session. This means that things like Google Reader's feed-preview will be easy to implement.

Proposed interface:

[scriptable, uuid(xxx)]
interface msgIDataStore : nsISupports {
  /**
   * Registers a data source that should be initializes at application startup
   *
   * @param contractId  the contract-id for the XPCOM object that is being
   *                    registered
   * @param source      the msgIDataSource being registered
   *
   * @returns a unique id for this datasource.  This id will be identical across
   *          restarts.
   */
  AString registerDataSource(in AString contractId, in msgIDataSource source);

  /**
   * Unregisters a datasource, so that it will no longer be created on startup
   *
   * @param id  The id returned when the data source was registered.
   */
  void unregisterDataSource(in AString id);

  /**
   * An array of all registered datasources.
   */
  void getDataSource(out PRUint32 count, [array, size_is(count), retval] out msgIDataSource aSources);
};

/**
 * All objects intending to provide data to be displayed in the main TB window
 * should implement this interface, if they wish to persist across sessions.
 */
[scriptable, uuid(xxx)]
interface msgIDataSource : nsISupports {
  /**
   * Called by the msgIDataStore on startup to initialize this object.
   *
   * @param id  the datastore's id for this object
   * @param properties  the properties this datasource stored last shutdown
   */
  void initialize(in AString id, in nsIPropertyBag properties);

  /**
   * Called when Thunderbird is shutting down.  The datasource should return a
   * property bag containing all of the information it needs to re-initialize
   * itself next startup.
   */
  nsIPropertyBag onShutdown();
};