Chromium Code Reviews| 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 auto index = g_appcache_handle_map.Get().find(appcache_host_id_); | |
|
michaeln
2016/12/06 21:10:46
does .erase(id) work?
ananta
2016/12/06 21:38:05
Done.
| |
| 47 g_appcache_handle_map.Get().erase(index); | |
| 48 } | |
| 49 | |
| 50 void AppCacheNavigationHandleCore::Initialize() { | |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 52 DCHECK(precreated_host_.get() == nullptr); | |
| 53 precreated_host_.reset( | |
| 54 new AppCacheHost(appcache_host_id_, this, GetAppCacheService())); | |
| 55 | |
| 56 DCHECK(g_appcache_handle_map.Get().find(appcache_host_id_) == | |
| 57 g_appcache_handle_map.Get().end()); | |
| 58 g_appcache_handle_map.Get()[appcache_host_id_] = this; | |
| 59 } | |
| 60 | |
| 61 // static | |
| 62 std::unique_ptr<AppCacheHost> AppCacheNavigationHandleCore::GetPrecreatedHost( | |
| 63 int host_id) { | |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 65 auto index = g_appcache_handle_map.Get().find(host_id); | |
| 66 if (index != g_appcache_handle_map.Get().end()) { | |
| 67 AppCacheNavigationHandleCore* instance = index->second; | |
| 68 DCHECK(instance); | |
| 69 return std::move(instance->precreated_host_); | |
|
michaeln
2016/12/06 21:10:46
ah... you leave the entry in the map but with a nu
ananta
2016/12/06 21:38:05
Yes. The map entry will go away when the object is
| |
| 70 } | |
| 71 return std::unique_ptr<AppCacheHost>(); | |
| 72 } | |
| 73 | |
| 74 AppCacheServiceImpl* AppCacheNavigationHandleCore::GetAppCacheService() { | |
| 75 return static_cast<AppCacheServiceImpl*>(appcache_service_.get()); | |
| 76 } | |
| 77 | |
| 78 void AppCacheNavigationHandleCore::OnCacheSelected(int host_id, | |
| 79 const AppCacheInfo& info) { | |
| 80 DCHECK(false); | |
| 81 } | |
| 82 | |
| 83 void AppCacheNavigationHandleCore::OnStatusChanged( | |
| 84 const std::vector<int>& host_ids, | |
| 85 AppCacheStatus status) { | |
| 86 // Should never be called. | |
| 87 DCHECK(false); | |
| 88 } | |
| 89 | |
| 90 void AppCacheNavigationHandleCore::OnEventRaised( | |
| 91 const std::vector<int>& host_ids, | |
| 92 AppCacheEventID event_id) { | |
| 93 // Should never be called. | |
| 94 DCHECK(false); | |
| 95 } | |
| 96 | |
| 97 void AppCacheNavigationHandleCore::OnProgressEventRaised( | |
| 98 const std::vector<int>& host_ids, | |
| 99 const GURL& url, | |
| 100 int num_total, | |
| 101 int num_complete) { | |
| 102 // Should never be called. | |
| 103 DCHECK(false); | |
| 104 } | |
| 105 | |
| 106 void AppCacheNavigationHandleCore::OnErrorEventRaised( | |
| 107 const std::vector<int>& host_ids, | |
| 108 const AppCacheErrorDetails& details) { | |
| 109 // Should never be called. | |
| 110 DCHECK(false); | |
| 111 } | |
| 112 | |
| 113 void AppCacheNavigationHandleCore::OnLogMessage(int host_id, | |
| 114 AppCacheLogLevel log_level, | |
| 115 const std::string& message) { | |
| 116 // Should never be called. | |
| 117 DCHECK(false); | |
| 118 } | |
| 119 | |
| 120 void AppCacheNavigationHandleCore::OnContentBlocked(int host_id, | |
| 121 const GURL& manifest_url) { | |
| 122 // Should never be called. | |
| 123 DCHECK(false); | |
| 124 } | |
| 125 | |
| 126 } // namespace content | |
| OLD | NEW |