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, 44 const base::string16& title); 45 void Remove(BackgroundContents* background_contents); 46 47 void AddToTaskManager(BackgroundContents* background_contents, 48 const base::string16& title); 49 50 // Whether we are currently reporting to the task manager. Used to ignore 51 // notifications sent after StopUpdating(). 52 bool updating_; 53 54 TaskManager* task_manager_; 55 56 // Maps the actual resources (the BackgroundContents) to the Task Manager 57 // resources. 58 typedef std::map<BackgroundContents*, BackgroundContentsResource*> 59 Resources; 60 Resources resources_; 61 62 // A scoped container for notification registries. 63 content::NotificationRegistrar registrar_; 64 65 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsResourceProvider); 66 }; 67 68 } // namespace task_manager 69 70 #endif // CHROME_BROWSER_TASK_MANAGER_BACKGROUND_RESOURCE_PROVIDER_H_ 71