sbFileMetadataService.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
30 #ifndef SBFILEMETADATASERVICE_H__
31 #define SBFILEMETADATASERVICE_H__
32 
33 // INCLUDES ===================================================================
34 #include <nscore.h>
35 #include <prlock.h>
36 #include <nsStringGlue.h>
37 #include <nsITimer.h>
38 #include <nsCOMPtr.h>
39 #include <nsIObserver.h>
40 #include <nsIStringBundle.h>
41 #include <nsTArray.h>
42 #include <nsAutoPtr.h>
43 
44 #include <sbIDataRemote.h>
45 #include <sbIMediacoreManager.h>
46 
47 #include "sbIFileMetadataService.h"
48 #include "sbPIFileMetadataService.h"
49 #include "sbMetadataJob.h"
50 
51 
52 // DEFINES ====================================================================
53 #define SONGBIRD_FILEMETADATASERVICE_CONTRACTID \
54 "@songbirdnest.com/Songbird/FileMetadataService;1"
55 
56 #define SONGBIRD_FILEMETADATASERVICE_CLASSNAME \
57 "Songbird File Metadata Service"
58 
59 #define SONGBIRD_FILEMETADATASERVICE_DESCRIPTION \
60 "Songbird File Metadata Service - Reads and writes media file metadata"
61 
62 // {183C63A5-8195-4294-8D41-A21FE16A0D7C}
63 #define SONGBIRD_FILEMETADATASERVICE_CID \
64 {0x183C63A5, 0x8195, 0x4294, {0x8D, 0x41, 0xA2, 0x1F, 0xE1, 0x6A, 0x0D, 0x7C}}
65 
66 
67 // CLASSES ====================================================================
68 class sbMetadataJob;
69 class sbMetadataJobItem;
73 
129  public nsIObserver
130 {
131 public:
132 
134  NS_DECL_SBIFILEMETADATASERVICE
135  NS_DECL_SBPIFILEMETADATASERVICE
136  NS_DECL_NSIOBSERVER
137 
139  virtual ~sbFileMetadataService();
140 
144  nsresult Init();
145 
146 
161  nsresult GetQueuedJobItem(PRBool aMainThreadOnly, sbMetadataJobItem** aJobItem);
162 
170  nsresult PutProcessedJobItem(sbMetadataJobItem* aJobItem);
171 
180  nsresult GetJobItemIsBlocked(sbMetadataJobItem* aJobItem,
181  PRBool* aJobItemIsBlocked);
182 
183 
184 protected:
185 
190  nsresult ProxiedRestartProcessors(PRUint16 aProcessorsToRestart);
200  nsresult ProxiedStartJob(nsIArray* aMediaItemsArray,
201  nsIStringEnumerator* aRequiredProperties,
202  sbMetadataJob::JobType aJobType,
203  sbIJobProgress** _retval);
204 
218  nsresult StartJob(nsIArray* aMediaItemsArray,
219  nsIStringEnumerator* aRequiredProperties,
220  sbMetadataJob::JobType aJobType,
221  sbIJobProgress** _retval);
222 
226  nsresult Shutdown();
227 
234  nsresult EnsureWritePermitted();
235 
241  nsresult UpdateDataRemotes(PRInt64 aJobCount);
242 
243  // Legacy dataremote used to indicate metadata status
244  nsCOMPtr<sbIDataRemote> mDataCurrentMetadataJobs;
245 
246  // Job processors
247  nsRefPtr<sbMainThreadMetadataProcessor> mMainThreadProcessor;
248  nsRefPtr<sbBackgroundThreadMetadataProcessor>
250 
251  PRBool mInitialized;
252  PRBool mRunning;
253 
254  // Timer used to call Job.OnJobProgress()
255  nsCOMPtr<nsITimer> mNotificationTimer;
256 
257  // Lock to protect mJobArray and mNextJobIndex
258  PRLock* mJobLock;
259 
260  // List of all active jobs
261  nsTArray<nsRefPtr<sbMetadataJob> > mJobArray;
262 
263  // Index into mJobArray to use with the next call to GetQueuedJobItem.
264  // Used to spread processing between all active jobs
265  PRUint32 mNextJobIndex;
266 
267  // Used to keep track of what we're processing, and
268  // blacklist files that seem to destroy the app
269  nsRefPtr<sbMetadataCrashTracker> mCrashTracker;
270 
271  // Mediacore manager;
272  nsCOMPtr<sbIMediacoreManager> mMediacoreManager;
273 };
274 
275 #endif // SBFILEMETADATASERVICE_H__
nsresult ProxiedStartJob(nsIArray *aMediaItemsArray, nsIStringEnumerator *aRequiredProperties, sbMetadataJob::JobType aJobType, sbIJobProgress **_retval)
nsresult PutProcessedJobItem(sbMetadataJobItem *aJobItem)
nsRefPtr< sbBackgroundThreadMetadataProcessor > mBackgroundThreadProcessor
nsresult StartJob(nsIArray *aMediaItemsArray, nsIStringEnumerator *aRequiredProperties, sbMetadataJob::JobType aJobType, sbIJobProgress **_retval)
Generic interface for exposing long running jobs to the UI.
nsTArray< nsRefPtr< sbMetadataJob > > mJobArray
nsCOMPtr< sbIDataRemote > mDataCurrentMetadataJobs
Private file metadata service interface for unit tests.
nsRefPtr< sbMetadataCrashTracker > mCrashTracker
A container of sbMetadataJobItems.
nsCOMPtr< sbIMediacoreManager > mMediacoreManager
nsresult GetQueuedJobItem(PRBool aMainThreadOnly, sbMetadataJobItem **aJobItem)
Manages reading and writing metadata to and from sbIMediaItem objects and media files.
NS_DECL_ISUPPORTS NS_DECL_SBIFILEMETADATASERVICE NS_DECL_SBPIFILEMETADATASERVICE NS_DECL_NSIOBSERVER sbFileMetadataService()
nsresult ProxiedRestartProcessors(PRUint16 aProcessorsToRestart)
Proxied version of RestartProcessors present on the sbIFileMetadataService interface.
nsresult GetJobItemIsBlocked(sbMetadataJobItem *aJobItem, PRBool *aJobItemIsBlocked)
nsRefPtr< sbMainThreadMetadataProcessor > mMainThreadProcessor
nsCOMPtr< nsITimer > mNotificationTimer
nsresult UpdateDataRemotes(PRInt64 aJobCount)