OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/browser/appcache/appcache_navigation_handle_core.h" |
| 6 |
| 7 #include <map> |
| 8 #include <utility> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" |
| 12 #include "content/browser/appcache/appcache_host.h" |
| 13 #include "content/browser/appcache/appcache_navigation_handle.h" |
| 14 #include "content/browser/appcache/appcache_service_impl.h" |
| 15 #include "content/browser/appcache/chrome_appcache_service.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Map of AppCache host id to the AppCacheNavigationHandleCore instance. |
| 21 // Accessed on the IO thread only. |
| 22 using AppCacheHandleMap = |
| 23 std::map <int, content::AppCacheNavigationHandleCore*>; |
| 24 base::LazyInstance<AppCacheHandleMap> g_appcache_handle_map; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 namespace content { |
| 29 |
| 30 |
| 31 AppCacheNavigationHandleCore::AppCacheNavigationHandleCore( |
| 32 base::WeakPtr<AppCacheNavigationHandle> ui_handle, |
| 33 ChromeAppCacheService* appcache_service, |
| 34 int appcache_host_id) |
| 35 : appcache_service_(appcache_service), |
| 36 appcache_host_id_(appcache_host_id), |
| 37 ui_handle_(ui_handle) { |
| 38 // The AppCacheNavigationHandleCore is created on the UI thread but |
| 39 // should only be accessed from the IO thread afterwards. |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 41 } |
| 42 |
| 43 AppCacheNavigationHandleCore::~AppCacheNavigationHandleCore() { |
| 44 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 45 precreated_host_.reset(nullptr); |
| 46 g_appcache_handle_map.Get().erase(appcache_host_id_); |
| 47 } |
| 48 |
| 49 void AppCacheNavigationHandleCore::Initialize() { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 51 DCHECK(precreated_host_.get() == nullptr); |
| 52 precreated_host_.reset( |
| 53 new AppCacheHost(appcache_host_id_, this, GetAppCacheService())); |
| 54 |
| 55 DCHECK(g_appcache_handle_map.Get().find(appcache_host_id_) == |
| 56 g_appcache_handle_map.Get().end()); |
| 57 g_appcache_handle_map.Get()[appcache_host_id_] = this; |
| 58 } |
| 59 |
| 60 // static |
| 61 std::unique_ptr<AppCacheHost> AppCacheNavigationHandleCore::GetPrecreatedHost( |
| 62 int host_id) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 64 auto index = g_appcache_handle_map.Get().find(host_id); |
| 65 if (index != g_appcache_handle_map.Get().end()) { |
| 66 AppCacheNavigationHandleCore* instance = index->second; |
| 67 DCHECK(instance); |
| 68 return std::move(instance->precreated_host_); |
| 69 } |
| 70 return std::unique_ptr<AppCacheHost>(); |
| 71 } |
| 72 |
| 73 AppCacheServiceImpl* AppCacheNavigationHandleCore::GetAppCacheService() { |
| 74 return static_cast<AppCacheServiceImpl*>(appcache_service_.get()); |
| 75 } |
| 76 |
| 77 void AppCacheNavigationHandleCore::OnCacheSelected(int host_id, |
| 78 const AppCacheInfo& info) { |
| 79 DCHECK(false); |
| 80 } |
| 81 |
| 82 void AppCacheNavigationHandleCore::OnStatusChanged( |
| 83 const std::vector<int>& host_ids, |
| 84 AppCacheStatus status) { |
| 85 // Should never be called. |
| 86 DCHECK(false); |
| 87 } |
| 88 |
| 89 void AppCacheNavigationHandleCore::OnEventRaised( |
| 90 const std::vector<int>& host_ids, |
| 91 AppCacheEventID event_id) { |
| 92 // Should never be called. |
| 93 DCHECK(false); |
| 94 } |
| 95 |
| 96 void AppCacheNavigationHandleCore::OnProgressEventRaised( |
| 97 const std::vector<int>& host_ids, |
| 98 const GURL& url, |
| 99 int num_total, |
| 100 int num_complete) { |
| 101 // Should never be called. |
| 102 DCHECK(false); |
| 103 } |
| 104 |
| 105 void AppCacheNavigationHandleCore::OnErrorEventRaised( |
| 106 const std::vector<int>& host_ids, |
| 107 const AppCacheErrorDetails& details) { |
| 108 // Should never be called. |
| 109 DCHECK(false); |
| 110 } |
| 111 |
| 112 void AppCacheNavigationHandleCore::OnLogMessage(int host_id, |
| 113 AppCacheLogLevel log_level, |
| 114 const std::string& message) { |
| 115 // Should never be called. |
| 116 DCHECK(false); |
| 117 } |
| 118 |
| 119 void AppCacheNavigationHandleCore::OnContentBlocked(int host_id, |
| 120 const GURL& manifest_url) { |
| 121 // Should never be called. |
| 122 DCHECK(false); |
| 123 } |
| 124 |
| 125 } // namespace content |
OLD | NEW |