Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: content/browser/appcache/chrome_appcache_service.cc

Issue 7210006: AppCaches which belong to hosted apps are not protected from deletion (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Moving test helpers to webkit/appcache. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/browser/appcache/chrome_appcache_service.h" 5 #include "content/browser/appcache/chrome_appcache_service.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "content/browser/content_browser_client.h" 9 #include "content/browser/content_browser_client.h"
10 #include "content/common/notification_service.h" 10 #include "content/common/notification_service.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "webkit/appcache/appcache_thread.h" 12 #include "webkit/appcache/appcache_thread.h"
13 #include "webkit/quota/quota_manager.h" 13 #include "webkit/quota/quota_manager.h"
14 14
15 static bool has_initialized_thread_ids; 15 static bool has_initialized_thread_ids;
16 16
17 namespace {
18
19 // Used to defer deleting of local storage until the destructor has finished.
20 void DeleteLocalStateOnIOThread(FilePath cache_path) {
21 // Post the actual deletion to the DB thread to ensure it happens after the
22 // database file has been closed.
23 BrowserThread::PostTask(
24 BrowserThread::DB, FROM_HERE,
25 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>(
26 &file_util::Delete, cache_path, true));
27 }
28
29 } // namespace
30
31 // ---------------------------------------------------------------------------- 17 // ----------------------------------------------------------------------------
32 18
33 ChromeAppCacheService::ChromeAppCacheService( 19 ChromeAppCacheService::ChromeAppCacheService(
34 quota::QuotaManagerProxy* quota_manager_proxy) 20 quota::QuotaManagerProxy* quota_manager_proxy)
35 : AppCacheService(quota_manager_proxy), 21 : AppCacheService(quota_manager_proxy),
36 resource_context_(NULL), clear_local_state_on_exit_(false) { 22 resource_context_(NULL) {
37 } 23 }
38 24
39 void ChromeAppCacheService::InitializeOnIOThread( 25 void ChromeAppCacheService::InitializeOnIOThread(
40 const FilePath& cache_path, 26 const FilePath& cache_path,
41 const content::ResourceContext* resource_context, 27 const content::ResourceContext* resource_context,
42 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, 28 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) {
43 bool clear_local_state_on_exit) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
45 30
46 if (!has_initialized_thread_ids) { 31 if (!has_initialized_thread_ids) {
47 has_initialized_thread_ids = true; 32 has_initialized_thread_ids = true;
48 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); 33 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO);
49 } 34 }
50 35
51 cache_path_ = cache_path; 36 cache_path_ = cache_path;
52 resource_context_ = resource_context; 37 resource_context_ = resource_context;
53 registrar_.Add( 38 registrar_.Add(
54 this, content::NOTIFICATION_PURGE_MEMORY, 39 this, content::NOTIFICATION_PURGE_MEMORY,
55 NotificationService::AllSources()); 40 NotificationService::AllSources());
56 SetClearLocalStateOnExit(clear_local_state_on_exit);
57 41
58 // Init our base class. 42 // Init our base class.
59 Initialize(cache_path_, 43 Initialize(cache_path_,
60 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
61 set_appcache_policy(this); 45 set_appcache_policy(this);
62 set_special_storage_policy(special_storage_policy); 46 set_special_storage_policy(special_storage_policy);
63 } 47 }
64 48
65 ChromeAppCacheService::~ChromeAppCacheService() { 49 ChromeAppCacheService::~ChromeAppCacheService() {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
67
68 if (clear_local_state_on_exit_ && !cache_path_.empty()) {
69 BrowserThread::PostTask(
70 BrowserThread::IO, FROM_HERE,
71 NewRunnableFunction(DeleteLocalStateOnIOThread, cache_path_));
72 }
73 }
74
75 void ChromeAppCacheService::SetClearLocalStateOnExit(bool clear_local_state) {
76 // TODO(michaeln): How is 'protected' status granted to apps in this case?
77 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
78 BrowserThread::PostTask(
79 BrowserThread::IO, FROM_HERE,
80 NewRunnableMethod(this,
81 &ChromeAppCacheService::SetClearLocalStateOnExit,
82 clear_local_state));
83 return;
84 }
85 clear_local_state_on_exit_ = clear_local_state;
86 } 50 }
87 51
88 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { 52 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
90 // We don't prompt for read access. 54 // We don't prompt for read access.
91 return content::GetContentClient()->browser()->AllowAppCache( 55 return content::GetContentClient()->browser()->AllowAppCache(
92 manifest_url, *resource_context_); 56 manifest_url, *resource_context_);
93 } 57 }
94 58
95 int ChromeAppCacheService::CanCreateAppCache( 59 int ChromeAppCacheService::CanCreateAppCache(
(...skipping 28 matching lines...) Expand all
124 const tracked_objects::Location& from_here, 88 const tracked_objects::Location& from_here,
125 Task* task) { 89 Task* task) {
126 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); 90 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task);
127 } 91 }
128 92
129 bool AppCacheThread::CurrentlyOn(int id) { 93 bool AppCacheThread::CurrentlyOn(int id) {
130 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); 94 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id));
131 } 95 }
132 96
133 } // namespace appcache 97 } // namespace appcache
OLDNEW
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.h ('k') | content/browser/appcache/chrome_appcache_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698