File: kiosk_session_plugin_handler.cc

package info (click to toggle)
chromium 140.0.7339.127-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,192,880 kB
  • sloc: cpp: 35,093,808; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/app_mode/kiosk_session_plugin_handler.h"

#include <algorithm>

#include "base/functional/bind.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/app_mode/kiosk_session_plugin_handler_delegate.h"

namespace chromeos {

KioskSessionPluginHandler::Observer::Observer(content::WebContents* contents,
                                              KioskSessionPluginHandler* owner)
    : content::WebContentsObserver(contents), owner_(owner) {}

KioskSessionPluginHandler::Observer::~Observer() = default;

std::set<int> KioskSessionPluginHandler::Observer::GetHungPluginsForTesting()
    const {
  return hung_plugins_;
}

void KioskSessionPluginHandler::Observer::OnHungWaitTimer() {
  owner_->OnPluginHung(hung_plugins_);
}

void KioskSessionPluginHandler::Observer::WebContentsDestroyed() {
  owner_->OnWebContentsDestroyed(this);
}

std::vector<KioskSessionPluginHandler::Observer*>
KioskSessionPluginHandler::GetWatchersForTesting() const {
  std::vector<KioskSessionPluginHandler::Observer*> observers;
  for (const auto& watcher : watchers_) {
    observers.push_back(watcher.get());
  }
  return observers;
}

KioskSessionPluginHandler::KioskSessionPluginHandler(
    KioskSessionPluginHandlerDelegate* delegate)
    : delegate_(delegate) {}

KioskSessionPluginHandler::~KioskSessionPluginHandler() = default;

void KioskSessionPluginHandler::Observe(content::WebContents* contents) {
  watchers_.push_back(std::make_unique<Observer>(contents, this));
}

void KioskSessionPluginHandler::OnPluginCrashed(
    const base::FilePath& plugin_path) {
  delegate_->OnPluginCrashed(plugin_path);
}

void KioskSessionPluginHandler::OnPluginHung(
    const std::set<int>& hung_plugins) {
  delegate_->OnPluginHung(hung_plugins);
}

void KioskSessionPluginHandler::OnWebContentsDestroyed(Observer* observer) {
  for (auto it = watchers_.begin(); it != watchers_.end(); ++it) {
    if (it->get() == observer) {
      it->release();
      watchers_.erase(it);

      // Schedule the delete later after `observer`'s WebContentsDestroyed
      // finishes.
      base::SingleThreadTaskRunner::GetCurrentDefault()->DeleteSoon(FROM_HERE,
                                                                    observer);

      return;
    }
  }
}

}  // namespace chromeos