OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEMORY_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_MEMORY_DETAILS_H_ |
6 #define CHROME_BROWSER_MEMORY_DETAILS_H_ | 6 #define CHROME_BROWSER_MEMORY_DETAILS_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/hash_tables.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/site_instance.h" |
| 16 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/process_type.h" | 17 #include "content/public/common/process_type.h" |
14 | 18 |
15 // We collect data about each browser process. A browser may | 19 // We collect data about each browser process. A browser may |
16 // have multiple processes (of course!). Even IE has multiple | 20 // have multiple processes (of course!). Even IE has multiple |
17 // processes these days. | 21 // processes these days. |
18 struct ProcessMemoryInformation { | 22 struct ProcessMemoryInformation { |
19 // NOTE: Do not remove or reorder the elements in this enum, and only add new | 23 // NOTE: Do not remove or reorder the elements in this enum, and only add new |
20 // items at the end. We depend on these specific values in a histogram. | 24 // items at the end. We depend on these specific values in a histogram. |
21 enum RendererProcessType { | 25 enum RendererProcessType { |
22 RENDERER_UNKNOWN = 0, | 26 RENDERER_UNKNOWN = 0, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // If this is a child process of Chrome, what type (i.e. plugin) it is. | 63 // If this is a child process of Chrome, what type (i.e. plugin) it is. |
60 int process_type; | 64 int process_type; |
61 // If this is a renderer process, what type it is. | 65 // If this is a renderer process, what type it is. |
62 RendererProcessType renderer_type; | 66 RendererProcessType renderer_type; |
63 // A collection of titles used, i.e. for a tab it'll show all the page titles. | 67 // A collection of titles used, i.e. for a tab it'll show all the page titles. |
64 std::vector<string16> titles; | 68 std::vector<string16> titles; |
65 }; | 69 }; |
66 | 70 |
67 typedef std::vector<ProcessMemoryInformation> ProcessMemoryInformationList; | 71 typedef std::vector<ProcessMemoryInformation> ProcessMemoryInformationList; |
68 | 72 |
| 73 // Maps an ID representing each BrowsingInstance to a set of site URLs. |
| 74 typedef base::hash_map<int32, std::set<GURL> > BrowsingInstanceSiteMap; |
| 75 |
| 76 // Information about the sites and SiteInstances in each BrowsingInstance, for |
| 77 // use in estimating the number of processes needed for various process models. |
| 78 struct SiteData { |
| 79 SiteData(); |
| 80 ~SiteData(); |
| 81 |
| 82 std::set<GURL> sites; |
| 83 std::set<GURL> https_sites; |
| 84 std::vector<content::SiteInstance*> instances; |
| 85 BrowsingInstanceSiteMap instance_site_map; |
| 86 BrowsingInstanceSiteMap instance_https_site_map; |
| 87 }; |
| 88 |
| 89 // Maps a BrowserContext to information about the SiteInstances it contains. |
| 90 typedef base::hash_map<content::BrowserContext*, SiteData> |
| 91 BrowserContextSiteDataMap; |
| 92 |
69 // Browser Process Information. | 93 // Browser Process Information. |
70 struct ProcessData { | 94 struct ProcessData { |
71 ProcessData(); | 95 ProcessData(); |
72 ProcessData(const ProcessData& rhs); | 96 ProcessData(const ProcessData& rhs); |
73 ~ProcessData(); | 97 ~ProcessData(); |
74 ProcessData& operator=(const ProcessData& rhs); | 98 ProcessData& operator=(const ProcessData& rhs); |
75 | 99 |
76 string16 name; | 100 string16 name; |
77 string16 process_name; | 101 string16 process_name; |
78 ProcessMemoryInformationList processes; | 102 ProcessMemoryInformationList processes; |
| 103 |
| 104 BrowserContextSiteDataMap site_data; |
79 }; | 105 }; |
80 | 106 |
81 #if defined(OS_MACOSX) | 107 #if defined(OS_MACOSX) |
82 class ProcessInfoSnapshot; | 108 class ProcessInfoSnapshot; |
83 #endif | 109 #endif |
84 | 110 |
85 // MemoryDetails fetches memory details about current running browsers. | 111 // MemoryDetails fetches memory details about current running browsers. |
86 // Because this data can only be fetched asynchronously, callers use | 112 // Because this data can only be fetched asynchronously, callers use |
87 // this class via a callback. | 113 // this class via a callback. |
88 // | 114 // |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void CollectProcessDataChrome( | 187 void CollectProcessDataChrome( |
162 const std::vector<ProcessMemoryInformation>& child_info, | 188 const std::vector<ProcessMemoryInformation>& child_info, |
163 base::ProcessId pid, | 189 base::ProcessId pid, |
164 const ProcessInfoSnapshot& process_info); | 190 const ProcessInfoSnapshot& process_info); |
165 #endif | 191 #endif |
166 | 192 |
167 // Collect child process information on the UI thread. Information about | 193 // Collect child process information on the UI thread. Information about |
168 // renderer processes is only available there. | 194 // renderer processes is only available there. |
169 void CollectChildInfoOnUIThread(); | 195 void CollectChildInfoOnUIThread(); |
170 | 196 |
| 197 // Collect information about all committed sites in the given WebContents. |
| 198 void CollectSiteInfo(content::WebContents* contents); |
| 199 |
171 // Updates the global histograms for tracking memory usage. | 200 // Updates the global histograms for tracking memory usage. |
172 void UpdateHistograms(); | 201 void UpdateHistograms(); |
173 | 202 |
174 // Returns a pointer to the ProcessData structure for Chrome. | 203 // Returns a pointer to the ProcessData structure for Chrome. |
175 ProcessData* ChromeBrowser(); | 204 ProcessData* ChromeBrowser(); |
176 | 205 |
177 std::vector<ProcessData> process_data_; | 206 std::vector<ProcessData> process_data_; |
178 | 207 |
179 UserMetricsMode user_metrics_mode_; | 208 UserMetricsMode user_metrics_mode_; |
180 | 209 |
181 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); | 210 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); |
182 }; | 211 }; |
183 | 212 |
184 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ | 213 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ |
OLD | NEW |