1 /*
2 * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * This library is distributed in the hope that i will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include "config.h"
25 #include "LocalStorageThread.h"
26
27 #include "LocalStorageTask.h"
28 #include "StorageAreaSync.h"
29
30 namespace WebCore {
31
LocalStorageThread()32 LocalStorageThread::LocalStorageThread()
33 : m_timer(this, &LocalStorageThread::timerFired)
34 {
35 }
36
~LocalStorageThread()37 LocalStorageThread::~LocalStorageThread()
38 {
39 }
40
start()41 bool LocalStorageThread::start()
42 {
43 return true;
44 }
45
timerFired(Timer<LocalStorageThread> *)46 void LocalStorageThread::timerFired(Timer<LocalStorageThread>*)
47 {
48 if (!m_queue.isEmpty()) {
49 RefPtr<LocalStorageTask> task = m_queue.first();
50 task->performTask();
51 m_queue.removeFirst();
52 if (!m_queue.isEmpty())
53 m_timer.startOneShot(0);
54 }
55 }
56
scheduleImport(PassRefPtr<StorageAreaSync> area)57 void LocalStorageThread::scheduleImport(PassRefPtr<StorageAreaSync> area)
58 {
59 m_queue.append(LocalStorageTask::createImport(area));
60 if (!m_timer.isActive())
61 m_timer.startOneShot(0);
62 }
63
scheduleSync(PassRefPtr<StorageAreaSync> area)64 void LocalStorageThread::scheduleSync(PassRefPtr<StorageAreaSync> area)
65 {
66 m_queue.append(LocalStorageTask::createSync(area));
67 if (!m_timer.isActive())
68 m_timer.startOneShot(0);
69 }
70
terminate()71 void LocalStorageThread::terminate()
72 {
73 m_queue.clear();
74 m_timer.stop();
75 }
76
performTerminate()77 void LocalStorageThread::performTerminate()
78 {
79 m_queue.clear();
80 m_timer.stop();
81 }
82
83 } // namespace WebCore
84