summaryrefslogtreecommitdiffstats
path: root/chrome/browser/task_manager/web_contents_resource_provider.h
blob: 4d3d365f3d9707d8a85f6d089652c6178e44980a (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
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 2014 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 CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_
#define CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_

#include <map>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/task_manager/renderer_resource.h"
#include "chrome/browser/task_manager/resource_provider.h"

class TaskManager;

namespace content {
class RenderFrameHost;
class SiteInstance;
class WebContents;
}

namespace task_manager {

class RendererResource;
class TaskManagerWebContentsEntry;
class WebContentsInformation;

// Provides resources to the task manager on behalf of a chrome service that
// owns WebContentses. The chrome service is parameterized as a
// WebContentsInformation, which provides a list of WebContentses to track.
//
// This ResourceProvider is instantiated several times by the task manager, each
// with a different implementation of WebContentsInformation.
class WebContentsResourceProvider : public ResourceProvider {
 public:
  WebContentsResourceProvider(TaskManager* task_manager,
                              scoped_ptr<WebContentsInformation> info);

  // ResourceProvider implementation.
  RendererResource* GetResource(int origin_pid,
                                int child_id,
                                int route_id) override;
  void StartUpdating() override;
  void StopUpdating() override;

  // Start observing |web_contents| for changes via WebContentsObserver, and
  // add it to the task manager.
  void OnWebContentsCreated(content::WebContents* web_contents);

  // Remove a TaskManagerWebContentsEntry from our tracking list, and delete it.
  void DeleteEntry(content::WebContents* web_contents,
                   TaskManagerWebContentsEntry* entry);

  TaskManager* task_manager() { return task_manager_; }
  WebContentsInformation* info() { return info_.get(); }

 protected:
  ~WebContentsResourceProvider() override;

 private:
  typedef std::map<content::WebContents*, TaskManagerWebContentsEntry*>
      EntryMap;

  TaskManager* task_manager_;

  // For every WebContents we maintain an entry, which holds the task manager's
  // RendererResources for that WebContents, and observes the WebContents for
  // changes.
  EntryMap entries_;

  // The WebContentsInformation that informs us when a new WebContents* is
  // created, and which serves as a RendererResource factory for our type.
  scoped_ptr<WebContentsInformation> info_;

  DISALLOW_COPY_AND_ASSIGN(WebContentsResourceProvider);
};

}  // namespace task_manager

#endif  // CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_