OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "chrome/browser/task_manager/task_manager_resource_providers.h" | 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
30 #include "chrome/browser/favicon/favicon_tab_helper.h" | 30 #include "chrome/browser/favicon/favicon_tab_helper.h" |
31 #include "chrome/browser/prerender/prerender_manager.h" | 31 #include "chrome/browser/prerender/prerender_manager.h" |
32 #include "chrome/browser/prerender/prerender_manager_factory.h" | 32 #include "chrome/browser/prerender/prerender_manager_factory.h" |
33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/profiles/profile_info_cache.h" | 34 #include "chrome/browser/profiles/profile_info_cache.h" |
35 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
36 #include "chrome/browser/tab_contents/background_contents.h" | 36 #include "chrome/browser/tab_contents/background_contents.h" |
37 #include "chrome/browser/tab_contents/tab_util.h" | 37 #include "chrome/browser/tab_contents/tab_util.h" |
38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_finder.h" |
39 #include "chrome/browser/ui/browser_instant_controller.h" | 40 #include "chrome/browser/ui/browser_instant_controller.h" |
40 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
41 #include "chrome/browser/ui/panels/panel.h" | 42 #include "chrome/browser/ui/panels/panel.h" |
42 #include "chrome/browser/ui/panels/panel_manager.h" | 43 #include "chrome/browser/ui/panels/panel_manager.h" |
43 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
44 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 45 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
45 #include "chrome/browser/view_type_utils.h" | 46 #include "chrome/browser/view_type_utils.h" |
46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
47 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/extensions/extension.h" | 49 #include "chrome/common/extensions/extension.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // might be wrong. For example, http://mail.yahoo.com, whose title is | 141 // might be wrong. For example, http://mail.yahoo.com, whose title is |
141 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly | 142 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly |
142 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best | 143 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best |
143 // web-based Email :BAT", in which the capital letters "BAT" stands for | 144 // web-based Email :BAT", in which the capital letters "BAT" stands for |
144 // the Hebrew word for "tab". | 145 // the Hebrew word for "tab". |
145 base::i18n::AdjustStringForLocaleDirection(&title); | 146 base::i18n::AdjustStringForLocaleDirection(&title); |
146 } | 147 } |
147 return title; | 148 return title; |
148 } | 149 } |
149 | 150 |
| 151 bool IsContentsPrerendering(WebContents* web_contents) { |
| 152 Profile* profile = |
| 153 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 154 prerender::PrerenderManager* prerender_manager = |
| 155 prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 156 return prerender_manager && |
| 157 prerender_manager->IsWebContentsPrerendering(web_contents, NULL); |
| 158 } |
| 159 |
| 160 bool IsContentsInstant(WebContents* web_contents) { |
| 161 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 162 i != BrowserList::end(); ++i) { |
| 163 if ((*i)->instant_controller() && |
| 164 (*i)->instant_controller()->instant()-> |
| 165 GetPreviewContents() == web_contents) { |
| 166 return true; |
| 167 } |
| 168 } |
| 169 |
| 170 return false; |
| 171 } |
| 172 |
150 } // namespace | 173 } // namespace |
151 | 174 |
152 //////////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////////// |
153 // TaskManagerRendererResource class | 176 // TaskManagerRendererResource class |
154 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
155 TaskManagerRendererResource::TaskManagerRendererResource( | 178 TaskManagerRendererResource::TaskManagerRendererResource( |
156 base::ProcessHandle process, content::RenderViewHost* render_view_host) | 179 base::ProcessHandle process, content::RenderViewHost* render_view_host) |
157 : process_(process), | 180 : process_(process), |
158 render_view_host_(render_view_host), | 181 render_view_host_(render_view_host), |
159 pending_stats_update_(false), | 182 pending_stats_update_(false), |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 287 } |
265 | 288 |
266 //////////////////////////////////////////////////////////////////////////////// | 289 //////////////////////////////////////////////////////////////////////////////// |
267 // TaskManagerTabContentsResource class | 290 // TaskManagerTabContentsResource class |
268 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
269 | 292 |
270 // static | 293 // static |
271 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; | 294 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; |
272 | 295 |
273 TaskManagerTabContentsResource::TaskManagerTabContentsResource( | 296 TaskManagerTabContentsResource::TaskManagerTabContentsResource( |
274 TabContents* tab_contents) | 297 WebContents* web_contents) |
275 : TaskManagerRendererResource( | 298 : TaskManagerRendererResource( |
276 tab_contents->web_contents()->GetRenderProcessHost()->GetHandle(), | 299 web_contents->GetRenderProcessHost()->GetHandle(), |
277 tab_contents->web_contents()->GetRenderViewHost()), | 300 web_contents->GetRenderViewHost()), |
278 tab_contents_(tab_contents), | 301 web_contents_(web_contents), |
279 is_instant_preview_(false) { | 302 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 303 is_instant_preview_(IsContentsInstant(web_contents)) { |
280 if (!prerender_icon_) { | 304 if (!prerender_icon_) { |
281 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 305 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
282 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); | 306 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); |
283 } | 307 } |
284 for (BrowserList::const_iterator i = BrowserList::begin(); | |
285 i != BrowserList::end(); ++i) { | |
286 if ((*i)->instant_controller() && | |
287 (*i)->instant_controller()->instant()->GetPreviewContents() == | |
288 tab_contents_->web_contents()) { | |
289 is_instant_preview_ = true; | |
290 break; | |
291 } | |
292 } | |
293 } | 308 } |
294 | 309 |
295 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { | 310 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { |
296 } | 311 } |
297 | 312 |
298 void TaskManagerTabContentsResource::InstantCommitted() { | 313 void TaskManagerTabContentsResource::InstantCommitted() { |
299 DCHECK(is_instant_preview_); | 314 DCHECK(is_instant_preview_); |
300 is_instant_preview_ = false; | 315 is_instant_preview_ = false; |
301 } | 316 } |
302 | 317 |
303 bool TaskManagerTabContentsResource::IsPrerendering() const { | |
304 prerender::PrerenderManager* prerender_manager = | |
305 prerender::PrerenderManagerFactory::GetForProfile( | |
306 tab_contents_->profile()); | |
307 return prerender_manager && | |
308 prerender_manager->IsWebContentsPrerendering( | |
309 tab_contents_->web_contents(), NULL); | |
310 } | |
311 | |
312 bool TaskManagerTabContentsResource::HostsExtension() const { | 318 bool TaskManagerTabContentsResource::HostsExtension() const { |
313 return tab_contents_->web_contents()->GetURL().SchemeIs( | 319 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme); |
314 extensions::kExtensionScheme); | |
315 } | 320 } |
316 | 321 |
317 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { | 322 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { |
318 return HostsExtension() ? EXTENSION : RENDERER; | 323 return HostsExtension() ? EXTENSION : RENDERER; |
319 } | 324 } |
320 | 325 |
321 string16 TaskManagerTabContentsResource::GetTitle() const { | 326 string16 TaskManagerTabContentsResource::GetTitle() const { |
322 // Fall back on the URL if there's no title. | 327 // Fall back on the URL if there's no title. |
323 WebContents* contents = tab_contents_->web_contents(); | 328 GURL url = web_contents_->GetURL(); |
324 GURL url = contents->GetURL(); | 329 string16 tab_title = GetTitleFromWebContents(web_contents_); |
325 string16 tab_title = GetTitleFromWebContents(contents); | |
326 | 330 |
327 // Only classify as an app if the URL is an app and the tab is hosting an | 331 // Only classify as an app if the URL is an app and the tab is hosting an |
328 // extension process. (It's possible to be showing the URL from before it | 332 // extension process. (It's possible to be showing the URL from before it |
329 // was installed as an app.) | 333 // was installed as an app.) |
330 ExtensionService* extension_service = | 334 ExtensionService* extension_service = profile_->GetExtensionService(); |
331 tab_contents_->profile()->GetExtensionService(); | |
332 extensions::ProcessMap* process_map = extension_service->process_map(); | 335 extensions::ProcessMap* process_map = extension_service->process_map(); |
333 bool is_app = extension_service->IsInstalledApp(url) && | 336 bool is_app = extension_service->IsInstalledApp(url) && |
334 process_map->Contains(contents->GetRenderProcessHost()->GetID()); | 337 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); |
335 | 338 |
336 int message_id = GetMessagePrefixID( | 339 int message_id = GetMessagePrefixID( |
337 is_app, | 340 is_app, |
338 HostsExtension(), | 341 HostsExtension(), |
339 tab_contents_->profile()->IsOffTheRecord(), | 342 profile_->IsOffTheRecord(), |
340 IsPrerendering(), | 343 IsContentsPrerendering(web_contents_), |
341 is_instant_preview_, | 344 is_instant_preview_, |
342 false); | 345 false); |
343 return l10n_util::GetStringFUTF16(message_id, tab_title); | 346 return l10n_util::GetStringFUTF16(message_id, tab_title); |
344 } | 347 } |
345 | 348 |
346 string16 TaskManagerTabContentsResource::GetProfileName() const { | 349 string16 TaskManagerTabContentsResource::GetProfileName() const { |
347 return GetProfileNameFromInfoCache(tab_contents_->profile()); | 350 return GetProfileNameFromInfoCache(profile_); |
348 } | 351 } |
349 | 352 |
350 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { | 353 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { |
351 if (IsPrerendering()) | 354 if (IsContentsPrerendering(web_contents_)) |
352 return *prerender_icon_; | 355 return *prerender_icon_; |
353 return FaviconTabHelper::FromWebContents(tab_contents_->web_contents())-> | 356 return FaviconTabHelper::FromWebContents(web_contents_)-> |
354 GetFavicon().AsImageSkia(); | 357 GetFavicon().AsImageSkia(); |
355 } | 358 } |
356 | 359 |
357 WebContents* TaskManagerTabContentsResource::GetWebContents() const { | 360 WebContents* TaskManagerTabContentsResource::GetWebContents() const { |
358 return tab_contents_->web_contents(); | 361 return web_contents_; |
359 } | 362 } |
360 | 363 |
361 const Extension* TaskManagerTabContentsResource::GetExtension() const { | 364 const Extension* TaskManagerTabContentsResource::GetExtension() const { |
362 if (HostsExtension()) { | 365 if (HostsExtension()) { |
363 ExtensionService* extension_service = | 366 ExtensionService* extension_service = profile_->GetExtensionService(); |
364 tab_contents_->profile()->GetExtensionService(); | |
365 return extension_service->extensions()->GetByID( | 367 return extension_service->extensions()->GetByID( |
366 tab_contents_->web_contents()->GetURL().host()); | 368 web_contents_->GetURL().host()); |
367 } | 369 } |
368 | 370 |
369 return NULL; | 371 return NULL; |
370 } | 372 } |
371 | 373 |
372 //////////////////////////////////////////////////////////////////////////////// | 374 //////////////////////////////////////////////////////////////////////////////// |
373 // TaskManagerTabContentsResourceProvider class | 375 // TaskManagerTabContentsResourceProvider class |
374 //////////////////////////////////////////////////////////////////////////////// | 376 //////////////////////////////////////////////////////////////////////////////// |
375 | 377 |
376 TaskManagerTabContentsResourceProvider:: | 378 TaskManagerTabContentsResourceProvider:: |
(...skipping 13 matching lines...) Expand all Loading... |
390 WebContents* web_contents = | 392 WebContents* web_contents = |
391 tab_util::GetWebContentsByID(render_process_host_id, routing_id); | 393 tab_util::GetWebContentsByID(render_process_host_id, routing_id); |
392 if (!web_contents) // Not one of our resource. | 394 if (!web_contents) // Not one of our resource. |
393 return NULL; | 395 return NULL; |
394 | 396 |
395 // If an origin PID was specified then the request originated in a plugin | 397 // If an origin PID was specified then the request originated in a plugin |
396 // working on the WebContents's behalf, so ignore it. | 398 // working on the WebContents's behalf, so ignore it. |
397 if (origin_pid) | 399 if (origin_pid) |
398 return NULL; | 400 return NULL; |
399 | 401 |
400 TabContents* tab_contents = TabContents::FromWebContents(web_contents); | 402 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator |
401 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator | 403 res_iter = resources_.find(web_contents); |
402 res_iter = resources_.find(tab_contents); | |
403 if (res_iter == resources_.end()) { | 404 if (res_iter == resources_.end()) { |
404 // Can happen if the tab was closed while a network request was being | 405 // Can happen if the tab was closed while a network request was being |
405 // performed. | 406 // performed. |
406 return NULL; | 407 return NULL; |
407 } | 408 } |
408 return res_iter->second; | 409 return res_iter->second; |
409 } | 410 } |
410 | 411 |
411 void TaskManagerTabContentsResourceProvider::StartUpdating() { | 412 void TaskManagerTabContentsResourceProvider::StartUpdating() { |
412 DCHECK(!updating_); | 413 DCHECK(!updating_); |
413 updating_ = true; | 414 updating_ = true; |
414 | 415 |
415 // Add all the existing TabContentses. | 416 // The contents that are tracked by this resource provider are those that |
| 417 // are tab contents (WebContents serving as a tab in a Browser), instant |
| 418 // pages, and prerender pages. |
| 419 |
| 420 // Add all the existing tab contents. |
416 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 421 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
417 Add(*iterator); | 422 Add(iterator->web_contents()); |
418 | 423 |
419 // Then we register for notifications to get new tabs. | 424 // Add all the instant pages. |
| 425 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 426 i != BrowserList::end(); ++i) { |
| 427 if ((*i)->instant_controller() && |
| 428 (*i)->instant_controller()->instant()->GetPreviewContents()) { |
| 429 Add((*i)->instant_controller()->instant()->GetPreviewContents()); |
| 430 } |
| 431 } |
| 432 |
| 433 // Add all the prerender pages. |
| 434 std::vector<Profile*> profiles( |
| 435 g_browser_process->profile_manager()->GetLoadedProfiles()); |
| 436 for (size_t i = 0; i < profiles.size(); ++i) { |
| 437 prerender::PrerenderManager* prerender_manager = |
| 438 prerender::PrerenderManagerFactory::GetForProfile(profiles[i]); |
| 439 const std::vector<content::WebContents*> contentses = |
| 440 prerender_manager->GetAllPrerenderingContents(); |
| 441 for (size_t j = 0; j < contentses.size(); ++j) |
| 442 Add(contentses[j]); |
| 443 } |
| 444 |
| 445 // Then we register for notifications to get new web contents. |
420 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 446 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
421 content::NotificationService::AllBrowserContextsAndSources()); | 447 content::NotificationService::AllBrowserContextsAndSources()); |
422 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 448 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
423 content::NotificationService::AllBrowserContextsAndSources()); | 449 content::NotificationService::AllBrowserContextsAndSources()); |
424 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 450 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
425 content::NotificationService::AllBrowserContextsAndSources()); | 451 content::NotificationService::AllBrowserContextsAndSources()); |
426 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 452 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
427 content::NotificationService::AllBrowserContextsAndSources()); | 453 content::NotificationService::AllBrowserContextsAndSources()); |
428 } | 454 } |
429 | 455 |
430 void TaskManagerTabContentsResourceProvider::StopUpdating() { | 456 void TaskManagerTabContentsResourceProvider::StopUpdating() { |
431 DCHECK(updating_); | 457 DCHECK(updating_); |
432 updating_ = false; | 458 updating_ = false; |
433 | 459 |
434 // Then we unregister for notifications to get new tabs. | 460 // Then we unregister for notifications to get new web contents. |
435 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 461 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
436 content::NotificationService::AllBrowserContextsAndSources()); | 462 content::NotificationService::AllBrowserContextsAndSources()); |
437 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 463 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
438 content::NotificationService::AllBrowserContextsAndSources()); | 464 content::NotificationService::AllBrowserContextsAndSources()); |
439 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 465 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
440 content::NotificationService::AllBrowserContextsAndSources()); | 466 content::NotificationService::AllBrowserContextsAndSources()); |
441 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 467 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
442 content::NotificationService::AllBrowserContextsAndSources()); | 468 content::NotificationService::AllBrowserContextsAndSources()); |
443 | 469 |
444 // Delete all the resources. | 470 // Delete all the resources. |
445 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 471 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
446 | 472 |
447 resources_.clear(); | 473 resources_.clear(); |
448 } | 474 } |
449 | 475 |
450 void TaskManagerTabContentsResourceProvider::AddToTaskManager( | 476 void TaskManagerTabContentsResourceProvider::AddToTaskManager( |
451 TabContents* tab_contents) { | 477 WebContents* web_contents) { |
452 TaskManagerTabContentsResource* resource = | 478 TaskManagerTabContentsResource* resource = |
453 new TaskManagerTabContentsResource(tab_contents); | 479 new TaskManagerTabContentsResource(web_contents); |
454 resources_[tab_contents] = resource; | 480 resources_[web_contents] = resource; |
455 task_manager_->AddResource(resource); | 481 task_manager_->AddResource(resource); |
456 } | 482 } |
457 | 483 |
458 void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { | 484 void TaskManagerTabContentsResourceProvider::Add(WebContents* web_contents) { |
459 if (!updating_) | 485 if (!updating_) |
460 return; | 486 return; |
461 | 487 |
462 // Don't add dead tabs or tabs that haven't yet connected. | 488 // Don't add dead tabs or tabs that haven't yet connected. |
463 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() || | 489 if (!web_contents->GetRenderProcessHost()->GetHandle() || |
464 !tab_contents->web_contents()->WillNotifyDisconnection()) { | 490 !web_contents->WillNotifyDisconnection()) { |
465 return; | 491 return; |
466 } | 492 } |
467 | 493 |
468 std::map<TabContents*, TaskManagerTabContentsResource*>::const_iterator | 494 if (resources_.count(web_contents)) { |
469 iter = resources_.find(tab_contents); | |
470 if (iter != resources_.end()) { | |
471 // The case may happen that we have added a WebContents as part of the | 495 // The case may happen that we have added a WebContents as part of the |
472 // iteration performed during StartUpdating() call but the notification that | 496 // iteration performed during StartUpdating() call but the notification that |
473 // it has connected was not fired yet. So when the notification happens, we | 497 // it has connected was not fired yet. So when the notification happens, we |
474 // already know about this tab and just ignore it. | 498 // already know about this tab and just ignore it. |
475 return; | 499 return; |
476 } | 500 } |
477 AddToTaskManager(tab_contents); | 501 AddToTaskManager(web_contents); |
478 } | 502 } |
479 | 503 |
480 void TaskManagerTabContentsResourceProvider::Remove(TabContents* tab_contents) { | 504 void TaskManagerTabContentsResourceProvider::Remove(WebContents* web_contents) { |
481 if (!updating_) | 505 if (!updating_) |
482 return; | 506 return; |
483 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator | 507 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator |
484 iter = resources_.find(tab_contents); | 508 iter = resources_.find(web_contents); |
485 if (iter == resources_.end()) { | 509 if (iter == resources_.end()) { |
486 // Since WebContents are destroyed asynchronously (see TabContentsCollector | 510 // Since WebContents are destroyed asynchronously (see TabContentsCollector |
487 // in navigation_controller.cc), we can be notified of a tab being removed | 511 // in navigation_controller.cc), we can be notified of a tab being removed |
488 // that we don't know. This can happen if the user closes a tab and quickly | 512 // that we don't know. This can happen if the user closes a tab and quickly |
489 // opens the task manager, before the tab is actually destroyed. | 513 // opens the task manager, before the tab is actually destroyed. |
490 return; | 514 return; |
491 } | 515 } |
492 | 516 |
493 // Remove the resource from the Task Manager. | 517 // Remove the resource from the Task Manager. |
494 TaskManagerTabContentsResource* resource = iter->second; | 518 TaskManagerTabContentsResource* resource = iter->second; |
495 task_manager_->RemoveResource(resource); | 519 task_manager_->RemoveResource(resource); |
496 // And from the provider. | 520 // And from the provider. |
497 resources_.erase(iter); | 521 resources_.erase(iter); |
498 // Finally, delete the resource. | 522 // Finally, delete the resource. |
499 delete resource; | 523 delete resource; |
500 } | 524 } |
501 | 525 |
502 void TaskManagerTabContentsResourceProvider::Update(TabContents* tab_contents) { | 526 void TaskManagerTabContentsResourceProvider::InstantCommitted( |
| 527 WebContents* web_contents) { |
503 if (!updating_) | 528 if (!updating_) |
504 return; | 529 return; |
505 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator | 530 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator |
506 iter = resources_.find(tab_contents); | 531 iter = resources_.find(web_contents); |
507 DCHECK(iter != resources_.end()); | 532 DCHECK(iter != resources_.end()); |
508 if (iter != resources_.end()) | 533 if (iter != resources_.end()) |
509 iter->second->InstantCommitted(); | 534 iter->second->InstantCommitted(); |
510 } | 535 } |
511 | 536 |
512 void TaskManagerTabContentsResourceProvider::Observe(int type, | 537 void TaskManagerTabContentsResourceProvider::Observe( |
| 538 int type, |
513 const content::NotificationSource& source, | 539 const content::NotificationSource& source, |
514 const content::NotificationDetails& details) { | 540 const content::NotificationDetails& details) { |
515 TabContents* tab_contents; | 541 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
516 tab_contents = TabContents::FromWebContents( | 542 |
517 content::Source<WebContents>(source).ptr()); | 543 // The contents that are tracked by this resource provider are those that |
518 // A background page does not have a TabContents. | 544 // are tab contents (WebContents serving as a tab in a Browser), instant |
519 if (!tab_contents) | 545 // pages, and prerender pages. |
| 546 if (!chrome::FindBrowserWithWebContents(web_contents) && |
| 547 !IsContentsPrerendering(web_contents) && |
| 548 !IsContentsInstant(web_contents)) { |
520 return; | 549 return; |
| 550 } |
| 551 |
521 switch (type) { | 552 switch (type) { |
522 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | 553 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
523 Add(tab_contents); | 554 Add(web_contents); |
524 break; | 555 break; |
525 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: | 556 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: |
526 Remove(tab_contents); | 557 Remove(web_contents); |
527 Add(tab_contents); | 558 Add(web_contents); |
528 break; | 559 break; |
529 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 560 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
530 Remove(tab_contents); | 561 Remove(web_contents); |
531 break; | 562 break; |
532 case chrome::NOTIFICATION_INSTANT_COMMITTED: | 563 case chrome::NOTIFICATION_INSTANT_COMMITTED: |
533 Update(tab_contents); | 564 InstantCommitted(web_contents); |
534 break; | 565 break; |
535 default: | 566 default: |
536 NOTREACHED() << "Unexpected notification."; | 567 NOTREACHED() << "Unexpected notification."; |
537 return; | 568 return; |
538 } | 569 } |
539 } | 570 } |
540 | 571 |
541 //////////////////////////////////////////////////////////////////////////////// | 572 //////////////////////////////////////////////////////////////////////////////// |
542 // TaskManagerPanelResource class | 573 // TaskManagerPanelResource class |
543 //////////////////////////////////////////////////////////////////////////////// | 574 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | 1902 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
1872 Add(web_contents->GetRenderViewHost()); | 1903 Add(web_contents->GetRenderViewHost()); |
1873 break; | 1904 break; |
1874 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 1905 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
1875 Remove(web_contents->GetRenderViewHost()); | 1906 Remove(web_contents->GetRenderViewHost()); |
1876 break; | 1907 break; |
1877 default: | 1908 default: |
1878 NOTREACHED() << "Unexpected notification."; | 1909 NOTREACHED() << "Unexpected notification."; |
1879 } | 1910 } |
1880 } | 1911 } |
OLD | NEW |