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)); | |
jochen (gone - plz use gerrit)
2011/01/07 14:58:01
hum, you include a reference to a temporary object
pastarmovj
2011/01/07 15:15:35
Actually if I follow the logic of NewRunnableFunct
michaeln
2011/01/07 19:53:05
Yes, const T& is fine here. I think you could also
| |
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_ , |
jochen (gone - plz use gerrit)
2011/01/07 14:58:01
no space before ,
pastarmovj
2011/01/07 15:15:35
Done.
| |
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()) { | |
65 BrowserThread::PostTask( | |
66 BrowserThread::IO, FROM_HERE, | |
67 NewRunnableFunction(DeleteLocalStateOnIOThread, cache_path_)); | |
68 } | |
46 } | 69 } |
47 | 70 |
48 void ChromeAppCacheService::SetOriginQuotaInMemory( | 71 void ChromeAppCacheService::SetOriginQuotaInMemory( |
49 const GURL& origin, int64 quota) { | 72 const GURL& origin, int64 quota) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
51 if (storage()) | 74 if (storage()) |
52 storage()->SetOriginQuotaInMemory(origin, quota); | 75 storage()->SetOriginQuotaInMemory(origin, quota); |
53 } | 76 } |
54 | 77 |
55 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { | 78 void ChromeAppCacheService::ResetOriginQuotaInMemory(const GURL& origin) { |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
57 if (storage()) | 80 if (storage()) |
58 storage()->ResetOriginQuotaInMemory(origin); | 81 storage()->ResetOriginQuotaInMemory(origin); |
59 } | 82 } |
60 | 83 |
61 // static | 84 void ChromeAppCacheService::SetClearLocalStateOnExit(bool clear_local_state) { |
62 void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { | 85 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
63 file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); | 86 BrowserThread::PostTask( |
87 BrowserThread::IO, FROM_HERE, | |
88 NewRunnableMethod(this, | |
89 &ChromeAppCacheService::SetClearLocalStateOnExit, | |
90 clear_local_state)); | |
91 return; | |
92 } | |
93 clear_local_state_on_exit_ = clear_local_state; | |
64 } | 94 } |
65 | 95 |
66 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { | 96 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
68 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | 98 ContentSetting setting = host_contents_settings_map_->GetContentSetting( |
69 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 99 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
70 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 100 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
71 // We don't prompt for read access. | 101 // We don't prompt for read access. |
72 return setting != CONTENT_SETTING_BLOCK; | 102 return setting != CONTENT_SETTING_BLOCK; |
73 } | 103 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 const tracked_objects::Location& from_here, | 137 const tracked_objects::Location& from_here, |
108 Task* task) { | 138 Task* task) { |
109 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); | 139 return BrowserThread::PostTask(ToBrowserThreadID(id), from_here, task); |
110 } | 140 } |
111 | 141 |
112 bool AppCacheThread::CurrentlyOn(int id) { | 142 bool AppCacheThread::CurrentlyOn(int id) { |
113 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); | 143 return BrowserThread::CurrentlyOn(ToBrowserThreadID(id)); |
114 } | 144 } |
115 | 145 |
116 } // namespace appcache | 146 } // namespace appcache |
OLD | NEW |