1 // Copyright 2014 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 #ifndef CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/task_manager/renderer_resource.h"
14 #include "chrome/browser/task_manager/resource_provider.h"
22 namespace task_manager
{
24 class RendererResource
;
25 class TaskManagerWebContentsObserver
;
26 class WebContentsInformation
;
28 // Provides resources to the task manager on behalf of a chrome service that
29 // owns WebContentses. The chrome service is parameterized as a
30 // WebContentsInformation, which provides a list of WebContentses to track.
32 // This ResourceProvider is instantiated several times by the task manager, each
33 // with a different implementation of WebContentsInformation.
34 class WebContentsResourceProvider
: public ResourceProvider
{
36 WebContentsResourceProvider(TaskManager
* task_manager
,
37 scoped_ptr
<WebContentsInformation
> info
);
39 // ResourceProvider implementation.
40 virtual RendererResource
* GetResource(int origin_pid
,
42 int route_id
) OVERRIDE
;
43 virtual void StartUpdating() OVERRIDE
;
44 virtual void StopUpdating() OVERRIDE
;
46 // Start observing |web_contents| for changes via WebContentsObserver, and
47 // add it to the task manager.
48 void OnWebContentsCreated(content::WebContents
* web_contents
);
50 // Create TaskManager resources for |web_contents|, and add them to the
52 bool AddToTaskManager(content::WebContents
* web_contents
);
54 // Remove the task manager resources associated with |web_contents|.
55 void RemoveFromTaskManager(content::WebContents
* web_contents
);
57 // Remove a WebContentsObserver from our tracking list, and delete it.
58 void DeleteObserver(TaskManagerWebContentsObserver
* observer
);
61 virtual ~WebContentsResourceProvider();
64 // Whether we are currently reporting to the task manager. Used to ignore
65 // notifications sent after StopUpdating().
68 TaskManager
* task_manager_
;
70 // Maps the actual resources (the WebContentses) to the TaskManager
71 // resources. The RendererResources are owned by us and registered with
73 std::map
<content::WebContents
*, RendererResource
*> resources_
;
75 // Set of current active WebContentsObserver instances owned by this class.
76 std::set
<TaskManagerWebContentsObserver
*> web_contents_observers_
;
78 // The WebContentsInformation that informs us when a new WebContents* is
79 // created, and which serves as a RendererResource factory for our type.
80 scoped_ptr
<WebContentsInformation
> info_
;
82 DISALLOW_COPY_AND_ASSIGN(WebContentsResourceProvider
);
85 } // namespace task_manager
87 #endif // CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_