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

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

Issue 9030032: Get rid of a bunch of tab_contents.h includes from chrome. These are all trivial changes to use W... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 11 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 (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"
(...skipping 26 matching lines...) Expand all
37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
38 #include "chrome/common/chrome_notification_types.h" 38 #include "chrome/common/chrome_notification_types.h"
39 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/chrome_view_type.h" 40 #include "chrome/common/chrome_view_type.h"
41 #include "chrome/common/extensions/extension.h" 41 #include "chrome/common/extensions/extension.h"
42 #include "chrome/common/render_messages.h" 42 #include "chrome/common/render_messages.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
44 #include "content/browser/browser_child_process_host.h" 44 #include "content/browser/browser_child_process_host.h"
45 #include "content/browser/renderer_host/render_message_filter.h" 45 #include "content/browser/renderer_host/render_message_filter.h"
46 #include "content/browser/renderer_host/render_view_host.h" 46 #include "content/browser/renderer_host/render_view_host.h"
47 #include "content/browser/tab_contents/tab_contents.h"
48 #include "content/public/browser/browser_thread.h" 47 #include "content/public/browser/browser_thread.h"
49 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/render_process_host.h" 49 #include "content/public/browser/render_process_host.h"
50 #include "content/public/browser/web_contents.h"
51 #include "content/public/common/process_type.h" 51 #include "content/public/common/process_type.h"
52 #include "grit/generated_resources.h" 52 #include "grit/generated_resources.h"
53 #include "grit/theme_resources.h" 53 #include "grit/theme_resources.h"
54 #include "grit/theme_resources_standard.h" 54 #include "grit/theme_resources_standard.h"
55 #include "third_party/sqlite/sqlite3.h" 55 #include "third_party/sqlite/sqlite3.h"
56 #include "ui/base/l10n/l10n_util.h" 56 #include "ui/base/l10n/l10n_util.h"
57 #include "ui/base/resource/resource_bundle.h" 57 #include "ui/base/resource/resource_bundle.h"
58 #include "v8/include/v8.h" 58 #include "v8/include/v8.h"
59 59
60 #if defined(OS_MACOSX) 60 #if defined(OS_MACOSX)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 //////////////////////////////////////////////////////////////////////////////// 214 ////////////////////////////////////////////////////////////////////////////////
215 // TaskManagerTabContentsResource class 215 // TaskManagerTabContentsResource class
216 //////////////////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////////////////
217 217
218 // static 218 // static
219 SkBitmap* TaskManagerTabContentsResource::prerender_icon_ = NULL; 219 SkBitmap* TaskManagerTabContentsResource::prerender_icon_ = NULL;
220 220
221 TaskManagerTabContentsResource::TaskManagerTabContentsResource( 221 TaskManagerTabContentsResource::TaskManagerTabContentsResource(
222 TabContentsWrapper* tab_contents) 222 TabContentsWrapper* tab_contents)
223 : TaskManagerRendererResource( 223 : TaskManagerRendererResource(
224 tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(), 224 tab_contents->web_contents()->GetRenderProcessHost()->GetHandle(),
225 tab_contents->tab_contents()->GetRenderViewHost()), 225 tab_contents->web_contents()->GetRenderViewHost()),
226 tab_contents_(tab_contents), 226 tab_contents_(tab_contents),
227 is_instant_preview_(false) { 227 is_instant_preview_(false) {
228 if (!prerender_icon_) { 228 if (!prerender_icon_) {
229 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 229 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
230 prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER); 230 prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER);
231 } 231 }
232 for (BrowserList::const_iterator i = BrowserList::begin(); 232 for (BrowserList::const_iterator i = BrowserList::begin();
233 i != BrowserList::end(); ++i) { 233 i != BrowserList::end(); ++i) {
234 if ((*i)->instant() && 234 if ((*i)->instant() &&
235 (*i)->instant()->GetPreviewContents() == tab_contents_) { 235 (*i)->instant()->GetPreviewContents() == tab_contents_) {
(...skipping 10 matching lines...) Expand all
246 DCHECK(is_instant_preview_); 246 DCHECK(is_instant_preview_);
247 is_instant_preview_ = false; 247 is_instant_preview_ = false;
248 } 248 }
249 249
250 bool TaskManagerTabContentsResource::IsPrerendering() const { 250 bool TaskManagerTabContentsResource::IsPrerendering() const {
251 prerender::PrerenderManager* prerender_manager = 251 prerender::PrerenderManager* prerender_manager =
252 prerender::PrerenderManagerFactory::GetForProfile( 252 prerender::PrerenderManagerFactory::GetForProfile(
253 tab_contents_->profile()); 253 tab_contents_->profile());
254 return prerender_manager && 254 return prerender_manager &&
255 prerender_manager->IsWebContentsPrerendering( 255 prerender_manager->IsWebContentsPrerendering(
256 tab_contents_->tab_contents()); 256 tab_contents_->web_contents());
257 } 257 }
258 258
259 bool TaskManagerTabContentsResource::HostsExtension() const { 259 bool TaskManagerTabContentsResource::HostsExtension() const {
260 return tab_contents_->tab_contents()->GetURL().SchemeIs( 260 return tab_contents_->web_contents()->GetURL().SchemeIs(
261 chrome::kExtensionScheme); 261 chrome::kExtensionScheme);
262 } 262 }
263 263
264 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { 264 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const {
265 return HostsExtension() ? EXTENSION : RENDERER; 265 return HostsExtension() ? EXTENSION : RENDERER;
266 } 266 }
267 267
268 string16 TaskManagerTabContentsResource::GetTitle() const { 268 string16 TaskManagerTabContentsResource::GetTitle() const {
269 // Fall back on the URL if there's no title. 269 // Fall back on the URL if there's no title.
270 TabContents* contents = tab_contents_->tab_contents(); 270 WebContents* contents = tab_contents_->web_contents();
271 string16 tab_title = contents->GetTitle(); 271 string16 tab_title = contents->GetTitle();
272 GURL url = contents->GetURL(); 272 GURL url = contents->GetURL();
273 if (tab_title.empty()) { 273 if (tab_title.empty()) {
274 tab_title = UTF8ToUTF16(url.spec()); 274 tab_title = UTF8ToUTF16(url.spec());
275 // Force URL to be LTR. 275 // Force URL to be LTR.
276 tab_title = base::i18n::GetDisplayStringInLTRDirectionality(tab_title); 276 tab_title = base::i18n::GetDisplayStringInLTRDirectionality(tab_title);
277 } else { 277 } else {
278 // Since the tab_title will be concatenated with 278 // Since the tab_title will be concatenated with
279 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to 279 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to
280 // be LTR format if there is no strong RTL charater in it. Otherwise, if 280 // be LTR format if there is no strong RTL charater in it. Otherwise, if
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 TabContentsWrapper* TaskManagerTabContentsResource::GetTabContents() const { 325 TabContentsWrapper* TaskManagerTabContentsResource::GetTabContents() const {
326 return tab_contents_; 326 return tab_contents_;
327 } 327 }
328 328
329 const Extension* TaskManagerTabContentsResource::GetExtension() const { 329 const Extension* TaskManagerTabContentsResource::GetExtension() const {
330 if (HostsExtension()) { 330 if (HostsExtension()) {
331 ExtensionService* extension_service = 331 ExtensionService* extension_service =
332 tab_contents_->profile()->GetExtensionService(); 332 tab_contents_->profile()->GetExtensionService();
333 return extension_service->extensions()->GetByID( 333 return extension_service->extensions()->GetByID(
334 tab_contents_->tab_contents()->GetURL().host()); 334 tab_contents_->web_contents()->GetURL().host());
335 } 335 }
336 336
337 return NULL; 337 return NULL;
338 } 338 }
339 339
340 //////////////////////////////////////////////////////////////////////////////// 340 ////////////////////////////////////////////////////////////////////////////////
341 // TaskManagerTabContentsResourceProvider class 341 // TaskManagerTabContentsResourceProvider class
342 //////////////////////////////////////////////////////////////////////////////// 342 ////////////////////////////////////////////////////////////////////////////////
343 343
344 TaskManagerTabContentsResourceProvider:: 344 TaskManagerTabContentsResourceProvider::
345 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) 345 TaskManagerTabContentsResourceProvider(TaskManager* task_manager)
346 : updating_(false), 346 : updating_(false),
347 task_manager_(task_manager) { 347 task_manager_(task_manager) {
348 } 348 }
349 349
350 TaskManagerTabContentsResourceProvider:: 350 TaskManagerTabContentsResourceProvider::
351 ~TaskManagerTabContentsResourceProvider() { 351 ~TaskManagerTabContentsResourceProvider() {
352 } 352 }
353 353
354 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( 354 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource(
355 int origin_pid, 355 int origin_pid,
356 int render_process_host_id, 356 int render_process_host_id,
357 int routing_id) { 357 int routing_id) {
358 TabContents* tab_contents = 358 WebContents* web_contents =
359 tab_util::GetTabContentsByID(render_process_host_id, routing_id); 359 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
360 if (!tab_contents) // Not one of our resource. 360 if (!web_contents) // Not one of our resource.
361 return NULL; 361 return NULL;
362 362
363 // If an origin PID was specified then the request originated in a plugin 363 // If an origin PID was specified then the request originated in a plugin
364 // working on the TabContent's behalf, so ignore it. 364 // working on the TabContent's behalf, so ignore it.
365 if (origin_pid) 365 if (origin_pid)
366 return NULL; 366 return NULL;
367 367
368 TabContentsWrapper* wrapper = 368 TabContentsWrapper* wrapper =
369 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); 369 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
370 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator 370 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator
371 res_iter = resources_.find(wrapper); 371 res_iter = resources_.find(wrapper);
372 if (res_iter == resources_.end()) { 372 if (res_iter == resources_.end()) {
373 // Can happen if the tab was closed while a network request was being 373 // Can happen if the tab was closed while a network request was being
374 // performed. 374 // performed.
375 return NULL; 375 return NULL;
376 } 376 }
377 return res_iter->second; 377 return res_iter->second;
378 } 378 }
379 379
380 void TaskManagerTabContentsResourceProvider::StartUpdating() { 380 void TaskManagerTabContentsResourceProvider::StartUpdating() {
381 DCHECK(!updating_); 381 DCHECK(!updating_);
382 updating_ = true; 382 updating_ = true;
383 383
384 // Add all the existing TabContents. 384 // Add all the existing TabContents.
385 for (TabContentsIterator iterator; !iterator.done(); ++iterator) 385 for (TabContentsIterator iterator; !iterator.done(); ++iterator)
386 Add(*iterator); 386 Add(*iterator);
387 387
388 // Then we register for notifications to get new tabs. 388 // Then we register for notifications to get new tabs.
389 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, 389 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
390 content::NotificationService::AllBrowserContextsAndSources()); 390 content::NotificationService::AllBrowserContextsAndSources());
391 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 391 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
392 content::NotificationService::AllBrowserContextsAndSources()); 392 content::NotificationService::AllBrowserContextsAndSources());
393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
394 content::NotificationService::AllBrowserContextsAndSources()); 394 content::NotificationService::AllBrowserContextsAndSources());
395 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a 395 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a
396 // resource. This is an attempt at mitigating a crasher that seem to 396 // resource. This is an attempt at mitigating a crasher that seem to
397 // indicate a resource is still referencing a deleted TabContents 397 // indicate a resource is still referencing a deleted TabContents
398 // (http://crbug.com/7321). 398 // (http://crbug.com/7321).
399 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 399 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
400 content::NotificationService::AllBrowserContextsAndSources()); 400 content::NotificationService::AllBrowserContextsAndSources());
401 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, 401 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
402 content::NotificationService::AllBrowserContextsAndSources()); 402 content::NotificationService::AllBrowserContextsAndSources());
403 } 403 }
404 404
405 void TaskManagerTabContentsResourceProvider::StopUpdating() { 405 void TaskManagerTabContentsResourceProvider::StopUpdating() {
406 DCHECK(updating_); 406 DCHECK(updating_);
407 updating_ = false; 407 updating_ = false;
408 408
409 // Then we unregister for notifications to get new tabs. 409 // Then we unregister for notifications to get new tabs.
410 registrar_.Remove( 410 registrar_.Remove(
411 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, 411 this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
412 content::NotificationService::AllBrowserContextsAndSources()); 412 content::NotificationService::AllBrowserContextsAndSources());
413 registrar_.Remove( 413 registrar_.Remove(
414 this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 414 this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
415 content::NotificationService::AllBrowserContextsAndSources()); 415 content::NotificationService::AllBrowserContextsAndSources());
416 registrar_.Remove( 416 registrar_.Remove(
417 this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 417 this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
418 content::NotificationService::AllBrowserContextsAndSources()); 418 content::NotificationService::AllBrowserContextsAndSources());
419 registrar_.Remove( 419 registrar_.Remove(
420 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 420 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
421 content::NotificationService::AllBrowserContextsAndSources()); 421 content::NotificationService::AllBrowserContextsAndSources());
(...skipping 14 matching lines...) Expand all
436 resources_[tab_contents] = resource; 436 resources_[tab_contents] = resource;
437 task_manager_->AddResource(resource); 437 task_manager_->AddResource(resource);
438 } 438 }
439 439
440 void TaskManagerTabContentsResourceProvider::Add( 440 void TaskManagerTabContentsResourceProvider::Add(
441 TabContentsWrapper* tab_contents) { 441 TabContentsWrapper* tab_contents) {
442 if (!updating_) 442 if (!updating_)
443 return; 443 return;
444 444
445 // Don't add dead tabs or tabs that haven't yet connected. 445 // Don't add dead tabs or tabs that haven't yet connected.
446 if (!tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle() || 446 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() ||
447 !tab_contents->tab_contents()->WillNotifyDisconnection()) { 447 !tab_contents->web_contents()->WillNotifyDisconnection()) {
448 return; 448 return;
449 } 449 }
450 450
451 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::const_iterator 451 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::const_iterator
452 iter = resources_.find(tab_contents); 452 iter = resources_.find(tab_contents);
453 if (iter != resources_.end()) { 453 if (iter != resources_.end()) {
454 // The case may happen that we have added a TabContents as part of the 454 // The case may happen that we have added a TabContents as part of the
455 // iteration performed during StartUpdating() call but the notification that 455 // iteration performed during StartUpdating() call but the notification that
456 // it has connected was not fired yet. So when the notification happens, we 456 // it has connected was not fired yet. So when the notification happens, we
457 // already know about this tab and just ignore it. 457 // already know about this tab and just ignore it.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 if (iter != resources_.end()) 493 if (iter != resources_.end())
494 iter->second->InstantCommitted(); 494 iter->second->InstantCommitted();
495 } 495 }
496 496
497 void TaskManagerTabContentsResourceProvider::Observe(int type, 497 void TaskManagerTabContentsResourceProvider::Observe(int type,
498 const content::NotificationSource& source, 498 const content::NotificationSource& source,
499 const content::NotificationDetails& details) { 499 const content::NotificationDetails& details) {
500 TabContentsWrapper* tab_contents; 500 TabContentsWrapper* tab_contents;
501 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { 501 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) {
502 tab_contents = content::Source<TabContentsWrapper>(source).ptr(); 502 tab_contents = content::Source<TabContentsWrapper>(source).ptr();
503 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED ||
504 type == content::NOTIFICATION_WEB_CONTENTS_SWAPPED) {
505 WebContents* web_contents = content::Source<WebContents>(source).ptr();
506 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents(
507 web_contents);
508 } else { 503 } else {
509 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( 504 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents(
510 content::Source<TabContents>(source).ptr()); 505 content::Source<WebContents>(source).ptr());
511 } 506 }
512 // A background page does not have a TabContentsWrapper. 507 // A background page does not have a TabContentsWrapper.
513 if (!tab_contents) 508 if (!tab_contents)
514 return; 509 return;
515 switch (type) { 510 switch (type) {
516 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: 511 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
517 Add(tab_contents); 512 Add(tab_contents);
518 break; 513 break;
519 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: 514 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED:
520 Remove(tab_contents); 515 Remove(tab_contents);
521 Add(tab_contents); 516 Add(tab_contents);
522 break; 517 break;
523 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 518 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
524 // If this DCHECK is triggered, it could explain http://crbug.com/7321 . 519 // If this DCHECK is triggered, it could explain http://crbug.com/7321 .
525 DCHECK(resources_.find(tab_contents) == 520 DCHECK(resources_.find(tab_contents) ==
526 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated " 521 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated "
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 1441
1447 return &resource_; 1442 return &resource_;
1448 } 1443 }
1449 1444
1450 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { 1445 void TaskManagerBrowserProcessResourceProvider::StartUpdating() {
1451 task_manager_->AddResource(&resource_); 1446 task_manager_->AddResource(&resource_);
1452 } 1447 }
1453 1448
1454 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { 1449 void TaskManagerBrowserProcessResourceProvider::StopUpdating() {
1455 } 1450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698