Infobar material design refresh: bg color
[chromium-blink-merge.git] / ios / web / web_view_counter_impl.mm
blobcd6b825ba4e0c2c8244d51ee2a5144512e6d102c
1 // Copyright 2015 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.
5 #import "ios/web/web_view_counter_impl.h"
7 #include "base/logging.h"
8 #include "ios/web/public/browser_state.h"
9 #include "ios/web/public/web_thread.h"
11 namespace web {
13 namespace {
14 // A key used to associate a WebViewCounter with a BrowserState.
15 const char kWebViewCounterKeyName[] = "web_view_counter";
16 }  // namespace
18 WebViewCounterImpl::WebViewCounterImpl() {
19   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
22 WebViewCounterImpl::~WebViewCounterImpl() {
23   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
26 // static
27 WebViewCounter* WebViewCounter::FromBrowserState(
28     web::BrowserState* browser_state) {
29   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
30   DCHECK(browser_state);
32   return WebViewCounterImpl::FromBrowserState(browser_state);
35 // static
36 WebViewCounterImpl* WebViewCounterImpl::FromBrowserState(
37     web::BrowserState* browser_state) {
38   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
39   DCHECK(browser_state);
41   if (!browser_state->GetUserData(kWebViewCounterKeyName)) {
42     browser_state->SetUserData(kWebViewCounterKeyName,
43                                new WebViewCounterImpl());
44   }
45   return static_cast<WebViewCounterImpl*>(
46       browser_state->GetUserData(kWebViewCounterKeyName));
49 size_t WebViewCounterImpl::GetWKWebViewCount() {
50   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
51   return wk_web_view_counter_.Size();
54 void WebViewCounterImpl::InsertWKWebView(WKWebView* wk_web_view) {
55   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
56   DCHECK(wk_web_view);
57   DCHECK([wk_web_view isKindOfClass:[WKWebView class]]);
59   wk_web_view_counter_.Insert(wk_web_view);
62 }  // namespace web