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

Side by Side Diff: chrome/browser/ui/webui/about_ui.cc

Issue 1249693002: Improve the about/discards UI, allowing each tab to be individually closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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/ui/webui/about_ui.h" 5 #include "chrome/browser/ui/webui/about_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 11 matching lines...) Expand all
22 #include "base/strings/string_piece.h" 22 #include "base/strings/string_piece.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "chrome/browser/about_flags.h" 28 #include "chrome/browser/about_flags.h"
29 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/defaults.h" 30 #include "chrome/browser/defaults.h"
31 #include "chrome/browser/memory/oom_priority_manager.h" 31 #include "chrome/browser/memory/oom_priority_manager.h"
32 #include "chrome/browser/memory/tab_stats.h"
32 #include "chrome/browser/memory_details.h" 33 #include "chrome/browser/memory_details.h"
33 #include "chrome/browser/net/predictor.h" 34 #include "chrome/browser/net/predictor.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/profiles/profile_manager.h" 36 #include "chrome/browser/profiles/profile_manager.h"
36 #include "chrome/browser/ui/browser_dialogs.h" 37 #include "chrome/browser/ui/browser_dialogs.h"
37 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/render_messages.h" 39 #include "chrome/common/render_messages.h"
39 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
40 #include "chrome/grit/chromium_strings.h" 41 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 42 #include "chrome/grit/generated_resources.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return WrapWithTR(row); 483 return WrapWithTR(row);
483 } 484 }
484 485
485 void AddContentSecurityPolicy(std::string* output) { 486 void AddContentSecurityPolicy(std::string* output) {
486 output->append("<meta http-equiv='Content-Security-Policy' " 487 output->append("<meta http-equiv='Content-Security-Policy' "
487 "content='default-src 'none';'>"); 488 "content='default-src 'none';'>");
488 } 489 }
489 490
490 // TODO(stevenjb): L10N AboutDiscards. 491 // TODO(stevenjb): L10N AboutDiscards.
491 492
492 std::string AboutDiscardsRun() { 493 std::string BuildAboutDiscardsRunPage() {
493 std::string output; 494 std::string output;
494 AppendHeader(&output, 0, "About discards"); 495 AppendHeader(&output, 0, "About discards");
495 output.append( 496 output.append(
496 base::StringPrintf("<meta http-equiv='refresh' content='2;%s'>", 497 base::StringPrintf("<meta http-equiv='refresh' content='2;%s'>",
497 chrome::kChromeUIDiscardsURL)); 498 chrome::kChromeUIDiscardsURL));
498 AddContentSecurityPolicy(&output); 499 AddContentSecurityPolicy(&output);
499 output.append(WrapWithTag("p", "Discarding a tab...")); 500 output.append(WrapWithTag("p", "Discarding a tab..."));
500 g_browser_process->GetOomPriorityManager()->LogMemoryAndDiscardTab();
501 AppendFooter(&output); 501 AppendFooter(&output);
502 return output; 502 return output;
503 } 503 }
504 504
505 std::string AboutDiscardsRun(int64 web_content_id) {
Georges Khalil 2015/07/21 18:13:37 Let's give this a different name. How about AboutD
proberge 2015/07/21 18:29:07 I don't think that's a good name for it either. Do
Georges Khalil 2015/07/21 18:38:29 Yes, if possible. In that case, there's no reason
proberge 2015/07/21 18:55:09 Done.
506 g_browser_process->GetOomPriorityManager()->DiscardTabById(web_content_id);
507 return BuildAboutDiscardsRunPage();
508 }
509
510 std::string AboutDiscardsRun() {
511 g_browser_process->GetOomPriorityManager()->DiscardTab();
512 return BuildAboutDiscardsRunPage();
513 }
514
515 std::vector<std::string> GetTabLines() {
516 const char kRunCommand[] = "run";
517 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager();
518 memory::TabStatsList stats = oom->GetTabStats();
519 std::vector<std::string> titles;
520 titles.reserve(stats.size());
521 memory::TabStatsList::iterator it = stats.begin();
522 for (; it != stats.end(); ++it) {
523 base::string16 str;
524 str.reserve(4096);
525 str += base::ASCIIToUTF16("<b>");
526 str += base::ASCIIToUTF16(it->is_app ? "[App] " : "");
527 str += base::ASCIIToUTF16(it->is_internal_page ? "[Internal] " : "");
528 str += base::ASCIIToUTF16(it->is_playing_audio ? "[Audio] " : "");
529 str += base::ASCIIToUTF16(it->is_pinned ? "[Pinned] " : "");
530 str += base::ASCIIToUTF16(it->is_discarded ? "[Discarded] " : "");
531 str += base::ASCIIToUTF16("</b>");
532 str += net::EscapeForHTML(it->title);
533 #if defined(OS_CHROMEOS)
534 str += base::ASCIIToUTF16(base::StringPrintf(" %d ", it->oom_score));
Georges Khalil 2015/07/21 18:13:37 Let's wrap this in parenthesis for better clarity.
proberge 2015/07/21 18:29:07 I don't understand what to wrap - this is an #if,
Georges Khalil 2015/07/21 18:38:29 Should have been more specific. Let's wrap the sco
proberge 2015/07/21 18:55:09 Done.
535 #endif
536 if (!it->is_discarded) {
537 str += base::ASCIIToUTF16(
538 base::StringPrintf(" <a href='%s%s/%ld'>Discard</a>",
539 chrome::kChromeUIDiscardsURL,
540 kRunCommand,
541 it->tab_contents_id));
542 }
543 titles.push_back(base::UTF16ToUTF8((str)));
544 }
545 return titles;
546 }
547
505 std::string AboutDiscards(const std::string& path) { 548 std::string AboutDiscards(const std::string& path) {
506 std::string output; 549 std::string output;
550 std::vector<std::string> path_split;
551 int64 web_content_id;
507 const char kRunCommand[] = "run"; 552 const char kRunCommand[] = "run";
Georges Khalil 2015/07/21 18:13:37 Let's dedupe this and put it higher up and give it
proberge 2015/07/21 18:29:07 Done.
508 if (path == kRunCommand) 553
554 base::SplitString(path, '/', &path_split);
555 if (path_split.size() == 2 && path_split[0] == kRunCommand &&
556 base::StringToInt64(path_split[1], &web_content_id)) {
557 return AboutDiscardsRun(web_content_id);
558 } else if (path_split.size() == 1 && path_split[0] == kRunCommand) {
509 return AboutDiscardsRun(); 559 return AboutDiscardsRun();
560 }
561
510 AppendHeader(&output, 0, "About discards"); 562 AppendHeader(&output, 0, "About discards");
511 AddContentSecurityPolicy(&output); 563 AddContentSecurityPolicy(&output);
512 AppendBody(&output); 564 AppendBody(&output);
513 output.append("<h3>About discards</h3>"); 565 output.append("<h3>Discarded Tabs</h3>");
514 output.append( 566 output.append(
515 "<p>Tabs sorted from most interesting to least interesting. The least " 567 "<p>Tabs sorted from most interesting to least interesting. The least "
516 "interesting tab may be discarded if we run out of physical memory.</p>"); 568 "interesting tab may be discarded if we run out of physical memory.</p>");
517 569
518 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager(); 570 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager();
519 std::vector<base::string16> titles = oom->GetTabTitles(); 571 std::vector<std::string> titles = GetTabLines();
520 if (!titles.empty()) { 572 if (!titles.empty()) {
521 output.append("<ul>"); 573 output.append("<ul>");
522 std::vector<base::string16>::iterator it = titles.begin(); 574 std::vector<std::string>::iterator it = titles.begin();
523 for ( ; it != titles.end(); ++it) { 575 for ( ; it != titles.end(); ++it) {
524 std::string title = base::UTF16ToUTF8(*it); 576 output.append(WrapWithTag("li", *it));
525 title = net::EscapeForHTML(title);
526 output.append(WrapWithTag("li", title));
527 } 577 }
528 output.append("</ul>"); 578 output.append("</ul>");
529 } else { 579 } else {
530 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); 580 output.append("<p>None found. Wait 10 seconds, then refresh.</p>");
531 } 581 }
532 output.append(base::StringPrintf("%d discards this session. ", 582 output.append(
533 oom->discard_count())); 583 base::StringPrintf("%d discards this session. ", oom->discard_count()));
534 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>", 584 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>",
535 chrome::kChromeUIDiscardsURL, 585 chrome::kChromeUIDiscardsURL, kRunCommand));
536 kRunCommand)); 586
537 #if defined(OS_CHROMEOS) 587 #if defined(OS_CHROMEOS)
538 base::SystemMemoryInfoKB meminfo; 588 base::SystemMemoryInfoKB meminfo;
539 base::GetSystemMemoryInfo(&meminfo); 589 base::GetSystemMemoryInfo(&meminfo);
540 output.append("<h3>System memory information in MB</h3>"); 590 output.append("<h3>System memory information in MB</h3>");
541 output.append("<table>"); 591 output.append("<table>");
542 // Start with summary statistics. 592 // Start with summary statistics.
543 output.append(AddStringRow( 593 output.append(AddStringRow(
544 "Total", base::IntToString(meminfo.total / 1024))); 594 "Total", base::IntToString(meminfo.total / 1024)));
545 output.append(AddStringRow( 595 output.append(AddStringRow(
546 "Free", base::IntToString(meminfo.free / 1024))); 596 "Free", base::IntToString(meminfo.free / 1024)));
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 Profile* profile = Profile::FromWebUI(web_ui); 1036 Profile* profile = Profile::FromWebUI(web_ui);
987 1037
988 #if defined(ENABLE_THEMES) 1038 #if defined(ENABLE_THEMES)
989 // Set up the chrome://theme/ source. 1039 // Set up the chrome://theme/ source.
990 ThemeSource* theme = new ThemeSource(profile); 1040 ThemeSource* theme = new ThemeSource(profile);
991 content::URLDataSource::Add(profile, theme); 1041 content::URLDataSource::Add(profile, theme);
992 #endif 1042 #endif
993 1043
994 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); 1044 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile));
995 } 1045 }
OLDNEW
« chrome/browser/memory/oom_priority_manager.h ('K') | « chrome/browser/memory/tab_stats.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698