| 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; |
| 51 | 60 |
| 52 virtual ~ChromeAppCacheService(); | 61 virtual ~ChromeAppCacheService(); |
| 53 | 62 |
| 54 // AppCachePolicy overrides | 63 // AppCachePolicy overrides |
| 55 virtual bool CanLoadAppCache(const GURL& manifest_url); | 64 virtual bool CanLoadAppCache(const GURL& manifest_url); |
| 56 virtual int CanCreateAppCache(const GURL& manifest_url, | 65 virtual int CanCreateAppCache(const GURL& manifest_url, |
| 57 net::CompletionCallback* callback); | 66 net::CompletionCallback* callback); |
| 58 | 67 |
| 59 // NotificationObserver override | 68 // NotificationObserver override |
| 60 virtual void Observe(NotificationType type, | 69 virtual void Observe(NotificationType type, |
| 61 const NotificationSource& source, | 70 const NotificationSource& source, |
| 62 const NotificationDetails& details); | 71 const NotificationDetails& details); |
| 63 | 72 |
| 73 // Appcache clearing helpers and callbacks |
| 74 void OnGotAppCacheInfo(int rv); |
| 75 void OnOriginDeleted(int rv); |
| 76 void OnClearedAppCache(); |
| 77 |
| 64 const content::ResourceContext* resource_context_; | 78 const content::ResourceContext* resource_context_; |
| 65 NotificationRegistrar registrar_; | 79 NotificationRegistrar registrar_; |
| 66 bool clear_local_state_on_exit_; | |
| 67 FilePath cache_path_; | 80 FilePath cache_path_; |
| 81 net::CompletionCallbackImpl<ChromeAppCacheService> |
| 82 appcache_got_info_callback_; |
| 83 net::CompletionCallbackImpl<ChromeAppCacheService> |
| 84 origin_deleted_callback_; |
| 85 scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_; |
| 86 int origins_to_be_deleted_count_; |
| 87 scoped_ptr<base::WaitableEvent> appcaches_cleared_event_; |
| 88 net::CompletionCallback* appcaches_cleared_callback_; |
| 89 bool waiting_for_clear_appcaches_; |
| 68 | 90 |
| 69 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); | 91 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); |
| 70 }; | 92 }; |
| 71 | 93 |
| 72 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 94 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
| OLD | NEW |