| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_ | |
| 6 #define CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "chrome/browser/task_manager/renderer_resource.h" | |
| 13 #include "chrome/browser/task_manager/resource_provider.h" | |
| 14 | |
| 15 class TaskManager; | |
| 16 | |
| 17 namespace content { | |
| 18 class RenderFrameHost; | |
| 19 class SiteInstance; | |
| 20 class WebContents; | |
| 21 } | |
| 22 | |
| 23 namespace task_manager { | |
| 24 | |
| 25 class RendererResource; | |
| 26 class TaskManagerWebContentsEntry; | |
| 27 class WebContentsInformation; | |
| 28 | |
| 29 // Provides resources to the task manager on behalf of a chrome service that | |
| 30 // owns WebContentses. The chrome service is parameterized as a | |
| 31 // WebContentsInformation, which provides a list of WebContentses to track. | |
| 32 // | |
| 33 // This ResourceProvider is instantiated several times by the task manager, each | |
| 34 // with a different implementation of WebContentsInformation. | |
| 35 class WebContentsResourceProvider : public ResourceProvider { | |
| 36 public: | |
| 37 WebContentsResourceProvider(TaskManager* task_manager, | |
| 38 std::unique_ptr<WebContentsInformation> info); | |
| 39 | |
| 40 // ResourceProvider implementation. | |
| 41 RendererResource* GetResource(int origin_pid, | |
| 42 int child_id, | |
| 43 int route_id) override; | |
| 44 void StartUpdating() override; | |
| 45 void StopUpdating() override; | |
| 46 | |
| 47 // Start observing |web_contents| for changes via WebContentsObserver, and | |
| 48 // add it to the task manager. | |
| 49 void OnWebContentsCreated(content::WebContents* web_contents); | |
| 50 | |
| 51 // Remove a TaskManagerWebContentsEntry from our tracking list, and delete it. | |
| 52 void DeleteEntry(content::WebContents* web_contents, | |
| 53 TaskManagerWebContentsEntry* entry); | |
| 54 | |
| 55 TaskManager* task_manager() { return task_manager_; } | |
| 56 WebContentsInformation* info() { return info_.get(); } | |
| 57 | |
| 58 protected: | |
| 59 ~WebContentsResourceProvider() override; | |
| 60 | |
| 61 private: | |
| 62 typedef std::map<content::WebContents*, TaskManagerWebContentsEntry*> | |
| 63 EntryMap; | |
| 64 | |
| 65 TaskManager* task_manager_; | |
| 66 | |
| 67 // For every WebContents we maintain an entry, which holds the task manager's | |
| 68 // RendererResources for that WebContents, and observes the WebContents for | |
| 69 // changes. | |
| 70 EntryMap entries_; | |
| 71 | |
| 72 // The WebContentsInformation that informs us when a new WebContents* is | |
| 73 // created, and which serves as a RendererResource factory for our type. | |
| 74 std::unique_ptr<WebContentsInformation> info_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(WebContentsResourceProvider); | |
| 77 }; | |
| 78 | |
| 79 } // namespace task_manager | |
| 80 | |
| 81 #endif // CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_RESOURCE_PROVIDER_H_ | |
| OLD | NEW |