| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/synchronization/waitable_event.h" |
| 10 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
| 11 #include "content/common/notification_observer.h" | 12 #include "content/common/notification_observer.h" |
| 12 #include "content/common/notification_registrar.h" | 13 #include "content/common/notification_registrar.h" |
| 14 #include "net/base/completion_callback.h" |
| 13 #include "webkit/appcache/appcache_policy.h" | 15 #include "webkit/appcache/appcache_policy.h" |
| 14 #include "webkit/appcache/appcache_service.h" | 16 #include "webkit/appcache/appcache_service.h" |
| 15 #include "webkit/quota/special_storage_policy.h" | 17 #include "webkit/quota/special_storage_policy.h" |
| 16 | 18 |
| 17 class FilePath; | 19 class FilePath; |
| 18 | 20 |
| 21 namespace appcache { |
| 22 class TestableChromeAppCacheService; |
| 23 } |
| 24 |
| 19 namespace content { | 25 namespace content { |
| 20 class ResourceContext; | 26 class ResourceContext; |
| 21 } | 27 } |
| 22 | 28 |
| 23 // An AppCacheService subclass used by the chrome. There is an instance | 29 // An AppCacheService subclass used by the chrome. There is an instance |
| 24 // associated with each Profile. This derivation adds refcounting semantics | 30 // associated with each Profile. This derivation adds refcounting semantics |
| 25 // since a profile has multiple URLRequestContexts which refer to the same | 31 // since a profile has multiple URLRequestContexts which refer to the same |
| 26 // object, and those URLRequestContexts are refcounted independently of the | 32 // object, and those URLRequestContexts are refcounted independently of the |
| 27 // owning profile. | 33 // owning profile. |
| 28 // | 34 // |
| 29 // All methods, except the ctor, are expected to be called on | 35 // All methods, except the ctor, are expected to be called on |
| 30 // the IO thread (unless specifically called out in doc comments). | 36 // the IO thread (unless specifically called out in doc comments). |
| 31 class ChromeAppCacheService | 37 class ChromeAppCacheService |
| 32 : public base::RefCountedThreadSafe<ChromeAppCacheService, | 38 : public base::RefCountedThreadSafe<ChromeAppCacheService, |
| 33 BrowserThread::DeleteOnIOThread>, | 39 BrowserThread::DeleteOnIOThread>, |
| 34 public appcache::AppCacheService, | 40 public appcache::AppCacheService, |
| 35 public appcache::AppCachePolicy, | 41 public appcache::AppCachePolicy, |
| 36 public NotificationObserver { | 42 public NotificationObserver { |
| 37 public: | 43 public: |
| 38 explicit ChromeAppCacheService(quota::QuotaManagerProxy* proxy); | 44 explicit ChromeAppCacheService(quota::QuotaManagerProxy* proxy); |
| 39 | 45 |
| 40 void InitializeOnIOThread( | 46 void InitializeOnIOThread( |
| 41 const FilePath& cache_path, // may be empty to use in-memory structures | 47 const FilePath& cache_path, // may be empty to use in-memory structures |
| 42 const content::ResourceContext* resource_context, | 48 const content::ResourceContext* resource_context, |
| 43 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy); |
| 44 bool clear_local_state_on_exit); | |
| 45 | 50 |
| 46 void SetClearLocalStateOnExit(bool clear_local_state); | 51 // Safe to call from any thread |
| 52 base::WaitableEvent* ClearAppCache(net::CompletionCallback* callback); |
| 47 | 53 |
| 48 private: | 54 private: |
| 49 friend class BrowserThread; | 55 friend class BrowserThread; |
| 50 friend class DeleteTask<ChromeAppCacheService>; | 56 friend class DeleteTask<ChromeAppCacheService>; |
| 57 // TestableChromeAppService is a subclass of ChromeAppCacheService used in the |
| 58 // unit tests |
| 59 friend class appcache::TestableChromeAppCacheService; |
| 60 FRIEND_TEST_ALL_PREFIXES(BrowsingDataRemoverTest, RemoveAppCacheForever); |
| 51 | 61 |
| 52 virtual ~ChromeAppCacheService(); | 62 virtual ~ChromeAppCacheService(); |
| 53 | 63 |
| 54 // AppCachePolicy overrides | 64 // AppCachePolicy overrides |
| 55 virtual bool CanLoadAppCache(const GURL& manifest_url); | 65 virtual bool CanLoadAppCache(const GURL& manifest_url); |
| 56 virtual int CanCreateAppCache(const GURL& manifest_url, | 66 virtual int CanCreateAppCache(const GURL& manifest_url, |
| 57 net::CompletionCallback* callback); | 67 net::CompletionCallback* callback); |
| 58 | 68 |
| 59 // NotificationObserver override | 69 // NotificationObserver override |
| 60 virtual void Observe(int type, | 70 virtual void Observe(int type, |
| 61 const NotificationSource& source, | 71 const NotificationSource& source, |
| 62 const NotificationDetails& details); | 72 const NotificationDetails& details); |
| 63 | 73 |
| 74 // Appcache clearing helpers and callbacks |
| 75 void OnGotAppCacheInfo(int rv); |
| 76 void OnOriginDeleted(int rv); |
| 77 void OnClearedAppCache(); |
| 78 |
| 64 const content::ResourceContext* resource_context_; | 79 const content::ResourceContext* resource_context_; |
| 65 NotificationRegistrar registrar_; | 80 NotificationRegistrar registrar_; |
| 66 bool clear_local_state_on_exit_; | |
| 67 FilePath cache_path_; | 81 FilePath cache_path_; |
| 82 net::CompletionCallbackImpl<ChromeAppCacheService> |
| 83 appcache_got_info_callback_; |
| 84 net::CompletionCallbackImpl<ChromeAppCacheService> |
| 85 origin_deleted_callback_; |
| 86 scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_; |
| 87 int origins_to_be_deleted_count_; |
| 88 scoped_ptr<base::WaitableEvent> appcaches_cleared_event_; |
| 89 net::CompletionCallback* appcaches_cleared_callback_; |
| 90 bool waiting_for_clear_appcaches_; |
| 68 | 91 |
| 69 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); | 92 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); |
| 70 }; | 93 }; |
| 71 | 94 |
| 72 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 95 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
| OLD | NEW |