36 #include <nsThreadUtils.h>
37 #include <nsComponentManagerUtils.h>
48 #define TIMER_PERIOD 33
49 #define NUM_ACTIVE_HANDLERS 15
52 extern PRLogModuleInfo* gMetadataLog;
53 #define TRACE(args) PR_LOG(gMetadataLog, PR_LOG_DEBUG, args)
54 #define LOG(args) PR_LOG(gMetadataLog, PR_LOG_WARN, args)
67 mJobManager(aManager),
72 TRACE((
"sbMainThreadMetadataProcessor[0x%.8x] - ctor",
this));
73 NS_ASSERTION(NS_IsMainThread(),
"sbMainThreadMetadataProcessor called off the main thread");
79 TRACE((
"sbMainThreadMetadataProcessor[0x%.8x] - dtor",
this));
88 NS_ASSERTION(NS_IsMainThread(),
"sbMainThreadMetadataProcessor called off the main thread!");
89 TRACE((
"sbMainThreadMetadataProcessor[0x%.8x] - Start",
this));
93 mTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
94 NS_ENSURE_SUCCESS(rv, rv);
100 rv =
mTimer->InitWithCallback(
this,
102 nsITimer::TYPE_REPEATING_SLACK);
103 NS_ENSURE_SUCCESS(rv, rv);
118 NS_ASSERTION(NS_IsMainThread(),
"sbMainThreadMetadataProcessor called off the main thread");
119 TRACE((
"sbMainThreadMetadataProcessor[0x%.8x] - Stop",
this));
133 nsCOMPtr<sbIMetadataHandler>
handler;
134 rv = item->GetHandler(getter_AddRefs(handler));
135 NS_ENSURE_SUCCESS(rv, rv);
152 NS_IMETHODIMP sbMainThreadMetadataProcessor::Notify(nsITimer* aTimer)
154 TRACE((
"sbMainThreadMetadataProcessor[0x%.8x] - Notify",
this));
168 nsCOMPtr<sbIMetadataHandler>
handler;
169 rv = item->GetHandler(getter_AddRefs(handler));
170 NS_ENSURE_SUCCESS(rv, rv);
171 PRBool handlerCompleted;
172 rv = handler->GetCompleted(&handlerCompleted);
173 NS_ENSURE_SUCCESS(rv, rv);
175 if (handlerCompleted) {
180 item->SetProcessed(PR_TRUE);
194 rv =
mJobManager->GetQueuedJobItem(PR_TRUE, getter_AddRefs(item));
196 if (rv == NS_ERROR_NOT_AVAILABLE) {
199 NS_ENSURE_SUCCESS(rv, rv);
210 PRBool processingStarted;
211 rv = item->GetProcessingStarted(&processingStarted);
212 NS_ENSURE_SUCCESS(rv, rv);
213 if (!processingStarted) {
215 nsRefPtr<sbMetadataJob> job;
216 rv = item->GetOwningJob(getter_AddRefs(job));
217 NS_ENSURE_SUCCESS(rv, rv);
220 PRBool jobItemIsBlocked;
221 rv =
mJobManager->GetJobItemIsBlocked(item, &jobItemIsBlocked);
222 NS_ENSURE_SUCCESS(rv, rv);
223 if (jobItemIsBlocked) {
225 rv = job->SetBlocked(PR_TRUE);
226 NS_ENSURE_SUCCESS(rv, rv);
234 rv = job->SetBlocked(PR_FALSE);
235 NS_ENSURE_SUCCESS(rv, rv);
239 nsCOMPtr<sbIMetadataHandler>
handler;
240 rv = item->GetHandler(getter_AddRefs(handler));
241 NS_ENSURE_SUCCESS(rv, rv);
244 rv = item->GetJobType(&jobType);
245 NS_ENSURE_SUCCESS(rv, rv);
248 PRBool async = PR_FALSE;
250 rv = handler->Write(&async);
253 rv = handler->Read(&async);
264 rv = item->SetProcessingStarted(PR_TRUE);
265 NS_ENSURE_SUCCESS(rv, rv);
NS_IMPL_THREADSAFE_ISUPPORTS1(sbMainThreadMetadataProcessor, nsITimerCallback)
nsRefPtr< sbFileMetadataService > mJobManager
nsCOMPtr< nsITimer > mTimer
#define NUM_ACTIVE_HANDLERS
nsTArray< nsRefPtr< sbMetadataJobItem > > mCurrentJobItems
Runs sbIMetadataHandlers with a timer on the main thread.
_getSelectedPageStyle s i
NS_DECL_ISUPPORTS NS_DECL_NSITIMERCALLBACK sbMainThreadMetadataProcessor(sbFileMetadataService *aManager)
virtual ~sbMainThreadMetadataProcessor()