1/*
2 * Copyright (C) 2010, 2011, 2012 Apple 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 SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef PlatformStrategies_h
27#define PlatformStrategies_h
28
29namespace WebCore {
30
31class CookiesStrategy;
32class DatabaseStrategy;
33class LoaderStrategy;
34class PasteboardStrategy;
35class PluginStrategy;
36class SharedWorkerStrategy;
37class StorageStrategy;
38
39class PlatformStrategies {
40public:
41    CookiesStrategy* cookiesStrategy()
42    {
43        if (!m_cookiesStrategy)
44            m_cookiesStrategy = createCookiesStrategy();
45        return m_cookiesStrategy;
46    }
47
48    DatabaseStrategy* databaseStrategy()
49    {
50        if (!m_databaseStrategy)
51            m_databaseStrategy = createDatabaseStrategy();
52        return m_databaseStrategy;
53    }
54
55    LoaderStrategy* loaderStrategy()
56    {
57        if (!m_loaderStrategy)
58            m_loaderStrategy = createLoaderStrategy();
59        return m_loaderStrategy;
60    }
61
62    PasteboardStrategy* pasteboardStrategy()
63    {
64        if (!m_pasteboardStrategy)
65            m_pasteboardStrategy = createPasteboardStrategy();
66        return m_pasteboardStrategy;
67    }
68
69    PluginStrategy* pluginStrategy()
70    {
71        if (!m_pluginStrategy)
72            m_pluginStrategy = createPluginStrategy();
73        return m_pluginStrategy;
74    }
75
76    SharedWorkerStrategy* sharedWorkerStrategy()
77    {
78        if (!m_sharedWorkerStrategy)
79            m_sharedWorkerStrategy = createSharedWorkerStrategy();
80        return m_sharedWorkerStrategy;
81    }
82
83    StorageStrategy* storageStrategy()
84    {
85        if (!m_storageStrategy)
86            m_storageStrategy = createStorageStrategy();
87        return m_storageStrategy;
88    }
89
90protected:
91    PlatformStrategies()
92        : m_cookiesStrategy(nullptr)
93        , m_databaseStrategy(nullptr)
94        , m_loaderStrategy(nullptr)
95        , m_pasteboardStrategy(nullptr)
96        , m_pluginStrategy(nullptr)
97        , m_sharedWorkerStrategy(nullptr)
98        , m_storageStrategy(nullptr)
99    {
100    }
101
102    virtual ~PlatformStrategies()
103    {
104    }
105
106private:
107    virtual CookiesStrategy* createCookiesStrategy() = 0;
108    virtual DatabaseStrategy* createDatabaseStrategy() = 0;
109    virtual LoaderStrategy* createLoaderStrategy() = 0;
110    virtual PasteboardStrategy* createPasteboardStrategy() = 0;
111    virtual PluginStrategy* createPluginStrategy() = 0;
112    virtual SharedWorkerStrategy* createSharedWorkerStrategy() = 0;
113    virtual StorageStrategy* createStorageStrategy() = 0;
114
115    CookiesStrategy* m_cookiesStrategy;
116    DatabaseStrategy* m_databaseStrategy;
117    LoaderStrategy* m_loaderStrategy;
118    PasteboardStrategy* m_pasteboardStrategy;
119    PluginStrategy* m_pluginStrategy;
120    SharedWorkerStrategy* m_sharedWorkerStrategy;
121    StorageStrategy* m_storageStrategy;
122};
123
124PlatformStrategies* platformStrategies();
125void setPlatformStrategies(PlatformStrategies*);
126bool hasPlatformStrategies();
127
128} // namespace WebCore
129
130#endif // PlatformStrategies_h
131