Home | History | Annotate | Download | only in appcache
      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.
      4 
      5 #include "content/child/appcache/appcache_frontend_impl.h"
      6 
      7 #include "base/logging.h"
      8 #include "content/child/appcache/web_application_cache_host_impl.h"
      9 #include "third_party/WebKit/public/web/WebApplicationCacheHost.h"
     10 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
     11 
     12 using WebKit::WebApplicationCacheHost;
     13 using WebKit::WebConsoleMessage;
     14 
     15 namespace content {
     16 
     17 // Inline helper to keep the lines shorter and unwrapped.
     18 inline WebApplicationCacheHostImpl* GetHost(int id) {
     19   return WebApplicationCacheHostImpl::FromId(id);
     20 }
     21 
     22 void AppCacheFrontendImpl::OnCacheSelected(int host_id,
     23                                            const appcache::AppCacheInfo& info) {
     24   WebApplicationCacheHostImpl* host = GetHost(host_id);
     25   if (host)
     26     host->OnCacheSelected(info);
     27 }
     28 
     29 void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids,
     30                                            appcache::Status status) {
     31   for (std::vector<int>::const_iterator i = host_ids.begin();
     32        i != host_ids.end(); ++i) {
     33     WebApplicationCacheHostImpl* host = GetHost(*i);
     34     if (host)
     35       host->OnStatusChanged(status);
     36   }
     37 }
     38 
     39 void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids,
     40                                          appcache::EventID event_id) {
     41   DCHECK(event_id != appcache::PROGRESS_EVENT);  // See OnProgressEventRaised.
     42   DCHECK(event_id != appcache::ERROR_EVENT);  // See OnErrorEventRaised.
     43   for (std::vector<int>::const_iterator i = host_ids.begin();
     44        i != host_ids.end(); ++i) {
     45     WebApplicationCacheHostImpl* host = GetHost(*i);
     46     if (host)
     47       host->OnEventRaised(event_id);
     48   }
     49 }
     50 
     51 void AppCacheFrontendImpl::OnProgressEventRaised(
     52     const std::vector<int>& host_ids,
     53     const GURL& url,
     54     int num_total,
     55     int num_complete) {
     56   for (std::vector<int>::const_iterator i = host_ids.begin();
     57        i != host_ids.end(); ++i) {
     58     WebApplicationCacheHostImpl* host = GetHost(*i);
     59     if (host)
     60       host->OnProgressEventRaised(url, num_total, num_complete);
     61   }
     62 }
     63 
     64 void AppCacheFrontendImpl::OnErrorEventRaised(const std::vector<int>& host_ids,
     65                                               const std::string& message) {
     66   for (std::vector<int>::const_iterator i = host_ids.begin();
     67        i != host_ids.end(); ++i) {
     68     WebApplicationCacheHostImpl* host = GetHost(*i);
     69     if (host)
     70       host->OnErrorEventRaised(message);
     71   }
     72 }
     73 
     74 void AppCacheFrontendImpl::OnLogMessage(int host_id,
     75                                         appcache::LogLevel log_level,
     76                                         const std::string& message) {
     77   WebApplicationCacheHostImpl* host = GetHost(host_id);
     78   if (host)
     79     host->OnLogMessage(log_level, message);
     80 }
     81 
     82 void AppCacheFrontendImpl::OnContentBlocked(int host_id,
     83                                             const GURL& manifest_url) {
     84   WebApplicationCacheHostImpl* host = GetHost(host_id);
     85   if (host)
     86     host->OnContentBlocked(manifest_url);
     87 }
     88 
     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);
    103 COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent ==
    104                (int)appcache::CHECKING_EVENT, CheckingEvent);
    105 COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent ==
    106                (int)appcache::ERROR_EVENT, ErrorEvent);
    107 COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent ==
    108                (int)appcache::NO_UPDATE_EVENT, NoUpdateEvent);
    109 COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent ==
    110                (int)appcache::DOWNLOADING_EVENT, DownloadingEvent);
    111 COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent ==
    112                (int)appcache::PROGRESS_EVENT, ProgressEvent);
    113 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent ==
    114                (int)appcache::UPDATE_READY_EVENT, UpdateReadyEvent);
    115 COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent ==
    116                (int)appcache::CACHED_EVENT, CachedEvent);
    117 COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent ==
    118                (int)appcache::OBSOLETE_EVENT, ObsoleteEvent);
    119 COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug ==
    120                (int)appcache::LOG_DEBUG, LevelDebug);
    121 COMPILE_ASSERT((int)WebConsoleMessage::LevelLog ==
    122                (int)appcache::LOG_INFO, LevelLog);
    123 COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning ==
    124                (int)appcache::LOG_WARNING, LevelWarning);
    125 COMPILE_ASSERT((int)WebConsoleMessage::LevelError ==
    126                (int)appcache::LOG_ERROR, LevelError);
    127 
    128 }  // namespace content
    129