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

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: Resolve comments on #6 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
« no previous file with comments | « chrome/browser/memory/tab_stats.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 "them into the address bar if you need them.</p>\n<ul>"; 452 "them into the address bar if you need them.</p>\n<ul>";
452 for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; i++) 453 for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; i++)
453 html += "<li>" + std::string(chrome::kChromeDebugURLs[i]) + "</li>\n"; 454 html += "<li>" + std::string(chrome::kChromeDebugURLs[i]) + "</li>\n";
454 html += "</ul>\n"; 455 html += "</ul>\n";
455 AppendFooter(&html); 456 AppendFooter(&html);
456 return html; 457 return html;
457 } 458 }
458 459
459 #if defined(OS_WIN) || defined(OS_CHROMEOS) 460 #if defined(OS_WIN) || defined(OS_CHROMEOS)
460 461
462 const char kAboutDiscardsRunCommand[] = "run";
463
461 // Html output helper functions 464 // Html output helper functions
462 465
463 // Helper function to wrap HTML with a tag. 466 // Helper function to wrap HTML with a tag.
464 std::string WrapWithTag(const std::string& tag, const std::string& text) { 467 std::string WrapWithTag(const std::string& tag, const std::string& text) {
465 return "<" + tag + ">" + text + "</" + tag + ">"; 468 return "<" + tag + ">" + text + "</" + tag + ">";
466 } 469 }
467 470
468 // Helper function to wrap Html with <td> tag. 471 // Helper function to wrap Html with <td> tag.
469 std::string WrapWithTD(const std::string& text) { 472 std::string WrapWithTD(const std::string& text) {
470 return "<td>" + text + "</td>"; 473 return "<td>" + text + "</td>";
(...skipping 11 matching lines...) Expand all
482 return WrapWithTR(row); 485 return WrapWithTR(row);
483 } 486 }
484 487
485 void AddContentSecurityPolicy(std::string* output) { 488 void AddContentSecurityPolicy(std::string* output) {
486 output->append("<meta http-equiv='Content-Security-Policy' " 489 output->append("<meta http-equiv='Content-Security-Policy' "
487 "content='default-src 'none';'>"); 490 "content='default-src 'none';'>");
488 } 491 }
489 492
490 // TODO(stevenjb): L10N AboutDiscards. 493 // TODO(stevenjb): L10N AboutDiscards.
491 494
492 std::string AboutDiscardsRun() { 495 std::string BuildAboutDiscardsRunPage() {
493 std::string output; 496 std::string output;
494 AppendHeader(&output, 0, "About discards"); 497 AppendHeader(&output, 0, "About discards");
495 output.append( 498 output.append(base::StringPrintf("<meta http-equiv='refresh' content='2;%s'>",
496 base::StringPrintf("<meta http-equiv='refresh' content='2;%s'>", 499 chrome::kChromeUIDiscardsURL));
497 chrome::kChromeUIDiscardsURL));
498 AddContentSecurityPolicy(&output); 500 AddContentSecurityPolicy(&output);
499 output.append(WrapWithTag("p", "Discarding a tab...")); 501 output.append(WrapWithTag("p", "Discarding a tab..."));
500 g_browser_process->GetOomPriorityManager()->LogMemoryAndDiscardTab();
501 AppendFooter(&output); 502 AppendFooter(&output);
502 return output; 503 return output;
503 } 504 }
504 505
506 std::vector<std::string> GetHtmlTabDescriptorsForDiscardPage() {
507 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager();
508 memory::TabStatsList stats = oom->GetTabStats();
509 std::vector<std::string> titles;
510 titles.reserve(stats.size());
511 for (memory::TabStatsList::iterator it = stats.begin(); it != stats.end();
512 ++it) {
513 std::string str;
514 str.reserve(4096);
515 str += "<b>";
516 str += it->is_app ? "[App] " : "";
517 str += it->is_internal_page ? "[Internal] " : "";
518 str += it->is_playing_audio ? "[Audio] " : "";
519 str += it->is_pinned ? "[Pinned] " : "";
520 str += it->is_discarded ? "[Discarded] " : "";
521 str += "</b>";
522 str += net::EscapeForHTML(base::UTF16ToUTF8(it->title));
523 #if defined(OS_CHROMEOS)
524 str += base::StringPrintf(" (%d) ", it->oom_score);
525 #endif
526 if (!it->is_discarded) {
527 str += base::StringPrintf(" <a href='%s%s/%" PRId64 "'>Discard</a>",
528 chrome::kChromeUIDiscardsURL,
529 kAboutDiscardsRunCommand, it->tab_contents_id);
530 }
531 titles.push_back(str);
532 }
533 return titles;
534 }
535
505 std::string AboutDiscards(const std::string& path) { 536 std::string AboutDiscards(const std::string& path) {
506 std::string output; 537 std::string output;
507 const char kRunCommand[] = "run"; 538 std::vector<std::string> path_split;
508 if (path == kRunCommand) 539 int64 web_content_id;
509 return AboutDiscardsRun(); 540 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager();
541
542 base::SplitString(path, '/', &path_split);
543 if (path_split.size() == 2 && path_split[0] == kAboutDiscardsRunCommand &&
544 base::StringToInt64(path_split[1], &web_content_id)) {
545 oom->DiscardTabById(web_content_id);
546 return BuildAboutDiscardsRunPage();
547 } else if (path_split.size() == 1 &&
548 path_split[0] == kAboutDiscardsRunCommand) {
549 oom->DiscardTab();
550 return BuildAboutDiscardsRunPage();
551 }
552
510 AppendHeader(&output, 0, "About discards"); 553 AppendHeader(&output, 0, "About discards");
511 AddContentSecurityPolicy(&output); 554 AddContentSecurityPolicy(&output);
512 AppendBody(&output); 555 AppendBody(&output);
513 output.append("<h3>About discards</h3>"); 556 output.append("<h3>Discarded Tabs</h3>");
514 output.append( 557 output.append(
515 "<p>Tabs sorted from most interesting to least interesting. The least " 558 "<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>"); 559 "interesting tab may be discarded if we run out of physical memory.</p>");
517 560
518 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager(); 561 std::vector<std::string> titles = GetHtmlTabDescriptorsForDiscardPage();
519 std::vector<base::string16> titles = oom->GetTabTitles();
520 if (!titles.empty()) { 562 if (!titles.empty()) {
521 output.append("<ul>"); 563 output.append("<ul>");
522 std::vector<base::string16>::iterator it = titles.begin(); 564 std::vector<std::string>::iterator it = titles.begin();
523 for ( ; it != titles.end(); ++it) { 565 for ( ; it != titles.end(); ++it) {
524 std::string title = base::UTF16ToUTF8(*it); 566 output.append(WrapWithTag("li", *it));
525 title = net::EscapeForHTML(title);
526 output.append(WrapWithTag("li", title));
527 } 567 }
528 output.append("</ul>"); 568 output.append("</ul>");
529 } else { 569 } else {
530 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); 570 output.append("<p>None found. Wait 10 seconds, then refresh.</p>");
531 } 571 }
532 output.append(base::StringPrintf("%d discards this session. ", 572 output.append(
533 oom->discard_count())); 573 base::StringPrintf("%d discards this session. ", oom->discard_count()));
534 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>", 574 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>",
535 chrome::kChromeUIDiscardsURL, 575 chrome::kChromeUIDiscardsURL,
536 kRunCommand)); 576 kAboutDiscardsRunCommand));
577
537 #if defined(OS_CHROMEOS) 578 #if defined(OS_CHROMEOS)
538 base::SystemMemoryInfoKB meminfo; 579 base::SystemMemoryInfoKB meminfo;
539 base::GetSystemMemoryInfo(&meminfo); 580 base::GetSystemMemoryInfo(&meminfo);
540 output.append("<h3>System memory information in MB</h3>"); 581 output.append("<h3>System memory information in MB</h3>");
541 output.append("<table>"); 582 output.append("<table>");
542 // Start with summary statistics. 583 // Start with summary statistics.
543 output.append(AddStringRow( 584 output.append(AddStringRow(
544 "Total", base::IntToString(meminfo.total / 1024))); 585 "Total", base::IntToString(meminfo.total / 1024)));
545 output.append(AddStringRow( 586 output.append(AddStringRow(
546 "Free", base::IntToString(meminfo.free / 1024))); 587 "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); 1027 Profile* profile = Profile::FromWebUI(web_ui);
987 1028
988 #if defined(ENABLE_THEMES) 1029 #if defined(ENABLE_THEMES)
989 // Set up the chrome://theme/ source. 1030 // Set up the chrome://theme/ source.
990 ThemeSource* theme = new ThemeSource(profile); 1031 ThemeSource* theme = new ThemeSource(profile);
991 content::URLDataSource::Add(profile, theme); 1032 content::URLDataSource::Add(profile, theme);
992 #endif 1033 #endif
993 1034
994 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); 1035 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile));
995 } 1036 }
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_stats.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698