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

Side by Side Diff: chrome/browser/memory/tab_manager.cc

Issue 2034573002: [Cleanup] Factor out common code. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wherein we relearn that "commit -a" doesn't add new files. Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 18 matching lines...) Expand all
29 #include "build/build_config.h" 29 #include "build/build_config.h"
30 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 31 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
32 #include "chrome/browser/media/media_stream_capture_indicator.h" 32 #include "chrome/browser/media/media_stream_capture_indicator.h"
33 #include "chrome/browser/memory/oom_memory_details.h" 33 #include "chrome/browser/memory/oom_memory_details.h"
34 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 34 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
35 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/ui/browser.h" 36 #include "chrome/browser/ui/browser.h"
37 #include "chrome/browser/ui/browser_list.h" 37 #include "chrome/browser/ui/browser_list.h"
38 #include "chrome/browser/ui/browser_window.h" 38 #include "chrome/browser/ui/browser_window.h"
39 #include "chrome/browser/ui/chrome_pages.h"
39 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 40 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
40 #include "chrome/browser/ui/tabs/tab_strip_model.h" 41 #include "chrome/browser/ui/tabs/tab_strip_model.h"
41 #include "chrome/browser/ui/tabs/tab_utils.h" 42 #include "chrome/browser/ui/tabs/tab_utils.h"
42 #include "chrome/common/chrome_constants.h" 43 #include "chrome/common/chrome_constants.h"
43 #include "chrome/common/chrome_features.h" 44 #include "chrome/common/chrome_features.h"
44 #include "chrome/common/chrome_switches.h" 45 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/url_constants.h" 46 #include "chrome/common/url_constants.h"
46 #include "components/metrics/system_memory_stats_recorder.h" 47 #include "components/metrics/system_memory_stats_recorder.h"
47 #include "components/variations/variations_associated_data.h" 48 #include "components/variations/variations_associated_data.h"
48 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 351
351 // static 352 // static
352 void TabManager::PurgeMemoryAndDiscardTab() { 353 void TabManager::PurgeMemoryAndDiscardTab() {
353 if (g_browser_process && g_browser_process->GetTabManager()) { 354 if (g_browser_process && g_browser_process->GetTabManager()) {
354 TabManager* manager = g_browser_process->GetTabManager(); 355 TabManager* manager = g_browser_process->GetTabManager();
355 manager->PurgeBrowserMemory(); 356 manager->PurgeBrowserMemory();
356 manager->DiscardTab(); 357 manager->DiscardTab();
357 } 358 }
358 } 359 }
359 360
360 // static
361 bool TabManager::IsInternalPage(const GURL& url) {
362 // There are many chrome:// UI URLs, but only look for the ones that users
363 // are likely to have open. Most of the benefit is the from NTP URL.
364 const char* const kInternalPagePrefixes[] = {
365 chrome::kChromeUIDownloadsURL, chrome::kChromeUIHistoryURL,
366 chrome::kChromeUINewTabURL, chrome::kChromeUISettingsURL,
367 };
368 // Prefix-match against the table above. Use strncmp to avoid allocating
369 // memory to convert the URL prefix constants into std::strings.
370 for (size_t i = 0; i < arraysize(kInternalPagePrefixes); ++i) {
371 if (!strncmp(url.spec().c_str(), kInternalPagePrefixes[i],
372 strlen(kInternalPagePrefixes[i])))
373 return true;
374 }
375 return false;
376 }
377
378 void TabManager::RecordDiscardStatistics() { 361 void TabManager::RecordDiscardStatistics() {
379 discard_count_++; 362 discard_count_++;
380 363
381 // TODO(jamescook): Maybe incorporate extension count? 364 // TODO(jamescook): Maybe incorporate extension count?
382 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.Discard.TabCount", GetTabCount(), 1, 100, 365 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.Discard.TabCount", GetTabCount(), 1, 100,
383 50); 366 50);
384 #if defined(OS_CHROMEOS) 367 #if defined(OS_CHROMEOS)
385 // Record the discarded tab in relation to the amount of simultaneously 368 // Record the discarded tab in relation to the amount of simultaneously
386 // logged in users. 369 // logged in users.
387 if (ash::Shell::HasInstance()) { 370 if (ash::Shell::HasInstance()) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 void TabManager::AddTabStats(const TabStripModel* model, 456 void TabManager::AddTabStats(const TabStripModel* model,
474 bool is_app, 457 bool is_app,
475 bool active_model, 458 bool active_model,
476 TabStatsList* stats_list) { 459 TabStatsList* stats_list) {
477 for (int i = 0; i < model->count(); i++) { 460 for (int i = 0; i < model->count(); i++) {
478 WebContents* contents = model->GetWebContentsAt(i); 461 WebContents* contents = model->GetWebContentsAt(i);
479 if (!contents->IsCrashed()) { 462 if (!contents->IsCrashed()) {
480 TabStats stats; 463 TabStats stats;
481 stats.is_app = is_app; 464 stats.is_app = is_app;
482 stats.is_internal_page = 465 stats.is_internal_page =
483 IsInternalPage(contents->GetLastCommittedURL()); 466 chrome::IsInternalPage(contents->GetLastCommittedURL());
484 stats.is_media = IsMediaTab(contents); 467 stats.is_media = IsMediaTab(contents);
485 stats.is_pinned = model->IsTabPinned(i); 468 stats.is_pinned = model->IsTabPinned(i);
486 stats.is_selected = active_model && model->IsTabSelected(i); 469 stats.is_selected = active_model && model->IsTabSelected(i);
487 stats.is_discarded = GetWebContentsData(contents)->IsDiscarded(); 470 stats.is_discarded = GetWebContentsData(contents)->IsDiscarded();
488 stats.has_form_entry = 471 stats.has_form_entry =
489 contents->GetPageImportanceSignals().had_form_interaction; 472 contents->GetPageImportanceSignals().had_form_interaction;
490 stats.discard_count = GetWebContentsData(contents)->DiscardCount(); 473 stats.discard_count = GetWebContentsData(contents)->DiscardCount();
491 stats.last_active = contents->GetLastActiveTime(); 474 stats.last_active = contents->GetLastActiveTime();
492 stats.render_process_host = contents->GetRenderProcessHost(); 475 stats.render_process_host = contents->GetRenderProcessHost();
493 stats.renderer_handle = contents->GetRenderProcessHost()->GetHandle(); 476 stats.renderer_handle = contents->GetRenderProcessHost()->GetHandle();
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 867 }
885 } else { 868 } else {
886 // The code here can only be tested under a full browser test. 869 // The code here can only be tested under a full browser test.
887 AddTabStats(&stats_list); 870 AddTabStats(&stats_list);
888 } 871 }
889 872
890 return stats_list; 873 return stats_list;
891 } 874 }
892 875
893 } // namespace memory 876 } // namespace memory
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager_unittest.cc » ('j') | chrome/browser/ui/chrome_pages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698