sbLocalDatabaseLibrary.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef __SBLOCALDATABASELIBRARY_H__
28 #define __SBLOCALDATABASELIBRARY_H__
29 
30 #include <nsIObserver.h>
31 #include <sbIDatabaseQuery.h>
32 #include <sbILibrary.h>
33 #include <sbILocalDatabaseLibrary.h>
34 #include <sbILocalDatabaseSimpleMediaList.h>
37 
38 #include <prmon.h>
39 #include <nsAutoLock.h>
40 #include <nsClassHashtable.h>
41 #include <nsDataHashtable.h>
42 #include <nsCOMArray.h>
43 #include <nsCOMPtr.h>
44 #include <nsIClassInfo.h>
45 #include <nsInterfaceHashtable.h>
46 #include <nsIRunnable.h>
47 #include <nsIStreamListener.h>
48 #include <nsITimer.h>
49 #include <nsIThread.h>
50 #include <nsIThreadPool.h>
51 #include <nsIURI.h>
52 #include <nsStringGlue.h>
53 #include <nsVoidArray.h>
54 #include <sbIMediaListFactory.h>
55 #include <sbILibraryStatistics.h>
56 
57 class nsIPropertyBag2;
58 class nsIWeakReference;
59 class nsStringHashKey;
60 class sbAutoBatchHelper;
62 class sbILibraryFactory;
69 class nsIPrefBranch;
70 class nsIURI;
71 
72 typedef nsCOMArray<sbIMediaItem> sbMediaItemArray;
73 typedef nsCOMArray<sbIMediaList> sbMediaListArray;
74 typedef nsClassHashtable<nsISupportsHashKey, sbMediaItemArray>
76 typedef nsDataHashtable<nsStringHashKey, PRUint32> sbListItemIndexMap;
77 typedef nsInterfaceHashtableMT<nsStringHashKey, nsIWeakReference>
79 
80 // These are the methods from sbLocalDatabaseMediaListBase that we're going to
81 // override in sbLocalDatabaseLibrary. Most of them are from sbIMediaList.
82 #define SB_DECL_MEDIALISTBASE_OVERRIDES \
83  NS_IMETHOD GetType(nsAString& aType); \
84  NS_IMETHOD GetItemByGuid(const nsAString& aGuid, sbIMediaItem** _retval); \
85  NS_IMETHOD Contains(sbIMediaItem* aMediaItem, PRBool* _retval); \
86  NS_IMETHOD Add(sbIMediaItem* aMediaItem); \
87  NS_IMETHOD AddItem(sbIMediaItem* aMediaItem, sbIMediaItem ** aNewMediaItem); \
88  NS_IMETHOD AddAll(sbIMediaList* aMediaList); \
89  NS_IMETHOD AddSome(nsISimpleEnumerator* aMediaItems); \
90  NS_IMETHOD AddMediaItems(nsISimpleEnumerator *aMediaItems, \
91  sbIAddMediaItemsListener *aListener, \
92  PRBool aAsync); \
93  NS_IMETHOD Remove(sbIMediaItem* aMediaItem); \
94  NS_IMETHOD RemoveByIndex(PRUint32 aIndex); \
95  NS_IMETHOD RemoveSome(nsISimpleEnumerator* aMediaItems); \
96  NS_IMETHOD Clear(); \
97  NS_IMETHOD CreateView(sbIMediaListViewState* aState, sbIMediaListView** _retval); \
98  /* nothing */
99 
100 #define SB_DECL_SBIMEDIAITEM_OVERRIDES \
101  NS_IMETHOD SetContentSrc(nsIURI* aContentSrc); \
102  /* nothing */
103 
104 #define SB_FORWARD_SBIMEDIAITEM(_to) \
105  NS_IMETHOD GetLibrary(sbILibrary * *aLibrary) { return _to GetLibrary(aLibrary); } \
106  NS_IMETHOD GetIsMutable(PRBool *aIsMutable) { return _to GetIsMutable(aIsMutable); } \
107  NS_IMETHOD GetItemController(sbIMediaItemController **aMediaItemController) { return _to GetItemController(aMediaItemController); } \
108  NS_IMETHOD GetMediaCreated(PRInt64 *aMediaCreated) { return _to GetMediaCreated(aMediaCreated); } \
109  NS_IMETHOD SetMediaCreated(PRInt64 aMediaCreated) { return _to SetMediaCreated(aMediaCreated); } \
110  NS_IMETHOD GetMediaUpdated(PRInt64 *aMediaUpdated) { return _to GetMediaUpdated(aMediaUpdated); } \
111  NS_IMETHOD SetMediaUpdated(PRInt64 aMediaUpdated) { return _to SetMediaUpdated(aMediaUpdated); } \
112  NS_IMETHOD GetContentSrc(nsIURI **aContentSrc) { return _to GetContentSrc(aContentSrc); } \
113  NS_IMETHOD GetContentLength(PRInt64 *aContentLength) { return _to GetContentLength(aContentLength); } \
114  NS_IMETHOD SetContentLength(PRInt64 aContentLength) { return _to SetContentLength(aContentLength); } \
115  NS_IMETHOD GetContentType(nsAString & aContentType) { return _to GetContentType(aContentType); } \
116  NS_IMETHOD SetContentType(const nsAString & aContentType) { return _to SetContentType(aContentType); } \
117  NS_IMETHOD TestIsURIAvailable(nsIObserver *aObserver) { return _to TestIsURIAvailable(aObserver); } \
118  NS_IMETHOD OpenInputStreamAsync(nsIStreamListener *aListener, nsISupports *aContext, nsIChannel **_retval) { return _to OpenInputStreamAsync(aListener, aContext, _retval); } \
119  NS_IMETHOD OpenInputStream(nsIInputStream **_retval) { return _to OpenInputStream(_retval); } \
120  NS_IMETHOD OpenOutputStream(nsIOutputStream **_retval) { return _to OpenOutputStream(_retval); } \
121  NS_IMETHOD ToString(nsAString & _retval) { return _to ToString(_retval); }
122 
123 #define SB_FORWARD_SBIMEDIALIST(_to) \
124  NS_IMETHOD GetName(nsAString & aName) { return _to GetName(aName); } \
125  NS_IMETHOD SetName(const nsAString & aName) { return _to SetName(aName); } \
126  NS_IMETHOD GetLength(PRUint32 *aLength) { return _to GetLength(aLength); } \
127  NS_IMETHOD GetIsEmpty(PRBool *aIsEmpty) { return _to GetIsEmpty(aIsEmpty); } \
128  NS_IMETHOD GetUserEditableContent(PRBool *aUserEditableContent) { return _to GetUserEditableContent(aUserEditableContent); } \
129  NS_IMETHOD GetItemByIndex(PRUint32 aIndex, sbIMediaItem **_retval) { return _to GetItemByIndex(aIndex, _retval); } \
130  NS_IMETHOD GetListContentType(PRUint16 *_retval) { return _to GetListContentType(_retval); } \
131  NS_IMETHOD EnumerateAllItems(sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return _to EnumerateAllItems(aEnumerationListener, aEnumerationType); } \
132  NS_IMETHOD EnumerateItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return _to EnumerateItemsByProperty(aPropertyID, aPropertyValue, aEnumerationListener, aEnumerationType); } \
133  NS_IMETHOD EnumerateItemsByProperties(sbIPropertyArray *aProperties, sbIMediaListEnumerationListener *aEnumerationListener, PRUint16 aEnumerationType) { return _to EnumerateItemsByProperties(aProperties, aEnumerationListener, aEnumerationType); } \
134  NS_IMETHOD GetItemsByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, nsIArray **_retval) { return _to GetItemsByProperty(aPropertyID, aPropertyValue, _retval); } \
135  NS_IMETHOD GetItemCountByProperty(const nsAString & aPropertyID, const nsAString & aPropertyValue, PRUint32 *_retval) { return _to GetItemCountByProperty(aPropertyID, aPropertyValue, _retval); } \
136  NS_IMETHOD GetItemsByProperties(sbIPropertyArray *aProperties, nsIArray **_retval) { return _to GetItemsByProperties(aProperties, _retval); } \
137  NS_IMETHOD IndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return _to IndexOf(aMediaItem, aStartFrom, _retval); } \
138  NS_IMETHOD LastIndexOf(sbIMediaItem *aMediaItem, PRUint32 aStartFrom, PRUint32 *_retval) { return _to LastIndexOf(aMediaItem, aStartFrom, _retval); } \
139  NS_IMETHOD AddListener(sbIMediaListListener *aListener, PRBool aOwnsWeak, PRUint32 aFlags, sbIPropertyArray *aPropertyFilter) { return _to AddListener(aListener, aOwnsWeak, aFlags, aPropertyFilter); } \
140  NS_IMETHOD RemoveListener(sbIMediaListListener *aListener) { return _to RemoveListener(aListener); } \
141  NS_IMETHOD RunInBatchMode(sbIMediaListBatchCallback *aCallback, nsISupports *aUserData) { return _to RunInBatchMode(aCallback, aUserData); } \
142  NS_IMETHOD GetDistinctValuesForProperty(const nsAString & aPropertyID, nsIStringEnumerator **_retval) { return _to GetDistinctValuesForProperty(aPropertyID, _retval); }
143 
145  public sbILibrary,
147  public nsIObserver,
148  public sbILibraryStatistics
149 {
154  friend class sbBatchCreateHelper;
155 
156  struct sbMediaListFactoryInfo {
157  sbMediaListFactoryInfo()
158  : typeID(0)
159  { }
160 
161  sbMediaListFactoryInfo(PRUint32 aTypeID, sbIMediaListFactory* aFactory)
162  : typeID(aTypeID),
163  factory(aFactory)
164  { }
165 
166  PRUint32 typeID;
167  nsCOMPtr<sbIMediaListFactory> factory;
168  };
169 
170  struct sbMediaItemInfo {
171  sbMediaItemInfo(PRPackedBool aHasListType = PR_FALSE,
172  PRPackedBool aHasAudioType = PR_FALSE,
173  PRPackedBool aHasVideoType = PR_FALSE)
174  : itemID(0),
175  hasItemID(PR_FALSE),
176  hasListType(aHasListType),
177  hasAudioType(aHasAudioType),
178  hasVideoType(aHasVideoType) {
179  }
180 
181  PRUint32 itemID;
182  nsString listType;
183  nsCOMPtr<nsIWeakReference> weakRef;
184  PRPackedBool hasItemID;
185  PRPackedBool hasListType;
186  PRPackedBool hasAudioType;
187  PRPackedBool hasVideoType;
188  };
189 
190  struct sbMediaItemPair {
191  sbMediaItemPair(sbIMediaItem *aSource,
192  sbIMediaItem *aDestination)
193  : sourceItem(aSource)
194  , destinationItem(aDestination)
195  { }
196 
197  nsCOMPtr<sbIMediaItem> sourceItem;
198  nsCOMPtr<sbIMediaItem> destinationItem;
199  };
200 
201  struct sbMediaItemUpdatedInfo {
202  sbMediaItemUpdatedInfo(sbIMediaItem *aItem,
203  sbIPropertyArray *aProperties,
204  sbGUIDToListMap *aMediaListTable)
205  : item(aItem)
206  , newProperties(aProperties)
207  , mediaListTable(aMediaListTable)
208  { }
209 
210  nsCOMPtr<sbIMediaItem> item;
211  nsCOMPtr<sbIPropertyArray> newProperties;
212  sbGUIDToListMap *mediaListTable;
213  };
214 
215  typedef nsClassHashtable<nsStringHashKey, sbMediaListFactoryInfo>
216  sbMediaListFactoryInfoTable;
217 
218  typedef nsClassHashtable<nsStringHashKey, sbMediaItemInfo>
219  sbMediaItemInfoTable;
220 
221 public:
222  NS_DECL_ISUPPORTS_INHERITED
223  NS_DECL_SBILIBRARY
224  NS_DECL_SBILOCALDATABASELIBRARY
225  NS_DECL_NSICLASSINFO
226  NS_DECL_NSIOBSERVER
227  NS_DECL_SBILIBRARYSTATISTICS
228 
229  NS_FORWARD_SBILIBRARYRESOURCE(sbLocalDatabaseMediaListBase::)
232 
233  // Include our overrides.
236 
238  ~sbLocalDatabaseLibrary();
239 
240  NS_IMETHOD GetDefaultSortProperty(nsAString& aProperty);
241 
242  nsresult Init(const nsAString& aDatabaseGuid,
243  nsIPropertyBag2* aCreationParameters,
244  sbILibraryFactory* aFactory,
245  nsIURI* aDatabaseLocation = nsnull);
246 
247  static void GetNowString(nsAString& _retval);
248 
253  nsresult RemoveSelected(nsISimpleEnumerator* aSelection,
255 
256  /*
257  * Internal methods for async operations on sbIMediaList
258  */
259  nsresult AddSomeAsyncInternal(nsISimpleEnumerator *aMediaItems,
260  sbIAddMediaItemsListener *aListener);
261 
262  nsresult GetLengthCache(sbILocalDatabaseGUIDArrayLengthCache **aLengthCache);
263 
264 private:
265  nsresult CreateQueries();
266 
267  inline nsresult MakeStandardQuery(sbIDatabaseQuery** _retval,
268  PRBool aRunAsync = PR_FALSE);
269 
270  nsresult AddNewItemQuery(sbIDatabaseQuery* aQuery,
271  const PRUint32 aMediaItemTypeID,
272  const nsAString& aURISpecOrPrefix,
273  nsAString& _retval);
274 
279  nsresult SetDefaultItemProperties(sbIMediaItem* aItem,
280  sbIPropertyArray* aProperties,
281  sbMediaItemInfo* aItemInfo);
282 
283  nsresult GetTypeForGUID(const nsAString& aGUID,
284  nsAString& _retval);
285 
286  // This callback is meant to be used with mMediaListFactoryTable.
287  // aUserData should be a nsTArray<nsString> pointer.
288  static PLDHashOperator PR_CALLBACK
289  AddTypesToArrayCallback(nsStringHashKey::KeyType aKey,
290  sbMediaListFactoryInfo* aEntry,
291  void* aUserData);
292 
293  static PLDHashOperator PR_CALLBACK
294  NotifyCopyListeners(nsISupportsHashKey::KeyType aKey,
296  void* aUserData);
297 
298  static PLDHashOperator PR_CALLBACK
299  NotifyListItemUpdated(nsStringHashKey::KeyType aKey,
300  nsCOMPtr<nsIWeakReference>& aEntry,
301  void* aUserData);
302 
303  static PLDHashOperator PR_CALLBACK
304  NotifyListsBeforeItemRemoved(nsISupportsHashKey::KeyType aKey,
305  sbMediaItemArray* aEntry,
306  void* aUserData);
307 
308  static PLDHashOperator PR_CALLBACK
309  NotifyListsAfterItemRemoved(nsISupportsHashKey::KeyType aKey,
310  sbMediaItemArray* aEntry,
311  void* aUserData);
312 
318  static PLDHashOperator PR_CALLBACK
319  NotifyListsBeforeAfterItemRemoved(nsISupportsHashKey::KeyType aKey,
320  sbMediaItemArray* aEntry,
321  void* aUserData);
322 
323  static PLDHashOperator PR_CALLBACK
324  EntriesToMediaListArray(nsISupportsHashKey* aEntry,
325  void* aUserData);
326 
327  static PLDHashOperator PR_CALLBACK
328  RemoveIfNotList(nsStringHashKey::KeyType aKey,
329  nsAutoPtr<sbMediaItemInfo> &aEntry,
330  void *aUserData);
331 
332  nsresult RegisterDefaultMediaListFactories();
333 
334  nsresult DeleteDatabaseItem(const nsAString& aGuid);
335 
336  nsresult AddItemToLocalDatabase(sbIMediaItem* aMediaItem,
337  sbIMediaItem** _retval);
338 
339  nsresult GetSimpleMediaListCopyProperties
340  (sbIMediaList* aMediaList,
341  sbIPropertyArray** aSimpleProperties);
342 
343  nsresult GetContainingLists(sbMediaItemArray* aItems,
344  sbMediaListArray* aLists,
345  sbMediaItemToListsMap* aMap);
346 
347  nsresult GetAllListsByType(const nsAString& aType, sbMediaListArray* aArray);
348 
349  nsresult ConvertURIsToStrings(nsIArray* aURIs, nsStringArray** aStringArray);
350 
351  nsresult ContainsCopy(sbIMediaItem* aMediaItem,
352  PRBool* aContainsCopy);
353 
354  nsresult FilterExistingItems(nsStringArray* aURIs,
355  nsIArray* aPropertyArrayArray,
356  nsTArray<PRUint32>* aFilteredIndexArray,
357  nsStringArray** aFilteredURIs,
358  nsIArray** aFilteredPropertyArrayArray);
359 
360  nsresult GetGuidFromContentURI(nsIURI* aURI, nsAString& aGUID);
361 
362  nsresult Shutdown();
363 
364  /* possibly create an item, and report if it was.
365  See sbILibrary::CreateMediaItem.*/
366  nsresult CreateMediaItemInternal(nsIURI* aUri,
367  sbIPropertyArray* aProperties,
368  PRBool aAllowDuplicates,
369  PRBool* aWasCreated,
370  sbIMediaItem** _retval);
371 
372  nsresult BatchCreateMediaItemsInternal(nsIArray* aURIArray,
373  nsIArray* aPropertyArrayArray,
374  PRBool aAllowDuplicates,
375  nsIArray** aMediaItemCreatedArray,
377  nsIArray** _retval);
378 
379  nsresult ClearInternal(PRBool aExcludeLists = PR_FALSE,
380  const nsAString &aContentType = EmptyString());
381 
382  /* Migration related methods */
383  nsresult NeedsMigration(PRBool *aNeedsMigration,
384  PRUint32 *aFromVersion,
385  PRUint32 *aToVersion);
386 
387  nsresult MigrateLibrary(PRUint32 aFromVersion, PRUint32 aToVersion);
388 
389  nsresult NeedsReindexCollations(PRBool *aNeedsReindexCollations);
390 
391  nsresult ReindexCollations();
392 
393 private:
394  // This is the GUID used by the DBEngine to uniquely identify the sqlite
395  // database file we'll be using. Don't confuse it with mGuid (inherited from
396  // sbLocalDatabaseMediaItem) - that one represents the GUID that uniquely
397  // identifies this "media item" in the sqlite database.
398  nsString mDatabaseGuid;
399 
400  // Location of the database file. This may be null to indicate that the file
401  // lives in the default DBEngine database store.
402  nsCOMPtr<nsIURI> mDatabaseLocation;
403 
404  // A dummy uri that holds a special 'songbird-library://' url.
405  nsCOMPtr<nsIURI> mContentSrc;
406 
407  nsCOMPtr<sbIDatabasePreparedStatement> mCreateMediaItemPreparedStatement;
408  nsCOMPtr<sbIDatabasePreparedStatement> mGetTypeForGUID;
409  nsCOMPtr<sbIDatabasePreparedStatement> mGetCountForIdentity;
410  nsCOMPtr<sbIDatabasePreparedStatement> mGetGUIDForIdentity;
411 
412  nsCOMPtr<sbILocalDatabasePropertyCache> mPropertyCache;
413 
414  nsCOMPtr<sbILocalDatabaseGUIDArrayLengthCache> mLengthCache;
415 
416  sbMediaListFactoryInfoTable mMediaListFactoryTable;
417  sbMediaItemInfoTable mMediaItemTable;
418 
419  // Weak references to media lists that have been instantiated
420  // (via CreateMediaList and GetMediaItem)
421  // Used for fast list update notifications.
422  sbGUIDToListMap mMediaListTable;
423 
424  nsCOMArray<nsITimer> mBatchCreateTimers;
425 
426  nsCOMPtr<nsIPropertyBag2> mCreationParameters;
427  nsCOMPtr<sbILibraryFactory> mFactory;
428 
429  PRUint32 mAnalyzeCountLimit;
430 
431  PRBool mPreventAddedNotification;
432 
433  // This monitor protects calls to GetMediaItem.
434  PRMonitor *mMonitor;
435 
436  // Hashtable that holds all the copy listeners.
437  nsInterfaceHashtableMT<nsISupportsHashKey,
438  sbILocalDatabaseLibraryCopyListener> mCopyListeners;
439 
440  // initialize the library statistics stuff
441  nsresult InitializeLibraryStatistics();
442  // precompiled queries for library stats
443  nsCOMPtr<sbIDatabaseQuery> mStatisticsSumQuery;
444  nsCOMPtr<sbIDatabasePreparedStatement> mStatisticsSumPreparedStatement;
445 
446  nsresult FindMusicFolderURI(nsIURI ** aMusicFolderURI);
447 
448  nsresult SubmitCopyRequest(sbIMediaItem * aSourceItem,
449  sbIMediaItem * aDestinationItem);
450 };
451 
456 {
457 public:
459  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
460 
462  sbLocalDatabaseLibrary* aLibrary,
463  sbIAddMediaItemsListener * aListener = nsnull)
464  : mFriendLibrary(aLibrary),
465  mShouldInvalidate(PR_FALSE),
466  mLength(0),
467  mListener(aListener)
468  {
469  NS_ASSERTION(mFriendLibrary, "Null pointer!");
470  }
471 
472 private:
473  sbLocalDatabaseLibrary* mFriendLibrary;
474  PRBool mShouldInvalidate;
475 
476  sbMediaItemArray mNotificationList;
477 
478  // This list is to enable copyListener notifications
479  // which must have the original item and the newly
480  // created item available for the listener.
481  sbMediaItemArray mOriginalItemList;
482 
483  PRUint32 mLength;
484 
485  nsCOMPtr<sbIAddMediaItemsListener> mListener;
486 };
487 
492 {
493 public:
495  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
496 
498  : mFriendLibrary(aLibrary),
499  mItemEnumerated(PR_FALSE)
500  {
501  NS_ASSERTION(mFriendLibrary, "Null pointer!");
502  }
503 
504 private:
505  sbLocalDatabaseLibrary* mFriendLibrary;
506  nsCOMPtr<sbIDatabaseQuery> mDBQuery;
507  nsCOMArray<sbIMediaItem> mNotificationList;
508  nsTArray<PRUint32> mNotificationIndexes;
509  PRPackedBool mItemEnumerated;
510 };
511 
512 // Forward declare
513 class sbBatchCreateHelper;
514 
516 {
518 
519 public:
521  NS_DECL_NSITIMERCALLBACK
522 
525  sbIDatabaseQuery* aQuery);
526 
527  nsresult Init();
528 
529  nsresult SetQueryCount(PRUint32 aQueryCount);
530 
531  nsresult NotifyInternal(PRBool* _retval);
532 
533  sbBatchCreateHelper* BatchHelper();
534 
535 private:
537  nsCOMPtr<sbIBatchCreateMediaItemsListener> mListener;
538  nsRefPtr<sbBatchCreateHelper> mBatchHelper;
539  nsCOMPtr<sbIDatabaseQuery> mQuery;
540  nsITimer* mTimer;
541  PRUint32 mQueryCount;
542 
543 };
544 
546 {
547 public:
548  NS_IMETHOD_(nsrefcnt) AddRef(void);
549  NS_IMETHOD_(nsrefcnt) Release(void);
550 
552  sbBatchCreateTimerCallback* aCallback = nsnull);
553 
554  nsresult InitQuery(sbIDatabaseQuery* aQuery,
555  nsStringArray* aURIArray,
556  nsIArray* aPropertyArrayArray);
557 
558  nsresult NotifyAndGetItems(nsIArray** _retval);
559 
560 protected:
561  nsAutoRefCnt mRefCnt;
562  NS_DECL_OWNINGTHREAD
563 
564 private:
565  // When this is used for an async batch, the helper will have an owning
566  // reference to the callback
568  sbBatchCreateTimerCallback* mCallback;
569  nsAutoPtr<nsStringArray> mURIArray;
570  nsCOMPtr<nsIArray> mPropertiesArray;
571  nsTArray<nsString> mGuids;
572  PRUint32 mLength;
573 };
574 
576 {
577 public:
579  : mLists(aLists)
580  {
581  NS_ASSERTION(aLists, "Null pointer!");
582  for (PRInt32 i = 0; i < mLists->Count(); i++) {
583  nsCOMPtr<sbILocalDatabaseSimpleMediaList> simple =
584  do_QueryInterface(mLists->ObjectAt(i));
585  if (simple)
586  simple->NotifyListenersBatchBegin(mLists->ObjectAt(i));
587  }
588  }
589 
591  {
592  for (PRInt32 i = 0; i < mLists->Count(); i++) {
593  nsCOMPtr<sbILocalDatabaseSimpleMediaList> simple =
594  do_QueryInterface(mLists->ObjectAt(i));
595  if (simple)
596  simple->NotifyListenersBatchEnd(mLists->ObjectAt(i));
597  }
598  }
599 
600 private:
601  // Not meant to be implemented. This makes it a compiler error to
602  // attempt to create an object on the heap.
603  static void* operator new(size_t /*size*/) CPP_THROW_NEW {return 0;}
604  static void operator delete(void* /*memory*/) { }
605 
606  sbMediaListArray* mLists;
607 };
608 
609 #endif /* __SBLOCALDATABASELIBRARY_H__ */
nsDataHashtable< nsStringHashKey, PRUint32 > sbListItemIndexMap
sbLocalDatabaseLibrary * mLibrary
#define SB_FORWARD_SBIMEDIAITEM(_to)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTENUMERATIONLISTENER sbLibraryInsertingEnumerationListener(sbLocalDatabaseLibrary *aLibrary, sbIAddMediaItemsListener *aListener=nsnull)
Interface used to enumerate the items in a media list.
nsresult RemoveSelected(nsISimpleEnumerator *aSelection, sbLocalDatabaseMediaListView *aView)
Bulk removes the selected items specified in aSelection from the view aView.
#define SB_DECL_SBIMEDIAITEM_OVERRIDES
nsClassHashtable< nsISupportsHashKey, sbMediaItemArray > sbMediaItemToListsMap
nsInterfaceHashtableMT< nsStringHashKey, nsIWeakReference > sbGUIDToListMap
Extract statistics from a media library.
NS_IMETHOD GetDefaultSortProperty(nsAString &aProperty)
Factory for new library instances.
const nsIPrefBranch
Factory for new media list instances.
#define SB_FORWARD_SBIMEDIALIST(_to)
Interface used to listen for items being copied from a library.
A brief description of the contents of this interface.
Simple class to make sure we notify listeners that a batch operation has completed every time they ar...
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
sbAutoSimpleMediaListBatchHelper(sbMediaListArray *aLists)
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTENUMERATIONLISTENER sbLibraryRemovingEnumerationListener(sbLocalDatabaseLibrary *aLibrary)
Media library abstraction.
Definition: sbILibrary.idl:82
Callback for batch media create items.
Definition: sbILibrary.idl:50
nsresult AddSomeAsyncInternal(nsISimpleEnumerator *aMediaItems, sbIAddMediaItemsListener *aListener)
nsresult GetLengthCache(sbILocalDatabaseGUIDArrayLengthCache **aLengthCache)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
An object responsible for executing SQL queries on the database.
Interface that defines a single item of media in the system.
nsCOMArray< sbIMediaList > sbMediaListArray
nsCOMArray< sbIMediaItem > sbMediaItemArray
#define SB_DECL_MEDIALISTBASE_OVERRIDES
static void GetNowString(nsAString &_retval)
Make a string of the current time in milliseconds.
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
_getSelectedPageStyle s i
readonly attribute sbILibraryFactory factory
Holds the factory that created this library.
Definition: sbILibrary.idl:102
nsITimerCallback
A prepared database statement.