OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/appcache_backend_impl.h" | 5 #include "webkit/appcache/appcache_backend_impl.h" |
6 | 6 |
7 #include "webkit/appcache/appcache_host.h" | 7 #include "base/stl_util-inl.h" |
8 #include "webkit/appcache/appcache.h" | 8 #include "webkit/appcache/appcache.h" |
9 #include "webkit/appcache/appcache_group.h" | 9 #include "webkit/appcache/appcache_group.h" |
10 #include "webkit/appcache/appcache_service.h" | 10 #include "webkit/appcache/appcache_service.h" |
11 #include "webkit/appcache/web_application_cache_host_impl.h" | 11 #include "webkit/appcache/web_application_cache_host_impl.h" |
12 | 12 |
13 namespace appcache { | 13 namespace appcache { |
14 | 14 |
15 AppCacheBackendImpl::~AppCacheBackendImpl() { | 15 AppCacheBackendImpl::~AppCacheBackendImpl() { |
| 16 STLDeleteValues(&hosts_); |
16 if (service_) | 17 if (service_) |
17 service_->UnregisterBackend(this); | 18 service_->UnregisterBackend(this); |
18 } | 19 } |
19 | 20 |
20 void AppCacheBackendImpl::Initialize(AppCacheService* service, | 21 void AppCacheBackendImpl::Initialize(AppCacheService* service, |
21 AppCacheFrontend* frontend, | 22 AppCacheFrontend* frontend, |
22 int process_id) { | 23 int process_id) { |
23 DCHECK(!service_ && !frontend_ && frontend && service); | 24 DCHECK(!service_ && !frontend_ && frontend && service); |
24 service_ = service; | 25 service_ = service; |
25 frontend_ = frontend; | 26 frontend_ = frontend; |
26 process_id_ = process_id; | 27 process_id_ = process_id; |
27 service_->RegisterBackend(this); | 28 service_->RegisterBackend(this); |
28 } | 29 } |
29 | 30 |
30 void AppCacheBackendImpl::RegisterHost(int id) { | 31 bool AppCacheBackendImpl::RegisterHost(int id) { |
31 DCHECK(hosts_.find(id) == hosts_.end()); | 32 if (GetHost(id)) |
32 hosts_.insert(HostMap::value_type(id, AppCacheHost(id, frontend_))); | 33 return false; |
| 34 |
| 35 hosts_.insert( |
| 36 HostMap::value_type(id, new AppCacheHost(id, frontend_, service_))); |
| 37 return true; |
33 } | 38 } |
34 | 39 |
35 void AppCacheBackendImpl::UnregisterHost(int id) { | 40 bool AppCacheBackendImpl::UnregisterHost(int id) { |
36 hosts_.erase(id); | 41 HostMap::iterator found = hosts_.find(id); |
| 42 if (found == hosts_.end()) |
| 43 return false; |
| 44 |
| 45 delete found->second; |
| 46 hosts_.erase(found); |
| 47 return true; |
37 } | 48 } |
38 | 49 |
39 void AppCacheBackendImpl::SelectCache( | 50 bool AppCacheBackendImpl::SelectCache( |
40 int host_id, | 51 int host_id, |
41 const GURL& document_url, | 52 const GURL& document_url, |
42 const int64 cache_document_was_loaded_from, | 53 const int64 cache_document_was_loaded_from, |
43 const GURL& manifest_url) { | 54 const GURL& manifest_url) { |
44 // TODO(michaeln): write me | 55 AppCacheHost* host = GetHost(host_id); |
45 frontend_->OnCacheSelected(host_id, kNoCacheId, UNCACHED); | 56 if (!host) |
| 57 return false; |
| 58 |
| 59 host->SelectCache(document_url, cache_document_was_loaded_from, |
| 60 manifest_url); |
| 61 return true; |
46 } | 62 } |
47 | 63 |
48 void AppCacheBackendImpl::MarkAsForeignEntry( | 64 bool AppCacheBackendImpl::MarkAsForeignEntry( |
49 int host_id, | 65 int host_id, |
50 const GURL& document_url, | 66 const GURL& document_url, |
51 int64 cache_document_was_loaded_from) { | 67 int64 cache_document_was_loaded_from) { |
52 // TODO(michaeln): write me | 68 AppCacheHost* host = GetHost(host_id); |
| 69 if (!host) |
| 70 return false; |
| 71 |
| 72 host->MarkAsForeignEntry(document_url, cache_document_was_loaded_from); |
| 73 return true; |
53 } | 74 } |
54 | 75 |
55 void AppCacheBackendImpl::GetStatusWithCallback( | 76 bool AppCacheBackendImpl::GetStatusWithCallback( |
56 int host_id, GetStatusCallback* callback, void* callback_param) { | 77 int host_id, GetStatusCallback* callback, void* callback_param) { |
57 // TODO(michaeln): write me | 78 AppCacheHost* host = GetHost(host_id); |
58 callback->Run(UNCACHED, callback_param); | 79 if (!host) |
| 80 return false; |
| 81 |
| 82 host->GetStatusWithCallback(callback, callback_param); |
| 83 return true; |
59 } | 84 } |
60 | 85 |
61 void AppCacheBackendImpl::StartUpdateWithCallback( | 86 bool AppCacheBackendImpl::StartUpdateWithCallback( |
62 int host_id, StartUpdateCallback* callback, void* callback_param) { | 87 int host_id, StartUpdateCallback* callback, void* callback_param) { |
63 // TODO(michaeln): write me | 88 AppCacheHost* host = GetHost(host_id); |
64 callback->Run(false, callback_param); | 89 if (!host) |
| 90 return false; |
| 91 |
| 92 host->StartUpdateWithCallback(callback, callback_param); |
| 93 return true; |
65 } | 94 } |
66 | 95 |
67 void AppCacheBackendImpl::SwapCacheWithCallback( | 96 bool AppCacheBackendImpl::SwapCacheWithCallback( |
68 int host_id, SwapCacheCallback* callback, void* callback_param) { | 97 int host_id, SwapCacheCallback* callback, void* callback_param) { |
69 // TODO(michaeln): write me | 98 AppCacheHost* host = GetHost(host_id); |
70 callback->Run(false, callback_param); | 99 if (!host) |
| 100 return false; |
| 101 |
| 102 host->SwapCacheWithCallback(callback, callback_param); |
| 103 return true; |
71 } | 104 } |
72 | 105 |
73 } // namespace appcache | 106 } // namespace appcache |
OLD | NEW |