OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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::string AboutDiscardsRun(int64 web_content_id) { |
| 507 g_browser_process->GetOomPriorityManager()->DiscardTabById(web_content_id); |
| 508 return BuildAboutDiscardsRunPage(); |
| 509 } |
| 510 |
| 511 std::string AboutDiscardsRun() { |
| 512 g_browser_process->GetOomPriorityManager()->DiscardTab(); |
| 513 return BuildAboutDiscardsRunPage(); |
| 514 } |
| 515 |
| 516 std::vector<std::string> GetTabLines() { |
| 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)); |
| 535 #endif |
| 536 if (!it->is_discarded) { |
| 537 str += base::ASCIIToUTF16(base::StringPrintf( |
| 538 " <a href='%s%s/%ld'>Discard</a>", chrome::kChromeUIDiscardsURL, |
| 539 kAboutDiscardsRunCommand, it->tab_contents_id)); |
| 540 } |
| 541 titles.push_back(base::UTF16ToUTF8((str))); |
| 542 } |
| 543 return titles; |
| 544 } |
| 545 |
505 std::string AboutDiscards(const std::string& path) { | 546 std::string AboutDiscards(const std::string& path) { |
506 std::string output; | 547 std::string output; |
507 const char kRunCommand[] = "run"; | 548 std::vector<std::string> path_split; |
508 if (path == kRunCommand) | 549 int64 web_content_id; |
| 550 |
| 551 base::SplitString(path, '/', &path_split); |
| 552 if (path_split.size() == 2 && path_split[0] == kAboutDiscardsRunCommand && |
| 553 base::StringToInt64(path_split[1], &web_content_id)) { |
| 554 return AboutDiscardsRun(web_content_id); |
| 555 } else if (path_split.size() == 1 && |
| 556 path_split[0] == kAboutDiscardsRunCommand) { |
509 return AboutDiscardsRun(); | 557 return AboutDiscardsRun(); |
| 558 } |
| 559 |
510 AppendHeader(&output, 0, "About discards"); | 560 AppendHeader(&output, 0, "About discards"); |
511 AddContentSecurityPolicy(&output); | 561 AddContentSecurityPolicy(&output); |
512 AppendBody(&output); | 562 AppendBody(&output); |
513 output.append("<h3>About discards</h3>"); | 563 output.append("<h3>Discarded Tabs</h3>"); |
514 output.append( | 564 output.append( |
515 "<p>Tabs sorted from most interesting to least interesting. The least " | 565 "<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>"); | 566 "interesting tab may be discarded if we run out of physical memory.</p>"); |
517 | 567 |
518 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager(); | 568 memory::OomPriorityManager* oom = g_browser_process->GetOomPriorityManager(); |
519 std::vector<base::string16> titles = oom->GetTabTitles(); | 569 std::vector<std::string> titles = GetTabLines(); |
520 if (!titles.empty()) { | 570 if (!titles.empty()) { |
521 output.append("<ul>"); | 571 output.append("<ul>"); |
522 std::vector<base::string16>::iterator it = titles.begin(); | 572 std::vector<std::string>::iterator it = titles.begin(); |
523 for ( ; it != titles.end(); ++it) { | 573 for ( ; it != titles.end(); ++it) { |
524 std::string title = base::UTF16ToUTF8(*it); | 574 output.append(WrapWithTag("li", *it)); |
525 title = net::EscapeForHTML(title); | |
526 output.append(WrapWithTag("li", title)); | |
527 } | 575 } |
528 output.append("</ul>"); | 576 output.append("</ul>"); |
529 } else { | 577 } else { |
530 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); | 578 output.append("<p>None found. Wait 10 seconds, then refresh.</p>"); |
531 } | 579 } |
532 output.append(base::StringPrintf("%d discards this session. ", | 580 output.append( |
533 oom->discard_count())); | 581 base::StringPrintf("%d discards this session. ", oom->discard_count())); |
534 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>", | 582 output.append(base::StringPrintf("<a href='%s%s'>Discard tab now</a>", |
535 chrome::kChromeUIDiscardsURL, | 583 chrome::kChromeUIDiscardsURL, |
536 kRunCommand)); | 584 kAboutDiscardsRunCommand)); |
| 585 |
537 #if defined(OS_CHROMEOS) | 586 #if defined(OS_CHROMEOS) |
538 base::SystemMemoryInfoKB meminfo; | 587 base::SystemMemoryInfoKB meminfo; |
539 base::GetSystemMemoryInfo(&meminfo); | 588 base::GetSystemMemoryInfo(&meminfo); |
540 output.append("<h3>System memory information in MB</h3>"); | 589 output.append("<h3>System memory information in MB</h3>"); |
541 output.append("<table>"); | 590 output.append("<table>"); |
542 // Start with summary statistics. | 591 // Start with summary statistics. |
543 output.append(AddStringRow( | 592 output.append(AddStringRow( |
544 "Total", base::IntToString(meminfo.total / 1024))); | 593 "Total", base::IntToString(meminfo.total / 1024))); |
545 output.append(AddStringRow( | 594 output.append(AddStringRow( |
546 "Free", base::IntToString(meminfo.free / 1024))); | 595 "Free", base::IntToString(meminfo.free / 1024))); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 Profile* profile = Profile::FromWebUI(web_ui); | 1035 Profile* profile = Profile::FromWebUI(web_ui); |
987 | 1036 |
988 #if defined(ENABLE_THEMES) | 1037 #if defined(ENABLE_THEMES) |
989 // Set up the chrome://theme/ source. | 1038 // Set up the chrome://theme/ source. |
990 ThemeSource* theme = new ThemeSource(profile); | 1039 ThemeSource* theme = new ThemeSource(profile); |
991 content::URLDataSource::Add(profile, theme); | 1040 content::URLDataSource::Add(profile, theme); |
992 #endif | 1041 #endif |
993 | 1042 |
994 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); | 1043 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); |
995 } | 1044 } |
OLD | NEW |