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 SetClearLocalStateOnExit(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 BrowserThread::PostTask( | |
| 52 BrowserThread::FILE, FROM_HERE, | |
| 53 NewRunnableFunction(file_util::Delete, cache_path_, true)); | |
|
michaeln
2011/01/05 00:59:14
I think if this task was posted to the DB thread f
pastarmovj
2011/01/05 10:47:07
After discussing this with Jochen, we decided that
| |
| 46 } | 54 } |
| 47 | 55 |
| 48 void ChromeAppCacheService::SetOriginQuotaInMemory( | 56 void ChromeAppCacheService::SetOriginQuotaInMemory( |
| 49 const GURL& origin, int64 quota) { | 57 const GURL& origin, int64 quota) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 51 if (storage()) | 59 if (storage()) |
| 52 storage()->SetOriginQuotaInMemory(origin, quota); | 60 storage()->SetOriginQuotaInMemory(origin, quota); |
| 53 } | 61 } |
| 54 | 62 |
| 55 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { | 63 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 57 if (storage()) | 65 if (storage()) |
| 58 storage()->ResetOriginQuotaInMemory(origin); | 66 storage()->ResetOriginQuotaInMemory(origin); |
| 59 } | 67 } |
| 60 | 68 |
| 61 // static | 69 void ChromeAppCacheService::SetClearLocalStateOnExit(bool clear_local_state) { |
| 62 void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { | 70 AutoLock lock(lock_); |
|
michaeln
2011/01/05 00:59:14
Instead of a lock, it might be better to post a ta
pastarmovj
2011/01/05 10:47:07
Done.
| |
| 63 file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); | 71 clear_local_state_on_exit_ = clear_local_state; |
| 64 } | 72 } |
| 65 | 73 |
| 66 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { | 74 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 68 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | 76 ContentSetting setting = host_contents_settings_map_->GetContentSetting( |
| 69 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 77 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 70 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 78 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 71 // We don't prompt for read access. | 79 // We don't prompt for read access. |
| 72 return setting != CONTENT_SETTING_BLOCK; | 80 return setting != CONTENT_SETTING_BLOCK; |
| 73 } | 81 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 const tracked_objects::Location& from_here, | 115 const tracked_objects::Location& from_here, |
| 108 Task* task) { | 116 Task* task) { |
| 109 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); | 117 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); |
| 110 } | 118 } |
| 111 | 119 |
| 112 bool AppCacheThread::CurrentlyOn(int id) { | 120 bool AppCacheThread::CurrentlyOn(int id) { |
| 113 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); | 121 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); |
| 114 } | 122 } |
| 115 | 123 |
| 116 } // namespace appcache | 124 } // namespace appcache |
| OLD | NEW |