Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/task_manager/task_manager_resource_providers.cc

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
21 #include "chrome/app/chrome_command_ids.h" 21 #include "chrome/app/chrome_command_ids.h"
22 #include "chrome/browser/background/background_contents_service.h" 22 #include "chrome/browser/background/background_contents_service.h"
23 #include "chrome/browser/background/background_contents_service_factory.h" 23 #include "chrome/browser/background/background_contents_service_factory.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/devtools/devtools_window.h" 25 #include "chrome/browser/devtools/devtools_window.h"
26 #include "chrome/browser/extensions/extension_host.h" 26 #include "chrome/browser/extensions/extension_host.h"
27 #include "chrome/browser/extensions/extension_process_manager.h" 27 #include "chrome/browser/extensions/extension_process_manager.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
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/instant/instant_controller.h"
32 #include "chrome/browser/instant/instant_loader.h"
33 #include "chrome/browser/instant/instant_service.h"
34 #include "chrome/browser/instant/instant_service_factory.h"
31 #include "chrome/browser/prerender/prerender_manager.h" 35 #include "chrome/browser/prerender/prerender_manager.h"
32 #include "chrome/browser/prerender/prerender_manager_factory.h" 36 #include "chrome/browser/prerender/prerender_manager_factory.h"
33 #include "chrome/browser/printing/background_printing_manager.h" 37 #include "chrome/browser/printing/background_printing_manager.h"
34 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/profiles/profile_info_cache.h" 39 #include "chrome/browser/profiles/profile_info_cache.h"
36 #include "chrome/browser/profiles/profile_manager.h" 40 #include "chrome/browser/profiles/profile_manager.h"
37 #include "chrome/browser/tab_contents/background_contents.h" 41 #include "chrome/browser/tab_contents/background_contents.h"
38 #include "chrome/browser/tab_contents/tab_util.h" 42 #include "chrome/browser/tab_contents/tab_util.h"
39 #include "chrome/browser/ui/browser.h" 43 #include "chrome/browser/ui/browser.h"
40 #include "chrome/browser/ui/browser_finder.h" 44 #include "chrome/browser/ui/browser_finder.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 using extensions::Extension; 88 using extensions::Extension;
85 89
86 namespace { 90 namespace {
87 91
88 // Returns the appropriate message prefix ID for tabs and extensions, 92 // Returns the appropriate message prefix ID for tabs and extensions,
89 // reflecting whether they are apps or in incognito mode. 93 // reflecting whether they are apps or in incognito mode.
90 int GetMessagePrefixID(bool is_app, 94 int GetMessagePrefixID(bool is_app,
91 bool is_extension, 95 bool is_extension,
92 bool is_incognito, 96 bool is_incognito,
93 bool is_prerender, 97 bool is_prerender,
94 bool is_instant_preview, 98 bool is_instant_overlay,
95 bool is_background) { 99 bool is_background) {
96 if (is_app) { 100 if (is_app) {
97 if (is_background) { 101 if (is_background) {
98 return IDS_TASK_MANAGER_BACKGROUND_PREFIX; 102 return IDS_TASK_MANAGER_BACKGROUND_PREFIX;
99 } else if (is_incognito) { 103 } else if (is_incognito) {
100 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; 104 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
101 } else { 105 } else {
102 return IDS_TASK_MANAGER_APP_PREFIX; 106 return IDS_TASK_MANAGER_APP_PREFIX;
103 } 107 }
104 } else if (is_extension) { 108 } else if (is_extension) {
105 if (is_incognito) 109 if (is_incognito)
106 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; 110 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX;
107 else 111 else
108 return IDS_TASK_MANAGER_EXTENSION_PREFIX; 112 return IDS_TASK_MANAGER_EXTENSION_PREFIX;
109 } else if (is_prerender) { 113 } else if (is_prerender) {
110 return IDS_TASK_MANAGER_PRERENDER_PREFIX; 114 return IDS_TASK_MANAGER_PRERENDER_PREFIX;
111 } else if (is_instant_preview) { 115 } else if (is_instant_overlay) {
112 return IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX; 116 return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX;
113 } else { 117 } else {
114 return IDS_TASK_MANAGER_TAB_PREFIX; 118 return IDS_TASK_MANAGER_TAB_PREFIX;
115 } 119 }
116 } 120 }
117 121
118 string16 GetProfileNameFromInfoCache(Profile* profile) { 122 string16 GetProfileNameFromInfoCache(Profile* profile) {
119 ProfileInfoCache& cache = 123 ProfileInfoCache& cache =
120 g_browser_process->profile_manager()->GetProfileInfoCache(); 124 g_browser_process->profile_manager()->GetProfileInfoCache();
121 size_t index = cache.GetIndexOfProfileWithPath( 125 size_t index = cache.GetIndexOfProfileWithPath(
122 profile->GetOriginalProfile()->GetPath()); 126 profile->GetOriginalProfile()->GetPath());
(...skipping 28 matching lines...) Expand all
151 bool IsContentsPrerendering(WebContents* web_contents) { 155 bool IsContentsPrerendering(WebContents* web_contents) {
152 Profile* profile = 156 Profile* profile =
153 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 157 Profile::FromBrowserContext(web_contents->GetBrowserContext());
154 prerender::PrerenderManager* prerender_manager = 158 prerender::PrerenderManager* prerender_manager =
155 prerender::PrerenderManagerFactory::GetForProfile(profile); 159 prerender::PrerenderManagerFactory::GetForProfile(profile);
156 return prerender_manager && 160 return prerender_manager &&
157 prerender_manager->IsWebContentsPrerendering(web_contents, NULL); 161 prerender_manager->IsWebContentsPrerendering(web_contents, NULL);
158 } 162 }
159 163
160 bool IsContentsInstant(WebContents* web_contents) { 164 bool IsContentsInstant(WebContents* web_contents) {
165 Profile* profile =
166 Profile::FromBrowserContext(web_contents->GetBrowserContext());
167 InstantService* instant_service =
168 InstantServiceFactory::GetForProfile(profile);
169 if (instant_service && instant_service->loader()->contents() == web_contents)
170 return true;
171
161 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 172 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
162 if (it->instant_controller() && 173 if (it->instant_controller() &&
163 it->instant_controller()->instant()-> 174 it->instant_controller()->instant()->
164 GetPreviewContents() == web_contents) { 175 GetOverlayContents() == web_contents) {
165 return true; 176 return true;
166 } 177 }
167 } 178 }
168 179
169 return false; 180 return false;
170 } 181 }
171 182
172 bool IsContentsBackgroundPrinted(WebContents* web_contents) { 183 bool IsContentsBackgroundPrinted(WebContents* web_contents) {
173 printing::BackgroundPrintingManager* printing_manager = 184 printing::BackgroundPrintingManager* printing_manager =
174 g_browser_process->background_printing_manager(); 185 g_browser_process->background_printing_manager();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // static 309 // static
299 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; 310 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL;
300 311
301 TaskManagerTabContentsResource::TaskManagerTabContentsResource( 312 TaskManagerTabContentsResource::TaskManagerTabContentsResource(
302 WebContents* web_contents) 313 WebContents* web_contents)
303 : TaskManagerRendererResource( 314 : TaskManagerRendererResource(
304 web_contents->GetRenderProcessHost()->GetHandle(), 315 web_contents->GetRenderProcessHost()->GetHandle(),
305 web_contents->GetRenderViewHost()), 316 web_contents->GetRenderViewHost()),
306 web_contents_(web_contents), 317 web_contents_(web_contents),
307 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 318 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
308 is_instant_preview_(IsContentsInstant(web_contents)) { 319 is_instant_overlay_(IsContentsInstant(web_contents)) {
309 if (!prerender_icon_) { 320 if (!prerender_icon_) {
310 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 321 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
311 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); 322 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER);
312 } 323 }
313 } 324 }
314 325
315 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { 326 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() {
316 } 327 }
317 328
318 void TaskManagerTabContentsResource::InstantCommitted() { 329 void TaskManagerTabContentsResource::InstantCommitted() {
319 DCHECK(is_instant_preview_); 330 DCHECK(is_instant_overlay_);
320 is_instant_preview_ = false; 331 is_instant_overlay_ = false;
321 } 332 }
322 333
323 bool TaskManagerTabContentsResource::HostsExtension() const { 334 bool TaskManagerTabContentsResource::HostsExtension() const {
324 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme); 335 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme);
325 } 336 }
326 337
327 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { 338 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const {
328 return HostsExtension() ? EXTENSION : RENDERER; 339 return HostsExtension() ? EXTENSION : RENDERER;
329 } 340 }
330 341
331 string16 TaskManagerTabContentsResource::GetTitle() const { 342 string16 TaskManagerTabContentsResource::GetTitle() const {
332 // Fall back on the URL if there's no title. 343 // Fall back on the URL if there's no title.
333 GURL url = web_contents_->GetURL(); 344 GURL url = web_contents_->GetURL();
334 string16 tab_title = GetTitleFromWebContents(web_contents_); 345 string16 tab_title = GetTitleFromWebContents(web_contents_);
335 346
336 // Only classify as an app if the URL is an app and the tab is hosting an 347 // Only classify as an app if the URL is an app and the tab is hosting an
337 // extension process. (It's possible to be showing the URL from before it 348 // extension process. (It's possible to be showing the URL from before it
338 // was installed as an app.) 349 // was installed as an app.)
339 ExtensionService* extension_service = profile_->GetExtensionService(); 350 ExtensionService* extension_service = profile_->GetExtensionService();
340 extensions::ProcessMap* process_map = extension_service->process_map(); 351 extensions::ProcessMap* process_map = extension_service->process_map();
341 bool is_app = extension_service->IsInstalledApp(url) && 352 bool is_app = extension_service->IsInstalledApp(url) &&
342 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); 353 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID());
343 354
344 int message_id = GetMessagePrefixID( 355 int message_id = GetMessagePrefixID(
345 is_app, 356 is_app,
346 HostsExtension(), 357 HostsExtension(),
347 profile_->IsOffTheRecord(), 358 profile_->IsOffTheRecord(),
348 IsContentsPrerendering(web_contents_), 359 IsContentsPrerendering(web_contents_),
349 is_instant_preview_, 360 is_instant_overlay_,
350 false); 361 false);
351 return l10n_util::GetStringFUTF16(message_id, tab_title); 362 return l10n_util::GetStringFUTF16(message_id, tab_title);
352 } 363 }
353 364
354 string16 TaskManagerTabContentsResource::GetProfileName() const { 365 string16 TaskManagerTabContentsResource::GetProfileName() const {
355 return GetProfileNameFromInfoCache(profile_); 366 return GetProfileNameFromInfoCache(profile_);
356 } 367 }
357 368
358 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { 369 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const {
359 if (IsContentsPrerendering(web_contents_)) 370 if (IsContentsPrerendering(web_contents_))
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return NULL; 423 return NULL;
413 } 424 }
414 return res_iter->second; 425 return res_iter->second;
415 } 426 }
416 427
417 void TaskManagerTabContentsResourceProvider::StartUpdating() { 428 void TaskManagerTabContentsResourceProvider::StartUpdating() {
418 DCHECK(!updating_); 429 DCHECK(!updating_);
419 updating_ = true; 430 updating_ = true;
420 431
421 // The contents that are tracked by this resource provider are those that 432 // The contents that are tracked by this resource provider are those that
422 // are tab contents (WebContents serving as a tab in a Browser), instant 433 // are tab contents (WebContents serving as a tab in a Browser), Instant
423 // pages, prerender pages, and background printed pages. 434 // pages, prerender pages, and background printed pages.
424 435
425 // Add all the existing WebContentses. 436 // Add all the existing WebContentses.
426 for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) 437 for (TabContentsIterator iterator; !iterator.done(); iterator.Next())
427 Add(*iterator); 438 Add(*iterator);
428 439
429 // Add all the instant pages. 440 // Add all the Instant pages.
430 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 441 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
431 if (it->instant_controller() && 442 if (it->instant_controller() &&
432 it->instant_controller()->instant()->GetPreviewContents()) { 443 it->instant_controller()->instant()->GetOverlayContents()) {
433 Add(it->instant_controller()->instant()->GetPreviewContents()); 444 Add(it->instant_controller()->instant()->GetOverlayContents());
434 } 445 }
435 } 446 }
436 447
437 // Add all the prerender pages.
438 std::vector<Profile*> profiles( 448 std::vector<Profile*> profiles(
439 g_browser_process->profile_manager()->GetLoadedProfiles()); 449 g_browser_process->profile_manager()->GetLoadedProfiles());
440 for (size_t i = 0; i < profiles.size(); ++i) { 450 for (size_t i = 0; i < profiles.size(); ++i) {
451 // Add all the prerender pages.
441 prerender::PrerenderManager* prerender_manager = 452 prerender::PrerenderManager* prerender_manager =
442 prerender::PrerenderManagerFactory::GetForProfile(profiles[i]); 453 prerender::PrerenderManagerFactory::GetForProfile(profiles[i]);
443 if (prerender_manager) { 454 if (prerender_manager) {
444 const std::vector<content::WebContents*> contentses = 455 const std::vector<content::WebContents*> contentses =
445 prerender_manager->GetAllPrerenderingContents(); 456 prerender_manager->GetAllPrerenderingContents();
446 for (size_t j = 0; j < contentses.size(); ++j) 457 for (size_t j = 0; j < contentses.size(); ++j)
447 Add(contentses[j]); 458 Add(contentses[j]);
448 } 459 }
460
461 // Add the Instant per-profile page.
462 InstantService* instant_service =
463 InstantServiceFactory::GetForProfile(profiles[i]);
464 if (instant_service && instant_service->loader()->contents())
465 Add(instant_service->loader()->contents());
449 } 466 }
450 467
451 // Add all the pages being background printed. 468 // Add all the pages being background printed.
452 printing::BackgroundPrintingManager* printing_manager = 469 printing::BackgroundPrintingManager* printing_manager =
453 g_browser_process->background_printing_manager(); 470 g_browser_process->background_printing_manager();
454 for (printing::BackgroundPrintingManager::WebContentsSet::iterator i = 471 for (printing::BackgroundPrintingManager::WebContentsSet::iterator i =
455 printing_manager->begin(); 472 printing_manager->begin();
456 i != printing_manager->end(); ++i) { 473 i != printing_manager->end(); ++i) {
457 Add(*i); 474 Add(*i);
458 } 475 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 new TaskManagerTabContentsResource(web_contents); 511 new TaskManagerTabContentsResource(web_contents);
495 resources_[web_contents] = resource; 512 resources_[web_contents] = resource;
496 task_manager_->AddResource(resource); 513 task_manager_->AddResource(resource);
497 } 514 }
498 515
499 void TaskManagerTabContentsResourceProvider::Add(WebContents* web_contents) { 516 void TaskManagerTabContentsResourceProvider::Add(WebContents* web_contents) {
500 if (!updating_) 517 if (!updating_)
501 return; 518 return;
502 519
503 // The contents that are tracked by this resource provider are those that 520 // The contents that are tracked by this resource provider are those that
504 // are tab contents (WebContents serving as a tab in a Browser), instant 521 // are tab contents (WebContents serving as a tab in a Browser), Instant
505 // pages, prerender pages, and background printed pages. 522 // pages, prerender pages, and background printed pages.
506 if (!chrome::FindBrowserWithWebContents(web_contents) && 523 if (!chrome::FindBrowserWithWebContents(web_contents) &&
507 !IsContentsPrerendering(web_contents) && 524 !IsContentsPrerendering(web_contents) &&
508 !IsContentsInstant(web_contents) && 525 !IsContentsInstant(web_contents) &&
509 !IsContentsBackgroundPrinted(web_contents)) { 526 !IsContentsBackgroundPrinted(web_contents)) {
510 return; 527 return;
511 } 528 }
512 529
513 // Don't add dead tabs or tabs that haven't yet connected. 530 // Don't add dead tabs or tabs that haven't yet connected.
514 if (!web_contents->GetRenderProcessHost()->GetHandle() || 531 if (!web_contents->GetRenderProcessHost()->GetHandle() ||
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: 1943 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
1927 Add(web_contents->GetRenderViewHost()); 1944 Add(web_contents->GetRenderViewHost());
1928 break; 1945 break;
1929 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: 1946 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED:
1930 Remove(web_contents->GetRenderViewHost()); 1947 Remove(web_contents->GetRenderViewHost());
1931 break; 1948 break;
1932 default: 1949 default:
1933 NOTREACHED() << "Unexpected notification."; 1950 NOTREACHED() << "Unexpected notification.";
1934 } 1951 }
1935 } 1952 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698