OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
20 #include "chrome/browser/background/background_contents_service.h" | 20 #include "chrome/browser/background/background_contents_service.h" |
21 #include "chrome/browser/background/background_contents_service_factory.h" | 21 #include "chrome/browser/background/background_contents_service_factory.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/debugger/devtools_window.h" | 23 #include "chrome/browser/debugger/devtools_window.h" |
24 #include "chrome/browser/extensions/extension_host.h" | 24 #include "chrome/browser/extensions/extension_host.h" |
25 #include "chrome/browser/extensions/extension_process_manager.h" | 25 #include "chrome/browser/extensions/extension_process_manager.h" |
26 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
27 #include "chrome/browser/favicon/favicon_tab_helper.h" | 27 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 28 #include "chrome/browser/instant/instant_controller.h" |
28 #include "chrome/browser/prerender/prerender_manager.h" | 29 #include "chrome/browser/prerender/prerender_manager.h" |
29 #include "chrome/browser/prerender/prerender_manager_factory.h" | 30 #include "chrome/browser/prerender/prerender_manager_factory.h" |
30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/profiles/profile_info_cache.h" | 32 #include "chrome/browser/profiles/profile_info_cache.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/browser/tab_contents/background_contents.h" | 34 #include "chrome/browser/tab_contents/background_contents.h" |
34 #include "chrome/browser/tab_contents/tab_util.h" | 35 #include "chrome/browser/tab_contents/tab_util.h" |
35 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
36 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
37 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
(...skipping 25 matching lines...) Expand all Loading... |
63 #include "chrome/browser/app_icon_win.h" | 64 #include "chrome/browser/app_icon_win.h" |
64 #include "ui/gfx/icon_util.h" | 65 #include "ui/gfx/icon_util.h" |
65 #endif // defined(OS_WIN) | 66 #endif // defined(OS_WIN) |
66 | 67 |
67 using content::BrowserThread; | 68 using content::BrowserThread; |
68 | 69 |
69 namespace { | 70 namespace { |
70 | 71 |
71 // Returns the appropriate message prefix ID for tabs and extensions, | 72 // Returns the appropriate message prefix ID for tabs and extensions, |
72 // reflecting whether they are apps or in incognito mode. | 73 // reflecting whether they are apps or in incognito mode. |
73 int GetMessagePrefixID(bool is_app, bool is_extension, | 74 int GetMessagePrefixID(bool is_app, |
74 bool is_incognito, bool is_prerender) { | 75 bool is_extension, |
| 76 bool is_incognito, |
| 77 bool is_prerender, |
| 78 bool is_instant_preview) { |
75 if (is_app) { | 79 if (is_app) { |
76 if (is_incognito) | 80 if (is_incognito) |
77 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; | 81 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; |
78 else | 82 else |
79 return IDS_TASK_MANAGER_APP_PREFIX; | 83 return IDS_TASK_MANAGER_APP_PREFIX; |
80 } else if (is_extension) { | 84 } else if (is_extension) { |
81 if (is_incognito) | 85 if (is_incognito) |
82 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; | 86 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; |
83 else | 87 else |
84 return IDS_TASK_MANAGER_EXTENSION_PREFIX; | 88 return IDS_TASK_MANAGER_EXTENSION_PREFIX; |
85 } else if (is_prerender) { | 89 } else if (is_prerender) { |
86 return IDS_TASK_MANAGER_PRERENDER_PREFIX; | 90 return IDS_TASK_MANAGER_PRERENDER_PREFIX; |
| 91 } else if (is_instant_preview) { |
| 92 return IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX; |
87 } else { | 93 } else { |
88 return IDS_TASK_MANAGER_TAB_PREFIX; | 94 return IDS_TASK_MANAGER_TAB_PREFIX; |
89 } | 95 } |
90 } | 96 } |
91 | 97 |
92 } // namespace | 98 } // namespace |
93 | 99 |
94 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
95 // TaskManagerRendererResource class | 101 // TaskManagerRendererResource class |
96 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 //////////////////////////////////////////////////////////////////////////////// | 215 //////////////////////////////////////////////////////////////////////////////// |
210 | 216 |
211 // static | 217 // static |
212 SkBitmap* TaskManagerTabContentsResource::prerender_icon_ = NULL; | 218 SkBitmap* TaskManagerTabContentsResource::prerender_icon_ = NULL; |
213 | 219 |
214 TaskManagerTabContentsResource::TaskManagerTabContentsResource( | 220 TaskManagerTabContentsResource::TaskManagerTabContentsResource( |
215 TabContentsWrapper* tab_contents) | 221 TabContentsWrapper* tab_contents) |
216 : TaskManagerRendererResource( | 222 : TaskManagerRendererResource( |
217 tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(), | 223 tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(), |
218 tab_contents->render_view_host()), | 224 tab_contents->render_view_host()), |
219 tab_contents_(tab_contents) { | 225 tab_contents_(tab_contents), |
| 226 is_instant_preview_(false) { |
220 if (!prerender_icon_) { | 227 if (!prerender_icon_) { |
221 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 228 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
222 prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER); | 229 prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER); |
223 } | 230 } |
| 231 for (BrowserList::const_iterator i = BrowserList::begin(); |
| 232 i != BrowserList::end(); ++i) { |
| 233 if ((*i)->instant() && |
| 234 (*i)->instant()->GetPreviewContents() == tab_contents_) { |
| 235 is_instant_preview_ = true; |
| 236 break; |
| 237 } |
| 238 } |
224 } | 239 } |
225 | 240 |
226 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { | 241 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { |
227 } | 242 } |
228 | 243 |
| 244 void TaskManagerTabContentsResource::InstantCommitted() { |
| 245 DCHECK(is_instant_preview_); |
| 246 is_instant_preview_ = false; |
| 247 } |
| 248 |
229 bool TaskManagerTabContentsResource::IsPrerendering() const { | 249 bool TaskManagerTabContentsResource::IsPrerendering() const { |
230 prerender::PrerenderManager* prerender_manager = | 250 prerender::PrerenderManager* prerender_manager = |
231 prerender::PrerenderManagerFactory::GetForProfile( | 251 prerender::PrerenderManagerFactory::GetForProfile( |
232 tab_contents_->profile()); | 252 tab_contents_->profile()); |
233 return prerender_manager && | 253 return prerender_manager && |
234 prerender_manager->IsTabContentsPrerendering( | 254 prerender_manager->IsTabContentsPrerendering( |
235 tab_contents_->tab_contents()); | 255 tab_contents_->tab_contents()); |
236 } | 256 } |
237 | 257 |
238 bool TaskManagerTabContentsResource::HostsExtension() const { | 258 bool TaskManagerTabContentsResource::HostsExtension() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 ExtensionService* extension_service = | 292 ExtensionService* extension_service = |
273 tab_contents_->profile()->GetExtensionService(); | 293 tab_contents_->profile()->GetExtensionService(); |
274 extensions::ProcessMap* process_map = extension_service->process_map(); | 294 extensions::ProcessMap* process_map = extension_service->process_map(); |
275 bool is_app = extension_service->IsInstalledApp(url) && | 295 bool is_app = extension_service->IsInstalledApp(url) && |
276 process_map->Contains(contents->GetRenderProcessHost()->GetID()); | 296 process_map->Contains(contents->GetRenderProcessHost()->GetID()); |
277 | 297 |
278 int message_id = GetMessagePrefixID( | 298 int message_id = GetMessagePrefixID( |
279 is_app, | 299 is_app, |
280 HostsExtension(), | 300 HostsExtension(), |
281 tab_contents_->profile()->IsOffTheRecord(), | 301 tab_contents_->profile()->IsOffTheRecord(), |
282 IsPrerendering()); | 302 IsPrerendering(), |
| 303 is_instant_preview_); |
283 return l10n_util::GetStringFUTF16(message_id, tab_title); | 304 return l10n_util::GetStringFUTF16(message_id, tab_title); |
284 } | 305 } |
285 | 306 |
286 string16 TaskManagerTabContentsResource::GetProfileName() const { | 307 string16 TaskManagerTabContentsResource::GetProfileName() const { |
287 ProfileInfoCache& cache = | 308 ProfileInfoCache& cache = |
288 g_browser_process->profile_manager()->GetProfileInfoCache(); | 309 g_browser_process->profile_manager()->GetProfileInfoCache(); |
289 Profile* profile = tab_contents_->profile()->GetOriginalProfile(); | 310 Profile* profile = tab_contents_->profile()->GetOriginalProfile(); |
290 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 311 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
291 if (index == std::string::npos) | 312 if (index == std::string::npos) |
292 return string16(); | 313 return string16(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 390 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
370 content::NotificationService::AllBrowserContextsAndSources()); | 391 content::NotificationService::AllBrowserContextsAndSources()); |
371 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 392 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
372 content::NotificationService::AllBrowserContextsAndSources()); | 393 content::NotificationService::AllBrowserContextsAndSources()); |
373 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a | 394 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a |
374 // resource. This is an attempt at mitigating a crasher that seem to | 395 // resource. This is an attempt at mitigating a crasher that seem to |
375 // indicate a resource is still referencing a deleted TabContents | 396 // indicate a resource is still referencing a deleted TabContents |
376 // (http://crbug.com/7321). | 397 // (http://crbug.com/7321). |
377 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 398 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
378 content::NotificationService::AllBrowserContextsAndSources()); | 399 content::NotificationService::AllBrowserContextsAndSources()); |
| 400 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 401 content::NotificationService::AllBrowserContextsAndSources()); |
379 } | 402 } |
380 | 403 |
381 void TaskManagerTabContentsResourceProvider::StopUpdating() { | 404 void TaskManagerTabContentsResourceProvider::StopUpdating() { |
382 DCHECK(updating_); | 405 DCHECK(updating_); |
383 updating_ = false; | 406 updating_ = false; |
384 | 407 |
385 // Then we unregister for notifications to get new tabs. | 408 // Then we unregister for notifications to get new tabs. |
386 registrar_.Remove( | 409 registrar_.Remove( |
387 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 410 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
388 content::NotificationService::AllBrowserContextsAndSources()); | 411 content::NotificationService::AllBrowserContextsAndSources()); |
389 registrar_.Remove( | 412 registrar_.Remove( |
390 this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 413 this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
391 content::NotificationService::AllBrowserContextsAndSources()); | 414 content::NotificationService::AllBrowserContextsAndSources()); |
392 registrar_.Remove( | 415 registrar_.Remove( |
393 this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 416 this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
394 content::NotificationService::AllBrowserContextsAndSources()); | 417 content::NotificationService::AllBrowserContextsAndSources()); |
395 registrar_.Remove( | 418 registrar_.Remove( |
396 this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 419 this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
397 content::NotificationService::AllBrowserContextsAndSources()); | 420 content::NotificationService::AllBrowserContextsAndSources()); |
| 421 registrar_.Remove( |
| 422 this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 423 content::NotificationService::AllBrowserContextsAndSources()); |
398 | 424 |
399 // Delete all the resources. | 425 // Delete all the resources. |
400 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 426 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
401 | 427 |
402 resources_.clear(); | 428 resources_.clear(); |
403 } | 429 } |
404 | 430 |
405 void TaskManagerTabContentsResourceProvider::AddToTaskManager( | 431 void TaskManagerTabContentsResourceProvider::AddToTaskManager( |
406 TabContentsWrapper* tab_contents) { | 432 TabContentsWrapper* tab_contents) { |
407 TaskManagerTabContentsResource* resource = | 433 TaskManagerTabContentsResource* resource = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 475 |
450 // Remove the resource from the Task Manager. | 476 // Remove the resource from the Task Manager. |
451 TaskManagerTabContentsResource* resource = iter->second; | 477 TaskManagerTabContentsResource* resource = iter->second; |
452 task_manager_->RemoveResource(resource); | 478 task_manager_->RemoveResource(resource); |
453 // And from the provider. | 479 // And from the provider. |
454 resources_.erase(iter); | 480 resources_.erase(iter); |
455 // Finally, delete the resource. | 481 // Finally, delete the resource. |
456 delete resource; | 482 delete resource; |
457 } | 483 } |
458 | 484 |
| 485 void TaskManagerTabContentsResourceProvider::Update( |
| 486 TabContentsWrapper* tab_contents) { |
| 487 if (!updating_) |
| 488 return; |
| 489 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator |
| 490 iter = resources_.find(tab_contents); |
| 491 DCHECK(iter != resources_.end()); |
| 492 if (iter != resources_.end()) |
| 493 iter->second->InstantCommitted(); |
| 494 } |
| 495 |
459 void TaskManagerTabContentsResourceProvider::Observe(int type, | 496 void TaskManagerTabContentsResourceProvider::Observe(int type, |
460 const content::NotificationSource& source, | 497 const content::NotificationSource& source, |
461 const content::NotificationDetails& details) { | 498 const content::NotificationDetails& details) { |
462 TabContentsWrapper* tab_contents = | 499 TabContentsWrapper* tab_contents; |
463 TabContentsWrapper::GetCurrentWrapperForContents( | 500 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { |
464 content::Source<TabContents>(source).ptr()); | 501 tab_contents = content::Source<TabContentsWrapper>(source).ptr(); |
| 502 } else { |
| 503 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( |
| 504 content::Source<TabContents>(source).ptr()); |
| 505 } |
465 // A background page does not have a TabContentsWrapper. | 506 // A background page does not have a TabContentsWrapper. |
466 if (!tab_contents) | 507 if (!tab_contents) |
467 return; | 508 return; |
468 switch (type) { | 509 switch (type) { |
469 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: | 510 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: |
470 Add(tab_contents); | 511 Add(tab_contents); |
471 break; | 512 break; |
472 case content::NOTIFICATION_TAB_CONTENTS_SWAPPED: | 513 case content::NOTIFICATION_TAB_CONTENTS_SWAPPED: |
473 Remove(tab_contents); | 514 Remove(tab_contents); |
474 Add(tab_contents); | 515 Add(tab_contents); |
475 break; | 516 break; |
476 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: | 517 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: |
477 // If this DCHECK is triggered, it could explain http://crbug.com/7321 . | 518 // If this DCHECK is triggered, it could explain http://crbug.com/7321 . |
478 DCHECK(resources_.find(tab_contents) == | 519 DCHECK(resources_.find(tab_contents) == |
479 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated " | 520 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated " |
480 "TAB_CONTENTS_DISCONNECTED"; | 521 "TAB_CONTENTS_DISCONNECTED"; |
481 // Fall through. | 522 // Fall through. |
482 case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED: | 523 case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED: |
483 Remove(tab_contents); | 524 Remove(tab_contents); |
484 break; | 525 break; |
| 526 case chrome::NOTIFICATION_INSTANT_COMMITTED: |
| 527 Update(tab_contents); |
| 528 break; |
485 default: | 529 default: |
486 NOTREACHED() << "Unexpected notification."; | 530 NOTREACHED() << "Unexpected notification."; |
487 return; | 531 return; |
488 } | 532 } |
489 } | 533 } |
490 | 534 |
491 //////////////////////////////////////////////////////////////////////////////// | 535 //////////////////////////////////////////////////////////////////////////////// |
492 // TaskManagerBackgroundContentsResource class | 536 // TaskManagerBackgroundContentsResource class |
493 //////////////////////////////////////////////////////////////////////////////// | 537 //////////////////////////////////////////////////////////////////////////////// |
494 | 538 |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 if (!default_icon_) { | 1105 if (!default_icon_) { |
1062 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1106 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1063 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 1107 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); |
1064 } | 1108 } |
1065 process_handle_ = extension_host_->render_process_host()->GetHandle(); | 1109 process_handle_ = extension_host_->render_process_host()->GetHandle(); |
1066 pid_ = base::GetProcId(process_handle_); | 1110 pid_ = base::GetProcId(process_handle_); |
1067 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); | 1111 string16 extension_name = UTF8ToUTF16(GetExtension()->name()); |
1068 DCHECK(!extension_name.empty()); | 1112 DCHECK(!extension_name.empty()); |
1069 | 1113 |
1070 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, | 1114 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, |
1071 extension_host_->profile()->IsOffTheRecord(), false); | 1115 extension_host_->profile()->IsOffTheRecord(), false, false); |
1072 title_ = l10n_util::GetStringFUTF16(message_id, extension_name); | 1116 title_ = l10n_util::GetStringFUTF16(message_id, extension_name); |
1073 } | 1117 } |
1074 | 1118 |
1075 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { | 1119 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { |
1076 } | 1120 } |
1077 | 1121 |
1078 string16 TaskManagerExtensionProcessResource::GetTitle() const { | 1122 string16 TaskManagerExtensionProcessResource::GetTitle() const { |
1079 return title_; | 1123 return title_; |
1080 } | 1124 } |
1081 | 1125 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 | 1436 |
1393 return &resource_; | 1437 return &resource_; |
1394 } | 1438 } |
1395 | 1439 |
1396 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1440 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
1397 task_manager_->AddResource(&resource_); | 1441 task_manager_->AddResource(&resource_); |
1398 } | 1442 } |
1399 | 1443 |
1400 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1444 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
1401 } | 1445 } |
OLD | NEW |