| 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 #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" | |
| 13 #include "webkit/quota/quota_manager.h" | 12 #include "webkit/quota/quota_manager.h" |
| 14 | 13 |
| 15 static bool has_initialized_thread_ids; | |
| 16 | |
| 17 // ---------------------------------------------------------------------------- | |
| 18 | |
| 19 ChromeAppCacheService::ChromeAppCacheService( | 14 ChromeAppCacheService::ChromeAppCacheService( |
| 20 quota::QuotaManagerProxy* quota_manager_proxy) | 15 quota::QuotaManagerProxy* quota_manager_proxy) |
| 21 : AppCacheService(quota_manager_proxy), | 16 : AppCacheService(quota_manager_proxy), |
| 22 resource_context_(NULL) { | 17 resource_context_(NULL) { |
| 23 } | 18 } |
| 24 | 19 |
| 25 void ChromeAppCacheService::InitializeOnIOThread( | 20 void ChromeAppCacheService::InitializeOnIOThread( |
| 26 const FilePath& cache_path, | 21 const FilePath& cache_path, |
| 27 const content::ResourceContext* resource_context, | 22 const content::ResourceContext* resource_context, |
| 28 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 23 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 30 | 25 |
| 31 if (!has_initialized_thread_ids) { | |
| 32 has_initialized_thread_ids = true; | |
| 33 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); | |
| 34 } | |
| 35 | |
| 36 cache_path_ = cache_path; | 26 cache_path_ = cache_path; |
| 37 resource_context_ = resource_context; | 27 resource_context_ = resource_context; |
| 38 registrar_.Add( | 28 registrar_.Add( |
| 39 this, content::NOTIFICATION_PURGE_MEMORY, | 29 this, content::NOTIFICATION_PURGE_MEMORY, |
| 40 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
| 41 | 31 |
| 42 // Init our base class. | 32 // Init our base class. |
| 43 Initialize(cache_path_, | 33 Initialize(cache_path_, |
| 34 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 35 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 45 set_appcache_policy(this); | 36 set_appcache_policy(this); |
| 46 set_special_storage_policy(special_storage_policy); | 37 set_special_storage_policy(special_storage_policy); |
| 47 } | 38 } |
| 48 | 39 |
| 49 ChromeAppCacheService::~ChromeAppCacheService() { | 40 ChromeAppCacheService::~ChromeAppCacheService() { |
| 50 } | 41 } |
| 51 | 42 |
| 52 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url, | 43 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url, |
| 53 const GURL& first_party) { | 44 const GURL& first_party) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 manifest_url, first_party, *resource_context_); | 55 manifest_url, first_party, *resource_context_); |
| 65 } | 56 } |
| 66 | 57 |
| 67 void ChromeAppCacheService::Observe(int type, | 58 void ChromeAppCacheService::Observe(int type, |
| 68 const NotificationSource& source, | 59 const NotificationSource& source, |
| 69 const NotificationDetails& details) { | 60 const NotificationDetails& details) { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 71 DCHECK(type == content::NOTIFICATION_PURGE_MEMORY); | 62 DCHECK(type == content::NOTIFICATION_PURGE_MEMORY); |
| 72 PurgeMemory(); | 63 PurgeMemory(); |
| 73 } | 64 } |
| 74 | |
| 75 // ---------------------------------------------------------------------------- | |
| 76 | |
| 77 static BrowserThread::ID ToBrowserThreadID(int id) { | |
| 78 DCHECK(has_initialized_thread_ids); | |
| 79 DCHECK(id == BrowserThread::DB || id == BrowserThread::IO); | |
| 80 return static_cast<BrowserThread::ID>(id); | |
| 81 } | |
| 82 | |
| 83 namespace appcache { | |
| 84 | |
| 85 // An impl of AppCacheThread we need to provide to the appcache lib. | |
| 86 | |
| 87 bool AppCacheThread::PostTask( | |
| 88 int id, | |
| 89 const tracked_objects::Location& from_here, | |
| 90 Task* task) { | |
| 91 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); | |
| 92 } | |
| 93 | |
| 94 bool AppCacheThread::CurrentlyOn(int id) { | |
| 95 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); | |
| 96 } | |
| 97 | |
| 98 } // namespace appcache | |
| OLD | NEW |