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); | |
michaeln
2011/07/14 00:42:34
Given the approach of deleting in the storage dtor
marja(google)
2011/07/14 10:31:59
Done.
michaeln
2011/07/14 22:53:16
But this method is still in the CL?
marja(google)
2011/07/15 11:03:42
Oops, misread which func this comment refers to. N
| |
53 // Can only be called when there are no pending operations on the | |
54 // ChromeAppCacheService (or the underlying AppCacheStorage), and when it will | |
55 // no longer accessed before deleting it. This function will call | |
56 // AppCacheDatabase functions in the IO thread; that can only work if there is | |
57 // no concurrency. | |
58 void SyncClearAppCacheOnIOThread(); | |
47 | 59 |
48 private: | 60 private: |
49 friend class BrowserThread; | 61 friend class BrowserThread; |
50 friend class DeleteTask<ChromeAppCacheService>; | 62 friend class DeleteTask<ChromeAppCacheService>; |
63 friend class appcache::TestableChromeAppCacheService; | |
51 | 64 |
52 virtual ~ChromeAppCacheService(); | 65 virtual ~ChromeAppCacheService(); |
53 | 66 |
54 // AppCachePolicy overrides | 67 // AppCachePolicy overrides |
55 virtual bool CanLoadAppCache(const GURL& manifest_url); | 68 virtual bool CanLoadAppCache(const GURL& manifest_url); |
56 virtual int CanCreateAppCache(const GURL& manifest_url, | 69 virtual int CanCreateAppCache(const GURL& manifest_url, |
57 net::CompletionCallback* callback); | 70 net::CompletionCallback* callback); |
58 | 71 |
59 // NotificationObserver override | 72 // NotificationObserver override |
60 virtual void Observe(int type, | 73 virtual void Observe(int type, |
61 const NotificationSource& source, | 74 const NotificationSource& source, |
62 const NotificationDetails& details); | 75 const NotificationDetails& details); |
63 | 76 |
77 // AppCache clearing helpers and callbacks | |
78 void OnGotAppCacheInfo(int rv); | |
79 void OnAppCacheDeleted(int rv); | |
80 void OnClearedAppCache(); | |
81 | |
64 const content::ResourceContext* resource_context_; | 82 const content::ResourceContext* resource_context_; |
65 NotificationRegistrar registrar_; | 83 NotificationRegistrar registrar_; |
66 bool clear_local_state_on_exit_; | |
67 FilePath cache_path_; | 84 FilePath cache_path_; |
85 net::CompletionCallbackImpl<ChromeAppCacheService> | |
86 appcache_got_info_callback_; | |
87 net::CompletionCallbackImpl<ChromeAppCacheService> | |
88 appcache_deleted_callback_; | |
89 scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_; | |
90 int appcaches_to_be_deleted_count_; | |
91 scoped_ptr<base::WaitableEvent> appcaches_cleared_event_; | |
92 net::CompletionCallback* appcaches_cleared_callback_; | |
93 bool waiting_for_clear_appcaches_; | |
68 | 94 |
69 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); | 95 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); |
70 }; | 96 }; |
71 | 97 |
72 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 98 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
OLD | NEW |