| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/task_manager/task_manager_extension_process_resource_pr
ovider.h" | 5 #include "chrome/browser/task_manager/extension_process_resource_provider.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/string16.h" | 7 #include "base/string16.h" |
| 11 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/devtools/devtools_window.h" | 10 #include "chrome/browser/devtools/devtools_window.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 11 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_process_manager.h" | 12 #include "chrome/browser/extensions/extension_process_manager.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/task_manager/resource_util.h" |
| 20 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 21 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/site_instance.h" | 20 #include "content/public/browser/site_instance.h" |
| 24 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 25 #include "extensions/browser/view_type_utils.h" | 22 #include "extensions/browser/view_type_utils.h" |
| 26 #include "grit/generated_resources.h" | |
| 27 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 31 | 27 |
| 32 using content::WebContents; | 28 using content::WebContents; |
| 33 using extensions::Extension; | 29 using extensions::Extension; |
| 34 | 30 |
| 35 namespace { | 31 namespace task_manager { |
| 36 | 32 |
| 37 // Returns the appropriate message prefix ID for tabs and extensions, | 33 class ExtensionProcessResource : public TaskManager::Resource { |
| 38 // reflecting whether they are apps or in incognito mode. | 34 public: |
| 39 int GetMessagePrefixID(bool is_app, | 35 explicit ExtensionProcessResource( |
| 40 bool is_extension, | 36 content::RenderViewHost* render_view_host); |
| 41 bool is_incognito, | 37 virtual ~ExtensionProcessResource(); |
| 42 bool is_prerender, | |
| 43 bool is_instant_overlay, | |
| 44 bool is_background) { | |
| 45 if (is_app) { | |
| 46 if (is_background) { | |
| 47 return IDS_TASK_MANAGER_BACKGROUND_PREFIX; | |
| 48 } else if (is_incognito) { | |
| 49 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; | |
| 50 } else { | |
| 51 return IDS_TASK_MANAGER_APP_PREFIX; | |
| 52 } | |
| 53 } else if (is_extension) { | |
| 54 if (is_incognito) | |
| 55 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; | |
| 56 else | |
| 57 return IDS_TASK_MANAGER_EXTENSION_PREFIX; | |
| 58 } else if (is_prerender) { | |
| 59 return IDS_TASK_MANAGER_PRERENDER_PREFIX; | |
| 60 } else if (is_instant_overlay) { | |
| 61 return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX; | |
| 62 } else { | |
| 63 return IDS_TASK_MANAGER_TAB_PREFIX; | |
| 64 } | |
| 65 } | |
| 66 | 38 |
| 67 string16 GetProfileNameFromInfoCache(Profile* profile) { | 39 // TaskManager::Resource methods: |
| 68 ProfileInfoCache& cache = | 40 virtual string16 GetTitle() const OVERRIDE; |
| 69 g_browser_process->profile_manager()->GetProfileInfoCache(); | 41 virtual string16 GetProfileName() const OVERRIDE; |
| 70 size_t index = cache.GetIndexOfProfileWithPath( | 42 virtual gfx::ImageSkia GetIcon() const OVERRIDE; |
| 71 profile->GetOriginalProfile()->GetPath()); | 43 virtual base::ProcessHandle GetProcess() const OVERRIDE; |
| 72 if (index == std::string::npos) | 44 virtual int GetUniqueChildProcessId() const OVERRIDE; |
| 73 return string16(); | 45 virtual Type GetType() const OVERRIDE; |
| 74 else | 46 virtual bool CanInspect() const OVERRIDE; |
| 75 return cache.GetNameOfProfileAtIndex(index); | 47 virtual void Inspect() const OVERRIDE; |
| 76 } | 48 virtual bool SupportNetworkUsage() const OVERRIDE; |
| 49 virtual void SetSupportNetworkUsage() OVERRIDE; |
| 50 virtual const extensions::Extension* GetExtension() const OVERRIDE; |
| 77 | 51 |
| 78 } // namespace | 52 // Returns the pid of the extension process. |
| 53 int process_id() const { return pid_; } |
| 79 | 54 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 55 // Returns true if the associated extension has a background page. |
| 81 // TaskManagerExtensionProcessResource class | 56 virtual bool IsBackground() const OVERRIDE; |
| 82 //////////////////////////////////////////////////////////////////////////////// | |
| 83 | 57 |
| 84 gfx::ImageSkia* TaskManagerExtensionProcessResource::default_icon_ = NULL; | 58 private: |
| 59 // The icon painted for the extension process. |
| 60 static gfx::ImageSkia* default_icon_; |
| 85 | 61 |
| 86 TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( | 62 content::RenderViewHost* render_view_host_; |
| 63 |
| 64 // Cached data about the extension. |
| 65 base::ProcessHandle process_handle_; |
| 66 int pid_; |
| 67 int unique_process_id_; |
| 68 string16 title_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessResource); |
| 71 }; |
| 72 |
| 73 gfx::ImageSkia* ExtensionProcessResource::default_icon_ = NULL; |
| 74 |
| 75 ExtensionProcessResource::ExtensionProcessResource( |
| 87 content::RenderViewHost* render_view_host) | 76 content::RenderViewHost* render_view_host) |
| 88 : render_view_host_(render_view_host) { | 77 : render_view_host_(render_view_host) { |
| 89 if (!default_icon_) { | 78 if (!default_icon_) { |
| 90 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 91 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 80 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| 92 } | 81 } |
| 93 process_handle_ = render_view_host_->GetProcess()->GetHandle(); | 82 process_handle_ = render_view_host_->GetProcess()->GetHandle(); |
| 94 unique_process_id_ = render_view_host->GetProcess()->GetID(); | 83 unique_process_id_ = render_view_host->GetProcess()->GetID(); |
| 95 pid_ = base::GetProcId(process_handle_); | 84 pid_ = base::GetProcId(process_handle_); |
| 96 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); | 85 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); |
| 97 DCHECK(!extension_name.empty()); | 86 DCHECK(!extension_name.empty()); |
| 98 | 87 |
| 99 Profile* profile = Profile::FromBrowserContext( | 88 Profile* profile = Profile::FromBrowserContext( |
| 100 render_view_host->GetProcess()->GetBrowserContext()); | 89 render_view_host->GetProcess()->GetBrowserContext()); |
| 101 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, | 90 int message_id = ResourceUtil::GetMessagePrefixID( |
| 102 profile->IsOffTheRecord(), false, false, IsBackground()); | 91 GetExtension()->is_app(), |
| 92 true, // is_extension |
| 93 profile->IsOffTheRecord(), |
| 94 false, // is_prerender |
| 95 false, // is_instant_overlay |
| 96 IsBackground()); |
| 103 title_ = l10n_util::GetStringFUTF16(message_id, extension_name); | 97 title_ = l10n_util::GetStringFUTF16(message_id, extension_name); |
| 104 } | 98 } |
| 105 | 99 |
| 106 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { | 100 ExtensionProcessResource::~ExtensionProcessResource() { |
| 107 } | 101 } |
| 108 | 102 |
| 109 string16 TaskManagerExtensionProcessResource::GetTitle() const { | 103 string16 ExtensionProcessResource::GetTitle() const { |
| 110 return title_; | 104 return title_; |
| 111 } | 105 } |
| 112 | 106 |
| 113 string16 TaskManagerExtensionProcessResource::GetProfileName() const { | 107 string16 ExtensionProcessResource::GetProfileName() const { |
| 114 return GetProfileNameFromInfoCache(Profile::FromBrowserContext( | 108 return ResourceUtil::GetProfileNameFromInfoCache( |
| 115 render_view_host_->GetProcess()->GetBrowserContext())); | 109 Profile::FromBrowserContext( |
| 110 render_view_host_->GetProcess()->GetBrowserContext())); |
| 116 } | 111 } |
| 117 | 112 |
| 118 gfx::ImageSkia TaskManagerExtensionProcessResource::GetIcon() const { | 113 gfx::ImageSkia ExtensionProcessResource::GetIcon() const { |
| 119 return *default_icon_; | 114 return *default_icon_; |
| 120 } | 115 } |
| 121 | 116 |
| 122 base::ProcessHandle TaskManagerExtensionProcessResource::GetProcess() const { | 117 base::ProcessHandle ExtensionProcessResource::GetProcess() const { |
| 123 return process_handle_; | 118 return process_handle_; |
| 124 } | 119 } |
| 125 | 120 |
| 126 int TaskManagerExtensionProcessResource::GetUniqueChildProcessId() const { | 121 int ExtensionProcessResource::GetUniqueChildProcessId() const { |
| 127 return unique_process_id_; | 122 return unique_process_id_; |
| 128 } | 123 } |
| 129 | 124 |
| 130 TaskManager::Resource::Type | 125 TaskManager::Resource::Type ExtensionProcessResource::GetType() const { |
| 131 TaskManagerExtensionProcessResource::GetType() const { | |
| 132 return EXTENSION; | 126 return EXTENSION; |
| 133 } | 127 } |
| 134 | 128 |
| 135 bool TaskManagerExtensionProcessResource::CanInspect() const { | 129 bool ExtensionProcessResource::CanInspect() const { |
| 136 return true; | 130 return true; |
| 137 } | 131 } |
| 138 | 132 |
| 139 void TaskManagerExtensionProcessResource::Inspect() const { | 133 void ExtensionProcessResource::Inspect() const { |
| 140 DevToolsWindow::OpenDevToolsWindow(render_view_host_); | 134 DevToolsWindow::OpenDevToolsWindow(render_view_host_); |
| 141 } | 135 } |
| 142 | 136 |
| 143 bool TaskManagerExtensionProcessResource::SupportNetworkUsage() const { | 137 bool ExtensionProcessResource::SupportNetworkUsage() const { |
| 144 return true; | 138 return true; |
| 145 } | 139 } |
| 146 | 140 |
| 147 void TaskManagerExtensionProcessResource::SetSupportNetworkUsage() { | 141 void ExtensionProcessResource::SetSupportNetworkUsage() { |
| 148 NOTREACHED(); | 142 NOTREACHED(); |
| 149 } | 143 } |
| 150 | 144 |
| 151 const Extension* TaskManagerExtensionProcessResource::GetExtension() const { | 145 const Extension* ExtensionProcessResource::GetExtension() const { |
| 152 Profile* profile = Profile::FromBrowserContext( | 146 Profile* profile = Profile::FromBrowserContext( |
| 153 render_view_host_->GetProcess()->GetBrowserContext()); | 147 render_view_host_->GetProcess()->GetBrowserContext()); |
| 154 ExtensionProcessManager* process_manager = | 148 ExtensionProcessManager* process_manager = |
| 155 extensions::ExtensionSystem::Get(profile)->process_manager(); | 149 extensions::ExtensionSystem::Get(profile)->process_manager(); |
| 156 return process_manager->GetExtensionForRenderViewHost(render_view_host_); | 150 return process_manager->GetExtensionForRenderViewHost(render_view_host_); |
| 157 } | 151 } |
| 158 | 152 |
| 159 bool TaskManagerExtensionProcessResource::IsBackground() const { | 153 bool ExtensionProcessResource::IsBackground() const { |
| 160 WebContents* web_contents = | 154 WebContents* web_contents = |
| 161 WebContents::FromRenderViewHost(render_view_host_); | 155 WebContents::FromRenderViewHost(render_view_host_); |
| 162 extensions::ViewType view_type = extensions::GetViewType(web_contents); | 156 extensions::ViewType view_type = extensions::GetViewType(web_contents); |
| 163 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 157 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
| 164 } | 158 } |
| 165 | 159 |
| 166 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 167 // TaskManagerExtensionProcessResourceProvider class | 161 // ExtensionProcessResourceProvider class |
| 168 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
| 169 | 163 |
| 170 TaskManagerExtensionProcessResourceProvider:: | 164 ExtensionProcessResourceProvider:: |
| 171 TaskManagerExtensionProcessResourceProvider(TaskManager* task_manager) | 165 ExtensionProcessResourceProvider(TaskManager* task_manager) |
| 172 : task_manager_(task_manager), | 166 : task_manager_(task_manager), |
| 173 updating_(false) { | 167 updating_(false) { |
| 174 } | 168 } |
| 175 | 169 |
| 176 TaskManagerExtensionProcessResourceProvider:: | 170 ExtensionProcessResourceProvider::~ExtensionProcessResourceProvider() { |
| 177 ~TaskManagerExtensionProcessResourceProvider() { | |
| 178 } | 171 } |
| 179 | 172 |
| 180 TaskManager::Resource* TaskManagerExtensionProcessResourceProvider::GetResource( | 173 TaskManager::Resource* ExtensionProcessResourceProvider::GetResource( |
| 181 int origin_pid, | 174 int origin_pid, |
| 182 int render_process_host_id, | 175 int render_process_host_id, |
| 183 int routing_id) { | 176 int routing_id) { |
| 184 // If an origin PID was specified, the request is from a plugin, not the | 177 // If an origin PID was specified, the request is from a plugin, not the |
| 185 // render view host process | 178 // render view host process |
| 186 if (origin_pid) | 179 if (origin_pid) |
| 187 return NULL; | 180 return NULL; |
| 188 | 181 |
| 189 for (ExtensionRenderViewHostMap::iterator i = resources_.begin(); | 182 for (ExtensionRenderViewHostMap::iterator i = resources_.begin(); |
| 190 i != resources_.end(); i++) { | 183 i != resources_.end(); i++) { |
| 191 if (i->first->GetSiteInstance()->GetProcess()->GetID() == | 184 if (i->first->GetSiteInstance()->GetProcess()->GetID() == |
| 192 render_process_host_id && | 185 render_process_host_id && |
| 193 i->first->GetRoutingID() == routing_id) | 186 i->first->GetRoutingID() == routing_id) |
| 194 return i->second; | 187 return i->second; |
| 195 } | 188 } |
| 196 | 189 |
| 197 // Can happen if the page went away while a network request was being | 190 // Can happen if the page went away while a network request was being |
| 198 // performed. | 191 // performed. |
| 199 return NULL; | 192 return NULL; |
| 200 } | 193 } |
| 201 | 194 |
| 202 void TaskManagerExtensionProcessResourceProvider::StartUpdating() { | 195 void ExtensionProcessResourceProvider::StartUpdating() { |
| 203 DCHECK(!updating_); | 196 DCHECK(!updating_); |
| 204 updating_ = true; | 197 updating_ = true; |
| 205 | 198 |
| 206 // Add all the existing extension views from all Profiles, including those | 199 // Add all the existing extension views from all Profiles, including those |
| 207 // from incognito split mode. | 200 // from incognito split mode. |
| 208 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 201 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 209 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 202 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
| 210 size_t num_default_profiles = profiles.size(); | 203 size_t num_default_profiles = profiles.size(); |
| 211 for (size_t i = 0; i < num_default_profiles; ++i) { | 204 for (size_t i = 0; i < num_default_profiles; ++i) { |
| 212 if (profiles[i]->HasOffTheRecordProfile()) { | 205 if (profiles[i]->HasOffTheRecordProfile()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 234 | 227 |
| 235 // Register for notifications about extension process changes. | 228 // Register for notifications about extension process changes. |
| 236 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, | 229 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, |
| 237 content::NotificationService::AllBrowserContextsAndSources()); | 230 content::NotificationService::AllBrowserContextsAndSources()); |
| 238 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 231 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 239 content::NotificationService::AllBrowserContextsAndSources()); | 232 content::NotificationService::AllBrowserContextsAndSources()); |
| 240 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, | 233 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, |
| 241 content::NotificationService::AllBrowserContextsAndSources()); | 234 content::NotificationService::AllBrowserContextsAndSources()); |
| 242 } | 235 } |
| 243 | 236 |
| 244 void TaskManagerExtensionProcessResourceProvider::StopUpdating() { | 237 void ExtensionProcessResourceProvider::StopUpdating() { |
| 245 DCHECK(updating_); | 238 DCHECK(updating_); |
| 246 updating_ = false; | 239 updating_ = false; |
| 247 | 240 |
| 248 // Unregister for notifications about extension process changes. | 241 // Unregister for notifications about extension process changes. |
| 249 registrar_.Remove( | 242 registrar_.Remove( |
| 250 this, chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, | 243 this, chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, |
| 251 content::NotificationService::AllBrowserContextsAndSources()); | 244 content::NotificationService::AllBrowserContextsAndSources()); |
| 252 registrar_.Remove( | 245 registrar_.Remove( |
| 253 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 246 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 254 content::NotificationService::AllBrowserContextsAndSources()); | 247 content::NotificationService::AllBrowserContextsAndSources()); |
| 255 registrar_.Remove( | 248 registrar_.Remove( |
| 256 this, chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, | 249 this, chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, |
| 257 content::NotificationService::AllBrowserContextsAndSources()); | 250 content::NotificationService::AllBrowserContextsAndSources()); |
| 258 | 251 |
| 259 // Delete all the resources. | 252 // Delete all the resources. |
| 260 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 253 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 261 | 254 |
| 262 resources_.clear(); | 255 resources_.clear(); |
| 263 } | 256 } |
| 264 | 257 |
| 265 void TaskManagerExtensionProcessResourceProvider::Observe( | 258 void ExtensionProcessResourceProvider::Observe( |
| 266 int type, | 259 int type, |
| 267 const content::NotificationSource& source, | 260 const content::NotificationSource& source, |
| 268 const content::NotificationDetails& details) { | 261 const content::NotificationDetails& details) { |
| 269 switch (type) { | 262 switch (type) { |
| 270 case chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED: | 263 case chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED: |
| 271 AddToTaskManager( | 264 AddToTaskManager( |
| 272 content::Details<content::RenderViewHost>(details).ptr()); | 265 content::Details<content::RenderViewHost>(details).ptr()); |
| 273 break; | 266 break; |
| 274 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: | 267 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
| 275 RemoveFromTaskManager( | 268 RemoveFromTaskManager( |
| 276 content::Details<extensions::ExtensionHost>(details).ptr()-> | 269 content::Details<extensions::ExtensionHost>(details).ptr()-> |
| 277 render_view_host()); | 270 render_view_host()); |
| 278 break; | 271 break; |
| 279 case chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED: | 272 case chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED: |
| 280 RemoveFromTaskManager( | 273 RemoveFromTaskManager( |
| 281 content::Details<content::RenderViewHost>(details).ptr()); | 274 content::Details<content::RenderViewHost>(details).ptr()); |
| 282 break; | 275 break; |
| 283 default: | 276 default: |
| 284 NOTREACHED() << "Unexpected notification."; | 277 NOTREACHED() << "Unexpected notification."; |
| 285 return; | 278 return; |
| 286 } | 279 } |
| 287 } | 280 } |
| 288 | 281 |
| 289 bool TaskManagerExtensionProcessResourceProvider:: | 282 bool ExtensionProcessResourceProvider:: |
| 290 IsHandledByThisProvider(content::RenderViewHost* render_view_host) { | 283 IsHandledByThisProvider(content::RenderViewHost* render_view_host) { |
| 291 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); | 284 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| 292 // Don't add WebContents that belong to a guest (those are handled by | 285 // Don't add WebContents that belong to a guest (those are handled by |
| 293 // TaskManagerGuestResourceProvider). Otherwise they will be added twice, and | 286 // TaskManagerGuestResourceProvider). Otherwise they will be added twice, and |
| 294 // in this case they will have the app's name as a title (due to the | 287 // in this case they will have the app's name as a title (due to the |
| 295 // TaskManagerExtensionProcessResource constructor). | 288 // ExtensionProcessResource constructor). |
| 296 if (web_contents->GetRenderProcessHost()->IsGuest()) | 289 if (web_contents->GetRenderProcessHost()->IsGuest()) |
| 297 return false; | 290 return false; |
| 298 extensions::ViewType view_type = extensions::GetViewType(web_contents); | 291 extensions::ViewType view_type = extensions::GetViewType(web_contents); |
| 299 // Don't add WebContents (those are handled by | 292 // Don't add WebContents (those are handled by |
| 300 // TaskManagerTabContentsResourceProvider) or background contents (handled | 293 // TaskManagerTabContentsResourceProvider) or background contents (handled |
| 301 // by TaskManagerBackgroundResourceProvider). | 294 // by TaskManagerBackgroundResourceProvider). |
| 302 #if defined(USE_ASH) | 295 #if defined(USE_ASH) |
| 303 return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS && | 296 return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS && |
| 304 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS); | 297 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS); |
| 305 #else | 298 #else |
| 306 return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS && | 299 return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS && |
| 307 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS && | 300 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS && |
| 308 view_type != extensions::VIEW_TYPE_PANEL); | 301 view_type != extensions::VIEW_TYPE_PANEL); |
| 309 #endif // USE_ASH | 302 #endif // USE_ASH |
| 310 } | 303 } |
| 311 | 304 |
| 312 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( | 305 void ExtensionProcessResourceProvider::AddToTaskManager( |
| 313 content::RenderViewHost* render_view_host) { | 306 content::RenderViewHost* render_view_host) { |
| 314 if (!IsHandledByThisProvider(render_view_host)) | 307 if (!IsHandledByThisProvider(render_view_host)) |
| 315 return; | 308 return; |
| 316 | 309 |
| 317 TaskManagerExtensionProcessResource* resource = | 310 ExtensionProcessResource* resource = |
| 318 new TaskManagerExtensionProcessResource(render_view_host); | 311 new ExtensionProcessResource(render_view_host); |
| 319 DCHECK(resources_.find(render_view_host) == resources_.end()); | 312 DCHECK(resources_.find(render_view_host) == resources_.end()); |
| 320 resources_[render_view_host] = resource; | 313 resources_[render_view_host] = resource; |
| 321 task_manager_->AddResource(resource); | 314 task_manager_->AddResource(resource); |
| 322 } | 315 } |
| 323 | 316 |
| 324 void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager( | 317 void ExtensionProcessResourceProvider::RemoveFromTaskManager( |
| 325 content::RenderViewHost* render_view_host) { | 318 content::RenderViewHost* render_view_host) { |
| 326 if (!updating_) | 319 if (!updating_) |
| 327 return; | 320 return; |
| 328 std::map<content::RenderViewHost*, TaskManagerExtensionProcessResource*> | 321 std::map<content::RenderViewHost*, ExtensionProcessResource*> |
| 329 ::iterator iter = resources_.find(render_view_host); | 322 ::iterator iter = resources_.find(render_view_host); |
| 330 if (iter == resources_.end()) | 323 if (iter == resources_.end()) |
| 331 return; | 324 return; |
| 332 | 325 |
| 333 // Remove the resource from the Task Manager. | 326 // Remove the resource from the Task Manager. |
| 334 TaskManagerExtensionProcessResource* resource = iter->second; | 327 ExtensionProcessResource* resource = iter->second; |
| 335 task_manager_->RemoveResource(resource); | 328 task_manager_->RemoveResource(resource); |
| 336 | 329 |
| 337 // Remove it from the provider. | 330 // Remove it from the provider. |
| 338 resources_.erase(iter); | 331 resources_.erase(iter); |
| 339 | 332 |
| 340 // Finally, delete the resource. | 333 // Finally, delete the resource. |
| 341 delete resource; | 334 delete resource; |
| 342 } | 335 } |
| 336 |
| 337 } // namespace task_manager |
| OLD | NEW |