| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/power/process_power_collector.h" | 5 #include "chrome/browser/power/process_power_collector.h" |
| 6 | 6 |
| 7 #include "apps/app_window.h" | |
| 8 #include "apps/app_window_registry.h" | |
| 9 #include "base/process/process_handle.h" | 7 #include "base/process/process_handle.h" |
| 10 #include "base/process/process_metrics.h" | 8 #include "base/process/process_metrics.h" |
| 11 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 15 #include "components/power/origin_power_map.h" | 13 #include "components/power/origin_power_map.h" |
| 16 #include "components/power/origin_power_map_factory.h" | 14 #include "components/power/origin_power_map_factory.h" |
| 17 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "extensions/browser/app_window/app_window.h" |
| 19 #include "extensions/browser/app_window/app_window_registry.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 23 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
| 24 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 24 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 const int kSecondsPerSample = 30; | 28 const int kSecondsPerSample = 30; |
| 29 } | 29 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 continue; | 120 continue; |
| 121 UpdateProcessInMap(render_process, it->GetLastCommittedURL().GetOrigin()); | 121 UpdateProcessInMap(render_process, it->GetLastCommittedURL().GetOrigin()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Iterate over all profiles to find all app windows to attribute all apps. | 124 // Iterate over all profiles to find all app windows to attribute all apps. |
| 125 ProfileManager* pm = g_browser_process->profile_manager(); | 125 ProfileManager* pm = g_browser_process->profile_manager(); |
| 126 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles(); | 126 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles(); |
| 127 for (std::vector<Profile*>::const_iterator it = open_profiles.begin(); | 127 for (std::vector<Profile*>::const_iterator it = open_profiles.begin(); |
| 128 it != open_profiles.end(); | 128 it != open_profiles.end(); |
| 129 ++it) { | 129 ++it) { |
| 130 const apps::AppWindowRegistry::AppWindowList& app_windows = | 130 const extensions::AppWindowRegistry::AppWindowList& app_windows = |
| 131 apps::AppWindowRegistry::Get(*it)->app_windows(); | 131 extensions::AppWindowRegistry::Get(*it)->app_windows(); |
| 132 for (apps::AppWindowRegistry::AppWindowList::const_iterator itr = | 132 for (extensions::AppWindowRegistry::AppWindowList::const_iterator itr = |
| 133 app_windows.begin(); | 133 app_windows.begin(); |
| 134 itr != app_windows.end(); | 134 itr != app_windows.end(); |
| 135 ++itr) { | 135 ++itr) { |
| 136 content::WebContents* web_contents = (*itr)->web_contents(); | 136 content::WebContents* web_contents = (*itr)->web_contents(); |
| 137 | 137 |
| 138 UpdateProcessInMap(web_contents->GetRenderProcessHost(), | 138 UpdateProcessInMap(web_contents->GetRenderProcessHost(), |
| 139 web_contents->GetLastCommittedURL().GetOrigin()); | 139 web_contents->GetLastCommittedURL().GetOrigin()); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 origin, | 192 origin, |
| 193 Profile::FromBrowserContext(rph->GetBrowserContext()))); | 193 Profile::FromBrowserContext(rph->GetBrowserContext()))); |
| 194 } | 194 } |
| 195 | 195 |
| 196 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; | 196 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; |
| 197 process_data->set_last_cpu_percent(std::max(0.0, | 197 process_data->set_last_cpu_percent(std::max(0.0, |
| 198 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() | 198 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() |
| 199 : cpu_usage_callback_.Run(handle))); | 199 : cpu_usage_callback_.Run(handle))); |
| 200 process_data->set_seen_this_cycle(true); | 200 process_data->set_seen_this_cycle(true); |
| 201 } | 201 } |
| OLD | NEW |