Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 "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 namespace { | |
| 19 | |
| 20 // Used to defer deleting of local storage until the destructor has finished. | |
| 21 void DeleteLocalStateOnIOThread(FilePath cache_path) { | |
| 22 // Post the actual deletion to the DB thread to ensure it happens after the | |
| 23 // database file has been closed. | |
| 24 BrowserThread::PostTask( | |
| 25 BrowserThread::DB, FROM_HERE, | |
| 26 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>( | |
| 27 &file_util::Delete, cache_path, true)); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 18 // ---------------------------------------------------------------------------- | 32 // ---------------------------------------------------------------------------- |
| 19 | 33 |
| 20 ChromeAppCacheService::ChromeAppCacheService() { | 34 ChromeAppCacheService::ChromeAppCacheService() { |
| 21 } | 35 } |
| 22 | 36 |
| 23 void ChromeAppCacheService::InitializeOnIOThread( | 37 void ChromeAppCacheService::InitializeOnIOThread( |
| 24 const FilePath& profile_path, bool is_incognito, | 38 const FilePath& profile_path, bool is_incognito, |
| 25 scoped_refptr<HostContentSettingsMap> content_settings_map) { | 39 scoped_refptr<HostContentSettingsMap> content_settings_map, |
| 40 bool clear_local_state_on_exit) { | |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 27 | 42 |
| 28 if (!has_initialized_thread_ids) { | 43 if (!has_initialized_thread_ids) { |
| 29 has_initialized_thread_ids = true; | 44 has_initialized_thread_ids = true; |
| 30 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); | 45 appcache::AppCacheThread::Init(BrowserThread::DB, BrowserThread::IO); |
| 31 } | 46 } |
| 32 | 47 |
| 33 host_contents_settings_map_ = content_settings_map; | 48 host_contents_settings_map_ = content_settings_map; |
| 34 registrar_.Add( | 49 registrar_.Add( |
| 35 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); | 50 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); |
| 51 SetClearLocalStateOnExit(clear_local_state_on_exit); | |
| 52 if (!is_incognito) | |
| 53 cache_path_ = profile_path.Append(chrome::kAppCacheDirname); | |
| 36 | 54 |
| 37 // Init our base class. | 55 // Init our base class. |
| 38 Initialize( | 56 Initialize(cache_path_ , |
| 39 is_incognito ? FilePath() : profile_path.Append(chrome::kAppCacheDirname), | 57 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
| 40 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
| 41 set_appcache_policy(this); | 58 set_appcache_policy(this); |
| 42 } | 59 } |
| 43 | 60 |
| 44 ChromeAppCacheService::~ChromeAppCacheService() { | 61 ChromeAppCacheService::~ChromeAppCacheService() { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 63 | |
| 64 if (clear_local_state_on_exit_ && !cache_path_.empty()) | |
|
jochen (gone - plz use gerrit)
2011/01/05 12:29:51
use { ... }.
also, please add an comment why this
pastarmovj
2011/01/05 13:47:38
Done.
| |
| 65 BrowserThread::PostTask( | |
| 66 BrowserThread::IO, FROM_HERE, | |
| 67 NewRunnableFunction(DeleteLocalStateOnIOThread, cache_path_)); | |
| 46 } | 68 } |
| 47 | 69 |
| 48 void ChromeAppCacheService::SetOriginQuotaInMemory( | 70 void ChromeAppCacheService::SetOriginQuotaInMemory( |
| 49 const GURL& origin, int64 quota) { | 71 const GURL& origin, int64 quota) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 51 if (storage()) | 73 if (storage()) |
| 52 storage()->SetOriginQuotaInMemory(origin, quota); | 74 storage()->SetOriginQuotaInMemory(origin, quota); |
| 53 } | 75 } |
| 54 | 76 |
| 55 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { | 77 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 57 if (storage()) | 79 if (storage()) |
| 58 storage()->ResetOriginQuotaInMemory(origin); | 80 storage()->ResetOriginQuotaInMemory(origin); |
| 59 } | 81 } |
| 60 | 82 |
| 61 // static | 83 void ChromeAppCacheService::SetClearLocalStateOnExit(bool clear_local_state) { |
| 62 void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { | 84 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 63 file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); | 85 BrowserThread::PostTask( |
| 86 BrowserThread::IO, FROM_HERE, | |
| 87 NewRunnableMethod(this, | |
| 88 &ChromeAppCacheService::SetClearLocalStateOnExit, | |
| 89 clear_local_state)); | |
| 90 return; | |
| 91 } | |
| 92 clear_local_state_on_exit_ = clear_local_state; | |
| 64 } | 93 } |
| 65 | 94 |
| 66 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { | 95 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 68 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | 97 ContentSetting setting = host_contents_settings_map_->GetContentSetting( |
| 69 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 98 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 70 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 99 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 71 // We don't prompt for read access. | 100 // We don't prompt for read access. |
| 72 return setting != CONTENT_SETTING_BLOCK; | 101 return setting != CONTENT_SETTING_BLOCK; |
| 73 } | 102 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 const tracked_objects::Location& from_here, | 136 const tracked_objects::Location& from_here, |
| 108 Task* task) { | 137 Task* task) { |
| 109 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); | 138 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); |
| 110 } | 139 } |
| 111 | 140 |
| 112 bool AppCacheThread::CurrentlyOn(int id) { | 141 bool AppCacheThread::CurrentlyOn(int id) { |
| 113 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); | 142 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); |
| 114 } | 143 } |
| 115 | 144 |
| 116 } // namespace appcache | 145 } // namespace appcache |
| OLD | NEW |