1 // Copyright 2015 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_TAGS_H_ 6 #define CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_TAGS_H_ 7 8 #include "base/macros.h" 9 #include "extensions/common/view_type.h" 10 11 class BackgroundContents; 12 13 namespace content { 14 class WebContents; 15 } // namespace content 16 17 namespace task_manager { 18 19 // Defines a factory class for creating the TaskManager-specific Tags for the 20 // WebContents that are owned by various types of services. 21 // 22 // Any service or feature that creates WebContents instances (via 23 // WebContents::Create) needs to make sure that they are tagged using this 24 // mechanism, otherwise the associated render processes will not show up in the 25 // task manager. 26 class WebContentsTags { 27 public: 28 // Tag a BackgroundContents so that it shows up in the task manager. Calling 29 // this function creates a BackgroundContentsTag, and attaches it to 30 // |web_contents|. If an instance is already attached, this does nothing. The 31 // resulting tag does not have to be cleaned up by the caller, as it is owned 32 // by |web_contents|. 33 static void CreateForBackgroundContents( 34 content::WebContents* web_contents, 35 BackgroundContents* background_contents); 36 37 // Tag a DevTools WebContents so that it shows up in the task manager. Calling 38 // this function creates a DevToolsTag, and attaches it to |web_contents|. If 39 // an instance is already attached, this does nothing. The resulting tag does 40 // not have to be cleaned up by the caller, as it is owned by |web_contents|. 41 static void CreateForDevToolsContents(content::WebContents* web_contents); 42 43 // Tag a WebContents owned by the PrerenderManager so that it shows up in the 44 // task manager. Calling this function creates a PrerenderTag, and attaches it 45 // to |web_contents|. If an instance is already attached, this does nothing. 46 // The resulting tag does not have to be cleaned up by the caller, as it is 47 // owned by |web_contents|. 48 static void CreateForPrerenderContents(content::WebContents* web_contents); 49 50 // Tag a WebContents owned by the TabStripModel so that it shows up in the 51 // task manager. Calling this function creates a TabContentsTag, and attaches 52 // it to |web_contents|. If an instance is already attached, this does 53 // nothing. The resulting tag does not have to be cleaned up by the caller, as 54 // it is owned by |web_contents|. 55 static void CreateForTabContents(content::WebContents* web_contents); 56 57 // Tag a WebContents created for a print preview or background printing so 58 // that it shows up in the task manager. Calling this function creates a 59 // PrintingTag, and attaches it to |web_contents|. If an instance is already 60 // attached, this does nothing. The resulting tag does not have to be cleaned 61 // up by the caller, as it is owned by |web_contents|. 62 static void CreateForPrintingContents(content::WebContents* web_contents); 63 64 // Tag a WebContents owned by a GuestViewBase so that it shows up in the 65 // task manager. Calling this function creates a GuestTag, and attaches it to 66 // |web_contents|. If an instance is already attached, this does nothing. The 67 // resulting tag does not have to be cleaned up by the caller, as it is owned 68 // by |web_contents|. 69 static void CreateForGuestContents(content::WebContents* web_contents); 70 71 // Tag a WebContents that belongs to |extension| so that it shows up in the 72 // task manager. Calling this function creates a ExtensionTag, and attaches 73 // it to |web_contents|. If an instance is already attached, this does 74 // nothing. The resulting tag does not have to be cleaned up by the caller, 75 // as it is owned by |web_contents|. 76 // |web_contents| must be of a non-tab, non-guest view, or 77 // non-background contents Extension. 78 static void CreateForExtension(content::WebContents* web_contents, 79 extensions::ViewType view_type); 80 81 // Tag a WebContents created for a Portal so that it shows up in the task 82 // manager. Calling this function creates a PortalTag, and attaches it to 83 // |web_contents|. If an instance is already attached, this does nothing. 84 // The resulting tag does not have to be cleaned up by the caller, as it is 85 // owned by |web_contents|. 86 static void CreateForPortal(content::WebContents* web_contents); 87 88 // Tag a WebContents created for a tool so that it shows up in the task 89 // manager. Calling this function creates a ToolTag, and attaches it to 90 // |web_contents|. If an instance is already attached, this does nothing. The 91 // resulting tag does not have to be cleaned up by the caller, as it is owned 92 // by |web_contents|. |tool_name| is the string ID of the name of the tool. 93 static void CreateForToolContents(content::WebContents* web_contents, 94 int tool_name); 95 96 // Clears the task-manager tag, created by any of the above functions, from 97 // the given |web_contents| if any. 98 // Clearing the tag is necessary only when you need to re-tag an existing 99 // WebContents, to indicate a change in ownership. 100 static void ClearTag(content::WebContents* web_contents); 101 102 private: 103 DISALLOW_COPY_AND_ASSIGN(WebContentsTags); 104 }; 105 106 } // namespace task_manager 107 108 #endif // CHROME_BROWSER_TASK_MANAGER_WEB_CONTENTS_TAGS_H_ 109