- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / task_manager / background_resource_provider.h
1 // Copyright 2013 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.
4
5 #ifndef CHROME_BROWSER_TASK_MANAGER_BACKGROUND_RESOURCE_PROVIDER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_BACKGROUND_RESOURCE_PROVIDER_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/task_manager/resource_provider.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15
16 class BackgroundContents;
17 class TaskManager;
18
19 namespace task_manager {
20
21 class BackgroundContentsResource;
22
23 class BackgroundContentsResourceProvider
24     : public ResourceProvider,
25       public content::NotificationObserver {
26  public:
27   explicit BackgroundContentsResourceProvider(TaskManager* task_manager);
28
29   virtual Resource* GetResource(int origin_pid,
30                                 int render_process_host_id,
31                                 int routing_id) OVERRIDE;
32   virtual void StartUpdating() OVERRIDE;
33   virtual void StopUpdating() OVERRIDE;
34
35   // content::NotificationObserver method:
36   virtual void Observe(int type,
37                        const content::NotificationSource& source,
38                        const content::NotificationDetails& details) OVERRIDE;
39
40  private:
41   virtual ~BackgroundContentsResourceProvider();
42
43   void Add(BackgroundContents* background_contents, const string16& title);
44   void Remove(BackgroundContents* background_contents);
45
46   void AddToTaskManager(BackgroundContents* background_contents,
47                         const string16& title);
48
49   // Whether we are currently reporting to the task manager. Used to ignore
50   // notifications sent after StopUpdating().
51   bool updating_;
52
53   TaskManager* task_manager_;
54
55   // Maps the actual resources (the BackgroundContents) to the Task Manager
56   // resources.
57   typedef std::map<BackgroundContents*, BackgroundContentsResource*>
58       Resources;
59   Resources resources_;
60
61   // A scoped container for notification registries.
62   content::NotificationRegistrar registrar_;
63
64   DISALLOW_COPY_AND_ASSIGN(BackgroundContentsResourceProvider);
65 };
66
67 }  // namespace task_manager
68
69 #endif  // CHROME_BROWSER_TASK_MANAGER_BACKGROUND_RESOURCE_PROVIDER_H_