| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/appcache/web_application_cache_host_impl.h" | 5 #include "webkit/appcache/web_application_cache_host_impl.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" |
| 10 #include "base/singleton.h" | 11 #include "base/singleton.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 16 | 17 |
| 17 using WebKit::WebApplicationCacheHost; | 18 using WebKit::WebApplicationCacheHost; |
| 18 using WebKit::WebApplicationCacheHostClient; | 19 using WebKit::WebApplicationCacheHostClient; |
| 19 using WebKit::WebDataSource; | 20 using WebKit::WebDataSource; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 status_ = status; | 102 status_ = status; |
| 102 } | 103 } |
| 103 | 104 |
| 104 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { | 105 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { |
| 105 DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. | 106 DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. |
| 106 DCHECK(event_id != ERROR_EVENT); // See OnErrorEventRaised. | 107 DCHECK(event_id != ERROR_EVENT); // See OnErrorEventRaised. |
| 107 | 108 |
| 108 // Emit logging output prior to calling out to script as we can get | 109 // Emit logging output prior to calling out to script as we can get |
| 109 // deleted within the script event handler. | 110 // deleted within the script event handler. |
| 110 const char* kFormatString = "Application Cache %s event"; | 111 const char* kFormatString = "Application Cache %s event"; |
| 111 std::string message = StringPrintf(kFormatString, kEventNames[event_id]); | 112 std::string message = base::StringPrintf(kFormatString, |
| 113 kEventNames[event_id]); |
| 112 OnLogMessage(LOG_INFO, message); | 114 OnLogMessage(LOG_INFO, message); |
| 113 | 115 |
| 114 // Most events change the status. Clear out what we know so that the latest | 116 // Most events change the status. Clear out what we know so that the latest |
| 115 // status will be obtained from the backend. | 117 // status will be obtained from the backend. |
| 116 has_status_ = false; | 118 has_status_ = false; |
| 117 has_cached_status_ = false; | 119 has_cached_status_ = false; |
| 118 client_->notifyEventListener(static_cast<EventID>(event_id)); | 120 client_->notifyEventListener(static_cast<EventID>(event_id)); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void WebApplicationCacheHostImpl::OnProgressEventRaised( | 123 void WebApplicationCacheHostImpl::OnProgressEventRaised( |
| 122 const GURL& url, int num_total, int num_complete) { | 124 const GURL& url, int num_total, int num_complete) { |
| 123 // Emit logging output prior to calling out to script as we can get | 125 // Emit logging output prior to calling out to script as we can get |
| 124 // deleted within the script event handler. | 126 // deleted within the script event handler. |
| 125 const char* kFormatString = "Application Cache Progress event (%d of %d) %s"; | 127 const char* kFormatString = "Application Cache Progress event (%d of %d) %s"; |
| 126 std::string message = StringPrintf(kFormatString, num_complete, | 128 std::string message = base::StringPrintf(kFormatString, num_complete, |
| 127 num_total, url.spec().c_str()); | 129 num_total, url.spec().c_str()); |
| 128 OnLogMessage(LOG_INFO, message); | 130 OnLogMessage(LOG_INFO, message); |
| 129 | 131 |
| 130 client_->notifyProgressEventListener(url, num_total, num_complete); | 132 client_->notifyProgressEventListener(url, num_total, num_complete); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void WebApplicationCacheHostImpl::OnErrorEventRaised( | 135 void WebApplicationCacheHostImpl::OnErrorEventRaised( |
| 134 const std::string& message) { | 136 const std::string& message) { |
| 135 // Emit logging output prior to calling out to script as we can get | 137 // Emit logging output prior to calling out to script as we can get |
| 136 // deleted within the script event handler. | 138 // deleted within the script event handler. |
| 137 const char* kFormatString = "Application Cache Error event: %s"; | 139 const char* kFormatString = "Application Cache Error event: %s"; |
| 138 std::string full_message = StringPrintf(kFormatString, message.c_str()); | 140 std::string full_message = base::StringPrintf(kFormatString, |
| 141 message.c_str()); |
| 139 OnLogMessage(LOG_ERROR, full_message); | 142 OnLogMessage(LOG_ERROR, full_message); |
| 140 | 143 |
| 141 // Most events change the status. Clear out what we know so that the latest | 144 // Most events change the status. Clear out what we know so that the latest |
| 142 // status will be obtained from the backend. | 145 // status will be obtained from the backend. |
| 143 has_status_ = false; | 146 has_status_ = false; |
| 144 has_cached_status_ = false; | 147 has_cached_status_ = false; |
| 145 client_->notifyEventListener(static_cast<EventID>(ERROR_EVENT)); | 148 client_->notifyEventListener(static_cast<EventID>(ERROR_EVENT)); |
| 146 } | 149 } |
| 147 | 150 |
| 148 void WebApplicationCacheHostImpl::willStartMainResourceRequest( | 151 void WebApplicationCacheHostImpl::willStartMainResourceRequest( |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 310 |
| 308 bool WebApplicationCacheHostImpl::swapCache() { | 311 bool WebApplicationCacheHostImpl::swapCache() { |
| 309 // Cache status will change when cache is swapped. Clear out any saved idea | 312 // Cache status will change when cache is swapped. Clear out any saved idea |
| 310 // of status so that backend will be queried for actual status. | 313 // of status so that backend will be queried for actual status. |
| 311 has_status_ = false; | 314 has_status_ = false; |
| 312 has_cached_status_ = false; | 315 has_cached_status_ = false; |
| 313 return backend_->SwapCache(host_id_); | 316 return backend_->SwapCache(host_id_); |
| 314 } | 317 } |
| 315 | 318 |
| 316 } // appcache namespace | 319 } // appcache namespace |
| OLD | NEW |