1 // Copyright 2013 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.
5 #include "content/child/appcache/appcache_frontend_impl.h"
7 #include "base/logging.h"
8 #include "content/child/appcache/web_application_cache_host_impl.h"
9 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
11 using blink::WebApplicationCacheHost;
12 using blink::WebConsoleMessage;
16 // Inline helper to keep the lines shorter and unwrapped.
17 inline WebApplicationCacheHostImpl* GetHost(int id) {
18 return WebApplicationCacheHostImpl::FromId(id);
21 void AppCacheFrontendImpl::OnCacheSelected(int host_id,
22 const appcache::AppCacheInfo& info) {
23 WebApplicationCacheHostImpl* host = GetHost(host_id);
25 host->OnCacheSelected(info);
28 void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids,
29 appcache::Status status) {
30 for (std::vector<int>::const_iterator i = host_ids.begin();
31 i != host_ids.end(); ++i) {
32 WebApplicationCacheHostImpl* host = GetHost(*i);
34 host->OnStatusChanged(status);
38 void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids,
39 appcache::EventID event_id) {
40 DCHECK(event_id != appcache::PROGRESS_EVENT); // See OnProgressEventRaised.
41 DCHECK(event_id != appcache::ERROR_EVENT); // See OnErrorEventRaised.
42 for (std::vector<int>::const_iterator i = host_ids.begin();
43 i != host_ids.end(); ++i) {
44 WebApplicationCacheHostImpl* host = GetHost(*i);
46 host->OnEventRaised(event_id);
50 void AppCacheFrontendImpl::OnProgressEventRaised(
51 const std::vector<int>& host_ids,
55 for (std::vector<int>::const_iterator i = host_ids.begin();
56 i != host_ids.end(); ++i) {
57 WebApplicationCacheHostImpl* host = GetHost(*i);
59 host->OnProgressEventRaised(url, num_total, num_complete);
63 void AppCacheFrontendImpl::OnErrorEventRaised(
64 const std::vector<int>& host_ids,
65 const appcache::ErrorDetails& details) {
66 for (std::vector<int>::const_iterator i = host_ids.begin();
67 i != host_ids.end(); ++i) {
68 WebApplicationCacheHostImpl* host = GetHost(*i);
70 host->OnErrorEventRaised(details);
74 void AppCacheFrontendImpl::OnLogMessage(int host_id,
75 appcache::LogLevel log_level,
76 const std::string& message) {
77 WebApplicationCacheHostImpl* host = GetHost(host_id);
79 host->OnLogMessage(log_level, message);
82 void AppCacheFrontendImpl::OnContentBlocked(int host_id,
83 const GURL& manifest_url) {
84 WebApplicationCacheHostImpl* host = GetHost(host_id);
86 host->OnContentBlocked(manifest_url);
89 // Ensure that enum values never get out of sync with the
90 // ones declared for use within the WebKit api
91 COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached ==
92 (int)appcache::UNCACHED, Uncached);
93 COMPILE_ASSERT((int)WebApplicationCacheHost::Idle ==
94 (int)appcache::IDLE, Idle);
95 COMPILE_ASSERT((int)WebApplicationCacheHost::Checking ==
96 (int)appcache::CHECKING, Checking);
97 COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading ==
98 (int)appcache::DOWNLOADING, Downloading);
99 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady ==
100 (int)appcache::UPDATE_READY, UpdateReady);
101 COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete ==
102 (int)appcache::OBSOLETE, Obsolete);
104 COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent ==
105 (int)appcache::CHECKING_EVENT, CheckingEvent);
106 COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent ==
107 (int)appcache::ERROR_EVENT, ErrorEvent);
108 COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent ==
109 (int)appcache::NO_UPDATE_EVENT, NoUpdateEvent);
110 COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent ==
111 (int)appcache::DOWNLOADING_EVENT, DownloadingEvent);
112 COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent ==
113 (int)appcache::PROGRESS_EVENT, ProgressEvent);
114 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent ==
115 (int)appcache::UPDATE_READY_EVENT, UpdateReadyEvent);
116 COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent ==
117 (int)appcache::CACHED_EVENT, CachedEvent);
118 COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent ==
119 (int)appcache::OBSOLETE_EVENT, ObsoleteEvent);
121 COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug ==
122 (int)appcache::LOG_DEBUG, LevelDebug);
123 COMPILE_ASSERT((int)WebConsoleMessage::LevelLog ==
124 (int)appcache::LOG_INFO, LevelLog);
125 COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning ==
126 (int)appcache::LOG_WARNING, LevelWarning);
127 COMPILE_ASSERT((int)WebConsoleMessage::LevelError ==
128 (int)appcache::LOG_ERROR, LevelError);
130 COMPILE_ASSERT((int)WebApplicationCacheHost::ManifestError ==
131 (int)appcache::MANIFEST_ERROR,
133 COMPILE_ASSERT((int)WebApplicationCacheHost::SignatureError ==
134 (int)appcache::SIGNATURE_ERROR,
136 COMPILE_ASSERT((int)WebApplicationCacheHost::ResourceError ==
137 (int)appcache::RESOURCE_ERROR,
139 COMPILE_ASSERT((int)WebApplicationCacheHost::ChangedError ==
140 (int)appcache::CHANGED_ERROR,
142 COMPILE_ASSERT((int)WebApplicationCacheHost::AbortError ==
143 (int)appcache::ABORT_ERROR,
145 COMPILE_ASSERT((int)WebApplicationCacheHost::QuotaError ==
146 (int)appcache::QUOTA_ERROR,
148 COMPILE_ASSERT((int)WebApplicationCacheHost::PolicyError ==
149 (int)appcache::POLICY_ERROR,
151 COMPILE_ASSERT((int)WebApplicationCacheHost::UnknownError ==
152 (int)appcache::UNKNOWN_ERROR,
155 } // namespace content