summaryrefslogtreecommitdiffstats
path: root/ios/web/web_view_counter_impl.h
blob: 34d1f02344aabba48342fcaf84cb9c154172f2cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_WEB_WEB_VIEW_COUNTER_IMPL_H_
#define IOS_WEB_WEB_VIEW_COUNTER_IMPL_H_

#include <stddef.h>
#import <WebKit/WebKit.h>

#include "base/macros.h"
#include "base/supports_user_data.h"
#include "ios/web/public/web_view_counter.h"
#import "ios/web/weak_nsobject_counter.h"

namespace web {

class WebViewCounterImpl : public WebViewCounter,
                           public base::SupportsUserData::Data {
 public:
  WebViewCounterImpl();
  ~WebViewCounterImpl() override;

  // Returns the WebViewCounterImpl for the given |browser_state|. Lazily
  // attaches one if it does not exist. |browser_state| cannot be null.
  static web::WebViewCounterImpl* FromBrowserState(
      web::BrowserState* browser_state);

  // WebViewCounter methods.
  size_t GetWKWebViewCount() override;

  // Inserts a WKWebView for tracking. |wk_web_view| cannot be null.
  void InsertWKWebView(WKWebView* wk_web_view);

 private:
  // The WeakNSObjectCounter that counts WKWebViews.
  WeakNSObjectCounter wk_web_view_counter_;

  DISALLOW_COPY_AND_ASSIGN(WebViewCounterImpl);
};

}  // namespace web

#endif  // IOS_WEB_WEB_VIEW_COUNTER_IMPL_H_