sbPlaybackHistoryService.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 __SB_PLAYBACKHISTORYSERVICE_H__
28 #define __SB_PLAYBACKHISTORYSERVICE_H__
29 
30 #include <sbIPlaybackHistoryService.h>
31 
32 #include <nsIArray.h>
33 #include <nsIClassInfo.h>
34 #include <nsIComponentManager.h>
35 #include <nsIFile.h>
36 #include <nsIGenericFactory.h>
37 #include <nsIObserver.h>
38 #include <nsIWeakReference.h>
39 
40 #include <nsCOMPtr.h>
41 #include <nsDataHashtable.h>
42 #include <nsHashKeys.h>
43 #include <nsInterfaceHashtable.h>
44 #include <nsStringGlue.h>
45 
46 #include <prmon.h>
47 #include <prtime.h>
48 
49 #include <sbIDatabaseQuery.h>
50 #include <sbILibrary.h>
51 #include <sbIMediacoreEventListener.h>
52 #include <sbIMediaItem.h>
53 #include <sbIMediaListView.h>
54 #ifdef METRICS_ENABLED
55 #include <sbIMetrics.h>
56 #endif
57 #include <sbIPlaybackHistoryListener.h>
58 
61  public nsIObserver
62 {
63 public:
65 
67  NS_DECL_NSIOBSERVER
68  NS_DECL_SBIMEDIACOREEVENTLISTENER
69  NS_DECL_SBIPLAYBACKHISTORYSERVICE
70 
71  static NS_METHOD RegisterSelf(nsIComponentManager* aCompMgr,
72  nsIFile* aPath,
73  const char* aLoaderStr,
74  const char* aType,
75  const nsModuleComponentInfo *aInfo);
76 
77  static PLDHashOperator PR_CALLBACK AddListenersToCOMArrayCallback(
78  nsISupportsHashKey::KeyType aKey,
80  void* aUserData);
81 
82  NS_METHOD Init();
83 
84  nsresult CreateQueries();
85  nsresult CreateDefaultQuery(sbIDatabaseQuery **aQuery);
86 
87  nsresult CreateAnnotationsFromEntryId(PRInt64 aEntryId,
88  sbIPropertyArray **aAnnotations);
89 
91  PRUint32 aRow,
92  sbIPlaybackHistoryEntry **aEntry);
93 
95  nsIArray **aEntries);
96 
98 
100  sbIPlaybackHistoryEntry *aEntry);
102  sbIPlaybackHistoryEntry *aEntry);
104  sbIPlaybackHistoryEntry *aEntry);
105 
106  nsresult GetItem(const nsAString &aLibraryGuid,
107  const nsAString &aItemGuid,
108  sbIMediaItem **aItem);
109 
110  nsresult GetPropertyDBID(const nsAString &aPropertyID,
111  PRUint32 *aPropertyDBID);
112  nsresult InsertPropertyID(const nsAString &aPropertyID,
113  PRUint32 *aPropertyDBID);
114  nsresult LoadPropertyIDs();
115 
117  nsresult DoEntriesAddedCallback(nsIArray *aEntries);
118 
120  nsresult DoEntriesUpdatedCallback(nsIArray *aEntry);
121 
123  nsresult DoEntriesRemovedCallback(nsIArray *aEntry);
124 
125  nsresult DoEntriesClearedCallback();
126 
127  // playcount, last played time management.
130  nsresult VerifyDataAndCreateNewEntry();
131  nsresult ResetTrackingData();
132 
133 #ifdef METRICS_ENABLED
134  // metrics
135  nsresult UpdateMetrics();
136 #endif
137 
138 protected:
140 
141 private:
142  nsString mAddEntryQuery;
143 
144  nsString mAddAnnotationQuery;
145  nsString mInsertAnnotationQuery;
146  nsString mUpdateAnnotationQuery;
147  nsString mRemoveAnnotationQuery;
148  nsString mIsAnnotationPresentQuery;
149 
150  nsString mGetEntryCountQuery;
151 
152  nsString mGetEntryIDQuery;
153 
154  nsString mInsertPropertyIDQuery;
155 
156  nsString mGetAllEntriesQuery;
157  nsString mGetEntriesByIndexQuery;
158  nsString mGetEntriesByIndexQueryAscending;
159 
160  nsString mGetEntriesByTimestampQuery;
161  nsString mGetEntriesByTimestampQueryAscending;
162 
163  nsString mGetAnnotationsForEntryQuery;
164 
165  nsString mRemoveEntriesQuery;
166  nsString mRemoveAnnotationsQuery;
167 
168  nsString mRemoveAllEntriesQuery;
169  nsString mRemoveAllAnnotationsQuery;
170 
171  nsInterfaceHashtableMT<nsStringHashKey, sbILibrary> mLibraries;
172 
173  nsInterfaceHashtableMT<nsISupportsHashKey,
174  sbIPlaybackHistoryListener> mListeners;
175 
176  nsDataHashtableMT<nsUint32HashKey, nsString> mPropertyDBIDToID;
177  nsDataHashtableMT<nsStringHashKey, PRUint32> mPropertyIDToDBID;
178 
179  nsCOMPtr<nsIWeakReference> mMediacoreManager;
180 
181  PRMonitor* mMonitor;
182 
183  PRPackedBool mCurrentlyTracking;
184 
185  PRTime mCurrentStartTime;
186  PRTime mCurrentPauseTime;
187  PRTime mCurrentDelta;
188 
189  nsCOMPtr<sbIMediaItem> mCurrentItem;
190  nsCOMPtr<sbIMediaListView> mCurrentView;
191 
192 #ifdef METRICS_ENABLED
193  nsCOMPtr<sbIMetrics> mMetrics;
194 #endif
195 };
196 
197 #endif /* __SB_PLAYBACKHISTORYSERVICE_H__ */
nsresult UpdateCurrentViewFromEvent(sbIMediacoreEvent *aEvent)
nsresult FillAddQueryParameters(sbIDatabaseQuery *aQuery, sbIPlaybackHistoryEntry *aEntry)
_updateCookies aPath
nsresult DoEntryRemovedCallback(sbIPlaybackHistoryEntry *aEntry)
nsresult DoEntryUpdatedCallback(sbIPlaybackHistoryEntry *aEntry)
nsresult CreateAnnotationsFromEntryId(PRInt64 aEntryId, sbIPropertyArray **aAnnotations)
nsresult DoEntriesRemovedCallback(nsIArray *aEntry)
nsresult FillRemoveEntryQueryParameters(sbIDatabaseQuery *aQuery, sbIPlaybackHistoryEntry *aEntry)
nsresult GetPropertyDBID(const nsAString &aPropertyID, PRUint32 *aPropertyDBID)
nsresult DoEntriesAddedCallback(nsIArray *aEntries)
nsresult FillAddAnnotationsQueryParameters(sbIDatabaseQuery *aQuery, sbIPlaybackHistoryEntry *aEntry)
nsresult CreateDefaultQuery(sbIDatabaseQuery **aQuery)
NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER NS_DECL_SBIMEDIACOREEVENTLISTENER static NS_DECL_SBIPLAYBACKHISTORYSERVICE NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
nsresult CreateEntriesFromResultSet(sbIDatabaseResult *aResult, nsIArray **aEntries)
Definition of the sbIMediacoreEvent interface.
An object containing the results of a database SELECT query.
nsresult InsertPropertyID(const nsAString &aPropertyID, PRUint32 *aPropertyDBID)
An object responsible for executing SQL queries on the database.
nsresult UpdateTrackingDataFromEvent(sbIMediacoreEvent *aEvent)
Interface that defines a single item of media in the system.
nsresult GetItem(const nsAString &aLibraryGuid, const nsAString &aItemGuid, sbIMediaItem **aItem)
nsresult DoEntryAddedCallback(sbIPlaybackHistoryEntry *aEntry)
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
nsresult DoEntriesUpdatedCallback(nsIArray *aEntry)
nsresult CreateEntryFromResultSet(sbIDatabaseResult *aResult, PRUint32 aRow, sbIPlaybackHistoryEntry **aEntry)
static PLDHashOperator PR_CALLBACK AddListenersToCOMArrayCallback(nsISupportsHashKey::KeyType aKey, sbIPlaybackHistoryListener *aEntry, void *aUserData)