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 | |
michaeln
2011/07/02 00:29:09
i'd nuke this comment, i think it's stating the ob
marja(google)
2011/07/13 11:06:59
Done.
| |
59 friend class appcache::TestableChromeAppCacheService; | |
60 | |
61 class ClearAppcacheHelper { | |
michaeln
2011/07/02 00:29:09
This class seems heavier weight than it needs to b
marja(google)
2011/07/13 11:06:59
Done.
| |
62 public: | |
63 ClearAppcacheHelper(ChromeAppCacheService* parent, | |
64 net::CompletionCallback* callback); | |
65 ~ClearAppcacheHelper(); | |
66 void OnClearedAppCache(); | |
67 private: | |
68 scoped_refptr<ChromeAppCacheService> parent_; | |
69 net::CompletionCallback* callback_; | |
70 }; | |
51 | 71 |
52 virtual ~ChromeAppCacheService(); | 72 virtual ~ChromeAppCacheService(); |
53 | 73 |
54 // AppCachePolicy overrides | 74 // AppCachePolicy overrides |
55 virtual bool CanLoadAppCache(const GURL& manifest_url); | 75 virtual bool CanLoadAppCache(const GURL& manifest_url); |
56 virtual int CanCreateAppCache(const GURL& manifest_url, | 76 virtual int CanCreateAppCache(const GURL& manifest_url, |
57 net::CompletionCallback* callback); | 77 net::CompletionCallback* callback); |
58 | 78 |
59 // NotificationObserver override | 79 // NotificationObserver override |
60 virtual void Observe(NotificationType type, | 80 virtual void Observe(NotificationType type, |
61 const NotificationSource& source, | 81 const NotificationSource& source, |
62 const NotificationDetails& details); | 82 const NotificationDetails& details); |
63 | 83 |
84 // Appcache clearing helpers and callbacks | |
michaeln
2011/07/02 00:29:09
AppCache with an upper 'C' is more in keeping with
marja(google)
2011/07/13 11:06:59
Done.
| |
85 void OnGotAppCacheInfo(int rv); | |
86 void OnAppCacheDeleted(int rv); | |
87 | |
64 const content::ResourceContext* resource_context_; | 88 const content::ResourceContext* resource_context_; |
65 NotificationRegistrar registrar_; | 89 NotificationRegistrar registrar_; |
66 bool clear_local_state_on_exit_; | |
67 FilePath cache_path_; | 90 FilePath cache_path_; |
91 ClearAppcacheHelper* clear_appcache_helper_; | |
92 net::CompletionCallbackImpl<ChromeAppCacheService> | |
93 appcache_got_info_callback_; | |
94 net::CompletionCallbackImpl<ChromeAppCacheService> | |
95 appcache_deleted_callback_; | |
96 scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_; | |
97 int appcaches_to_be_deleted_count_; | |
98 scoped_ptr<base::WaitableEvent> appcaches_cleared_event_; | |
68 | 99 |
69 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); | 100 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); |
70 }; | 101 }; |
71 | 102 |
72 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ | 103 #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ |
OLD | NEW |