appcache_frontend_impl.cc revision f2477e01787aa58f445919b809d89e252beef54f
1ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/child/appcache/appcache_frontend_impl.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/logging.h" 8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/child/appcache/web_application_cache_host_impl.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebApplicationCacheHost.h" 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebConsoleMessage.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebApplicationCacheHost; 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebConsoleMessage; 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 15ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace content { 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Inline helper to keep the lines shorter and unwrapped. 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline WebApplicationCacheHostImpl* GetHost(int id) { 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return WebApplicationCacheHostImpl::FromId(id); 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid AppCacheFrontendImpl::OnCacheSelected(int host_id, 23ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const appcache::AppCacheInfo& info) { 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnCacheSelected(info); 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids, 30ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch appcache::Status status) { 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnStatusChanged(status); 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, 40ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch appcache::EventID event_id) { 41ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch DCHECK(event_id != appcache::PROGRESS_EVENT); // See OnProgressEventRaised. 42ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch DCHECK(event_id != appcache::ERROR_EVENT); // See OnErrorEventRaised. 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnEventRaised(event_id); 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnProgressEventRaised( 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::vector<int>& host_ids, 53ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const GURL& url, 54ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch int num_total, 55ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch int num_complete) { 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnProgressEventRaised(url, num_total, num_complete); 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 64ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid AppCacheFrontendImpl::OnErrorEventRaised(const std::vector<int>& host_ids, 65ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const std::string& message) { 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnErrorEventRaised(message); 71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 74ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid AppCacheFrontendImpl::OnLogMessage(int host_id, 75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch appcache::LogLevel log_level, 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string& message) { 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnLogMessage(log_level, message); 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnContentBlocked(int host_id, 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& manifest_url) { 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnContentBlocked(manifest_url); 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure that enum values never get out of sync with the 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// ones declared for use within the WebKit api 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached == 92ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::UNCACHED, Uncached); 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Idle == 94ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::IDLE, Idle); 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Checking == 96ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::CHECKING, Checking); 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading == 98ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::DOWNLOADING, Downloading); 99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady == 100ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::UPDATE_READY, UpdateReady); 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete == 102ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::OBSOLETE, Obsolete); 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent == 104ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::CHECKING_EVENT, CheckingEvent); 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent == 106ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::ERROR_EVENT, ErrorEvent); 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent == 108ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::NO_UPDATE_EVENT, NoUpdateEvent); 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent == 110ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::DOWNLOADING_EVENT, DownloadingEvent); 111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent == 112ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::PROGRESS_EVENT, ProgressEvent); 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent == 114ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::UPDATE_READY_EVENT, UpdateReadyEvent); 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent == 116ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::CACHED_EVENT, CachedEvent); 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent == 118ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::OBSOLETE_EVENT, ObsoleteEvent); 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug == 120ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::LOG_DEBUG, LevelDebug); 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelLog == 122ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::LOG_INFO, LevelLog); 123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning == 124ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::LOG_WARNING, LevelWarning); 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelError == 126ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch (int)appcache::LOG_ERROR, LevelError); 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 128ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch} // namespace content 129