Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/appcache/chrome_appcache_service.h" | 5 #include "chrome/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 "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/net/chrome_url_request_context.h" | 10 #include "chrome/browser/net/chrome_url_request_context.h" |
| 11 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 12 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "webkit/appcache/appcache_thread.h" | 14 #include "webkit/appcache/appcache_thread.h" |
| 15 | 15 |
| 16 static bool has_initialized_thread_ids; | 16 static bool has_initialized_thread_ids; |
| 17 | 17 |
| 18 // ---------------------------------------------------------------------------- | 18 // ---------------------------------------------------------------------------- |
| 19 | 19 |
| 20 ChromeAppCacheService::ChromeAppCacheService() { | 20 ChromeAppCacheService::ChromeAppCacheService() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void ChromeAppCacheService::InitializeOnIOThread( | 23 void ChromeAppCacheService::InitializeOnIOThread( |
| 24 const FilePath& profile_path, bool is_incognito, | 24 const FilePath& profile_path, bool is_incognito, |
| 25 scoped_refptr<HostContentSettingsMap> content_settings_map) { | 25 scoped_refptr<HostContentSettingsMap> content_settings_map, |
| 26 bool clear_local_state_on_exit) { | |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 27 | 28 |
| 28 if (!has_initialized_thread_ids) { | 29 if (!has_initialized_thread_ids) { |
| 29 has_initialized_thread_ids = true; | 30 has_initialized_thread_ids = true; |
| 30 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); | 31 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); |
| 31 } | 32 } |
| 32 | 33 |
| 33 host_contents_settings_map_ = content_settings_map; | 34 host_contents_settings_map_ = content_settings_map; |
| 34 registrar_.Add( | 35 registrar_.Add( |
| 35 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); | 36 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); |
| 37 clear_local_state_on_exit_ = clear_local_state_on_exit; | |
| 38 if (!is_incognito) | |
| 39 cache_path_ = profile_path.Append(chrome::kAppCacheDirname); | |
| 36 | 40 |
| 37 // Init our base class. | 41 // Init our base class. |
| 38 Initialize( | 42 Initialize(cache_path_ , |
| 39 is_incognito ? FilePath() : profile_path.Append(chrome::kAppCacheDirname), | 43 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 40 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
| 41 set_appcache_policy(this); | 44 set_appcache_policy(this); |
| 42 } | 45 } |
| 43 | 46 |
| 44 ChromeAppCacheService::~ChromeAppCacheService() { | 47 ChromeAppCacheService::~ChromeAppCacheService() { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 49 | |
| 50 if (clear_local_state_on_exit_ && !cache_path_.empty()) | |
| 51 file_util::Delete(cache_path_, true); | |
|
jochen (gone - plz use gerrit)
2011/01/04 14:32:53
this should happen on the FILE thread
| |
| 46 } | 52 } |
| 47 | 53 |
| 48 void ChromeAppCacheService::SetOriginQuotaInMemory( | 54 void ChromeAppCacheService::SetOriginQuotaInMemory( |
| 49 const GURL& origin, int64 quota) { | 55 const GURL& origin, int64 quota) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 51 if (storage()) | 57 if (storage()) |
| 52 storage()->SetOriginQuotaInMemory(origin, quota); | 58 storage()->SetOriginQuotaInMemory(origin, quota); |
| 53 } | 59 } |
| 54 | 60 |
| 55 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { | 61 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 57 if (storage()) | 63 if (storage()) |
| 58 storage()->ResetOriginQuotaInMemory(origin); | 64 storage()->ResetOriginQuotaInMemory(origin); |
| 59 } | 65 } |
| 60 | 66 |
| 61 // static | |
| 62 void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { | |
| 63 file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); | |
| 64 } | |
| 65 | |
| 66 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { | 67 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 68 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | 69 ContentSetting setting = host_contents_settings_map_->GetContentSetting( |
| 69 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 70 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 70 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 71 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 71 // We don't prompt for read access. | 72 // We don't prompt for read access. |
| 72 return setting != CONTENT_SETTING_BLOCK; | 73 return setting != CONTENT_SETTING_BLOCK; |
| 73 } | 74 } |
| 74 | 75 |
| 75 int ChromeAppCacheService::CanCreateAppCache( | 76 int ChromeAppCacheService::CanCreateAppCache( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 const tracked_objects::Location& from_here, | 108 const tracked_objects::Location& from_here, |
| 108 Task* task) { | 109 Task* task) { |
| 109 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); | 110 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); |
| 110 } | 111 } |
| 111 | 112 |
| 112 bool AppCacheThread::CurrentlyOn(int id) { | 113 bool AppCacheThread::CurrentlyOn(int id) { |
| 113 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); | 114 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); |
| 114 } | 115 } |
| 115 | 116 |
| 116 } // namespace appcache | 117 } // namespace appcache |
| OLD | NEW |