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_INFORMATION_H_
6 #define CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_INFORMATION_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
18 namespace task_manager
{
20 class RendererResource
;
22 // This interface gives a WebContentsResourceProvider information about a
23 // category of WebContentses owned by some service. The instances are expected
24 // to be owned by their WebContentsResourceProvider, which will track and adapt
25 // the WebContentses into TaskManager resources.
26 class WebContentsInformation
{
28 typedef base::Callback
<void(content::WebContents
*)> NewWebContentsCallback
;
30 WebContentsInformation();
31 virtual ~WebContentsInformation();
33 // Retrieve all known WebContents instances from the service we're tracking.
34 // Invoke |callback| on each one.
35 virtual void GetAll(const NewWebContentsCallback
& callback
) = 0;
37 // Return true if |web_contents| is from the service we're tracking.
38 virtual bool CheckOwnership(content::WebContents
* web_contents
) = 0;
40 // Start listening to the creation of new WebContents instances from
41 // the service. While listening, invoke |callback| on each new instance.
42 virtual void StartObservingCreation(
43 const NewWebContentsCallback
& callback
) = 0;
45 // Stop listening to creation of new WebContents instances.
46 virtual void StopObservingCreation() = 0;
48 // Create a new task manager resource for the given WebContents instance.
49 virtual scoped_ptr
<RendererResource
> MakeResource(
50 content::WebContents
* web_contents
) = 0;
53 DISALLOW_COPY_AND_ASSIGN(WebContentsInformation
);
56 // Implements the observer methods (StartObservingCreation() /
57 // StopObservingCreation()) of WebContentsInformation using
58 // NOTIFICATION_WEB_CONTENTS_CONNECTED.
59 class NotificationObservingWebContentsInformation
60 : public WebContentsInformation
,
61 public content::NotificationObserver
{
63 NotificationObservingWebContentsInformation();
64 virtual ~NotificationObservingWebContentsInformation();
66 // WebContentsInformation partial implementation.
67 virtual void StartObservingCreation(const NewWebContentsCallback
& callback
)
69 virtual void StopObservingCreation() OVERRIDE
;
71 // content::NotificationObserver implementation.
72 virtual void Observe(int type
,
73 const content::NotificationSource
& source
,
74 const content::NotificationDetails
& details
) OVERRIDE
;
77 content::NotificationRegistrar registrar_
;
78 NewWebContentsCallback observer_callback_
;
79 DISALLOW_COPY_AND_ASSIGN(NotificationObservingWebContentsInformation
);
82 } // namespace task_manager
84 #endif // CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_INFORMATION_H_