| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/appcache/chrome_appcache_service.h" | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "chrome/browser/chrome_thread.h" | |
| 10 #include "chrome/browser/net/chrome_url_request_context.h" | |
| 11 #include "chrome/common/chrome_constants.h" | |
| 12 #include "chrome/common/notification_service.h" | |
| 13 #include "net/base/net_errors.h" | |
| 14 #include "webkit/appcache/appcache_thread.h" | |
| 15 | |
| 16 static bool has_initialized_thread_ids; | |
| 17 | |
| 18 ChromeAppCacheService::ChromeAppCacheService( | |
| 19 const FilePath& profile_path, | |
| 20 ChromeURLRequestContext* request_context) { | |
| 21 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 22 DCHECK(request_context); | |
| 23 | |
| 24 if (!has_initialized_thread_ids) { | |
| 25 has_initialized_thread_ids = true; | |
| 26 appcache::AppCacheThread::InitIDs(ChromeThread::DB, ChromeThread::IO); | |
| 27 } | |
| 28 | |
| 29 host_contents_settings_map_ = request_context->host_content_settings_map(); | |
| 30 registrar_.Add( | |
| 31 this, NotificationType::PURGE_MEMORY, NotificationService::AllSources()); | |
| 32 | |
| 33 // Init our base class. | |
| 34 Initialize(request_context->is_off_the_record() ? | |
| 35 FilePath() : profile_path.Append(chrome::kAppCacheDirname)); | |
| 36 set_request_context(request_context); | |
| 37 set_appcache_policy(this); | |
| 38 } | |
| 39 | |
| 40 ChromeAppCacheService::~ChromeAppCacheService() { | |
| 41 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { | |
| 46 file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); | |
| 47 } | |
| 48 | |
| 49 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { | |
| 50 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | |
| 51 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); | |
| 52 DCHECK(setting != CONTENT_SETTING_DEFAULT); | |
| 53 return setting == CONTENT_SETTING_ALLOW || | |
| 54 setting == CONTENT_SETTING_ASK; // we don't prompt for read access | |
| 55 } | |
| 56 | |
| 57 int ChromeAppCacheService::CanCreateAppCache( | |
| 58 const GURL& manifest_url, net::CompletionCallback* callback) { | |
| 59 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | |
| 60 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); | |
| 61 DCHECK(setting != CONTENT_SETTING_DEFAULT); | |
| 62 if (setting == CONTENT_SETTING_ASK) { | |
| 63 // TODO(michaeln): prompt the user, for now we block | |
| 64 setting = CONTENT_SETTING_BLOCK; | |
| 65 } | |
| 66 return (setting != CONTENT_SETTING_BLOCK) ? net::OK : net::ERR_ACCESS_DENIED; | |
| 67 } | |
| 68 | |
| 69 void ChromeAppCacheService::Observe(NotificationType type, | |
| 70 const NotificationSource& source, | |
| 71 const NotificationDetails& details) { | |
| 72 DCHECK(type == NotificationType::PURGE_MEMORY); | |
| 73 PurgeMemory(); | |
| 74 } | |
| 75 | |
| 76 static ChromeThread::ID ToChromeThreadID(int id) { | |
| 77 DCHECK(has_initialized_thread_ids); | |
| 78 DCHECK(id == ChromeThread::DB || id == ChromeThread::IO); | |
| 79 return static_cast<ChromeThread::ID>(id); | |
| 80 } | |
| 81 | |
| 82 namespace appcache { | |
| 83 | |
| 84 // An impl of AppCacheThread we need to provide to the appcache lib. | |
| 85 | |
| 86 bool AppCacheThread::PostTask( | |
| 87 int id, | |
| 88 const tracked_objects::Location& from_here, | |
| 89 Task* task) { | |
| 90 return ChromeThread::PostTask(ToChromeThreadID(id), from_here, task); | |
| 91 } | |
| 92 | |
| 93 bool AppCacheThread::CurrentlyOn(int id) { | |
| 94 return ChromeThread::CurrentlyOn(ToChromeThreadID(id)); | |
| 95 } | |
| 96 | |
| 97 } // namespace appcache | |
| OLD | NEW |