1 /* 2 * Copyright 2010, The Android Open Source Project 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 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * 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 THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WebCache_h 27 #define WebCache_h 28 29 #include "CacheResult.h" 30 #include "ChromiumIncludes.h" 31 32 #include <OwnPtr.h> 33 #include <platform/text/PlatformString.h> 34 #include <wtf/ThreadingPrimitives.h> 35 36 namespace android { 37 38 // This class is not generally threadsafe. However, get() and cleanup() are 39 // threadsafe. 40 class WebCache : public base::RefCountedThreadSafe<WebCache> { 41 public: 42 static WebCache* get(bool isPrivateBrowsing); 43 static void cleanup(bool isPrivateBrowsing); 44 45 void clear(); 46 scoped_refptr<CacheResult> getCacheResult(WTF::String url); 47 net::HostResolver* hostResolver() { return m_hostResolver.get(); } 48 net::HttpCache* cache() { return m_cache.get(); } 49 net::ProxyConfigServiceAndroid* proxy() { return m_proxyConfigService; } 50 void closeIdleConnections(); 51 void certTrustChanged(); 52 53 private: 54 WebCache(bool isPrivateBrowsing); 55 56 // For clear() 57 void clearImpl(); 58 void doomAllEntries(int); 59 void onClearDone(int); 60 61 // For closeIdleConnections 62 void closeIdleImpl(); 63 void certTrustChangedImpl(); 64 65 // For getEntry() 66 void getEntryImpl(); 67 void openEntry(int); 68 void onGetEntryDone(int); 69 70 OwnPtr<net::HostResolver> m_hostResolver; 71 OwnPtr<net::HttpCache> m_cache; 72 // This is owned by the ProxyService, which is owned by the HttpNetworkLayer, 73 // which is owned by the HttpCache, which is owned by this class. 74 net::ProxyConfigServiceAndroid* m_proxyConfigService; 75 76 // For clear() 77 net::CompletionCallbackImpl<WebCache> m_doomAllEntriesCallback; 78 net::CompletionCallbackImpl<WebCache> m_onClearDoneCallback; 79 bool m_isClearInProgress; 80 // For getEntry() 81 net::CompletionCallbackImpl<WebCache> m_openEntryCallback; 82 net::CompletionCallbackImpl<WebCache> m_onGetEntryDoneCallback; 83 bool m_isGetEntryInProgress; 84 String m_entryUrl; 85 disk_cache::Entry* m_entry; 86 WTF::Mutex m_getEntryMutex; 87 WTF::ThreadCondition m_getEntryCondition; 88 89 disk_cache::Backend* m_cacheBackend; 90 }; 91 92 } // namespace android 93 94 #endif 95