#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
-#include "base/file_util.h"
+#include "base/files/file_util.h"
#include "base/i18n/number_formatting.h"
#include "base/json/json_writer.h"
#include "base/memory/singleton.h"
#include "base/metrics/statistics_recorder.h"
#include "base/metrics/stats_table.h"
-#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/net/url_fixer_upper.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "chrome/grit/locale_settings.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/common/process_type.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
#include "net/base/escape.h"
+#include "net/base/filename_util.h"
#include "net/base/load_flags.h"
-#include "net/base/net_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/memory/oom_priority_manager.h"
-#include "chromeos/chromeos_switches.h"
#endif
using base::Time;
namespace {
const char kCreditsJsPath[] = "credits.js";
+const char kKeyboardUtilsPath[] = "keyboard_utils.js";
const char kMemoryJsPath[] = "memory.js";
const char kMemoryCssPath[] = "about_memory.css";
const char kStatsJsPath[] = "stats.js";
: callback_(callback) {
}
- virtual void OnDetailsAvailable() OVERRIDE;
+ void OnDetailsAvailable() override;
private:
- virtual ~AboutMemoryHandler() {}
+ ~AboutMemoryHandler() override {}
- void BindProcessMetrics(DictionaryValue* data,
+ void BindProcessMetrics(base::DictionaryValue* data,
ProcessMemoryInformation* info);
- void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
+ void AppendProcess(base::ListValue* child_data,
+ ProcessMemoryInformation* info);
content::URLDataSource::GotDataCallback callback_;
virtual ~ChromeOSOnlineTermsHandler() {}
// net::URLFetcherDelegate:
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) override {
if (source != eula_fetcher_.get()) {
NOTREACHED() << "Callback from foreign URL fetcher";
return;
virtual ~ChromeOSTermsHandler() {}
void StartOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (path_ == chrome::kOemEulaURLPath) {
// Load local OEM EULA from the disk.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ChromeOSTermsHandler::LoadOemEulaFileOnFileThread, this));
- } else if (CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kDisableOnlineEULA)) {
- // Fallback to the local file.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
} else {
// Try to load online version of ChromeOS terms first.
// ChromeOSOnlineTermsHandler object destroys itself.
}
void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
loader->GetResponseResult(&contents_);
if (contents_.empty()) {
// Load local ChromeOS terms from the file.
}
void LoadOemEulaFileOnFileThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
const chromeos::StartupCustomizationDocument* customization =
chromeos::StartupCustomizationDocument::GetInstance();
if (customization->IsReady()) {
}
void ResponseOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
// If we fail to load Chrome OS EULA from disk, load it from resources.
// Do nothing if OEM EULA load failed.
if (contents_.empty() && path_ != chrome::kOemEulaURLPath)
DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler);
};
+class ChromeOSCreditsHandler
+ : public base::RefCountedThreadSafe<ChromeOSCreditsHandler> {
+ public:
+ static void Start(const std::string& path,
+ const content::URLDataSource::GotDataCallback& callback) {
+ scoped_refptr<ChromeOSCreditsHandler> handler(
+ new ChromeOSCreditsHandler(path, callback));
+ handler->StartOnUIThread();
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<ChromeOSCreditsHandler>;
+
+ ChromeOSCreditsHandler(
+ const std::string& path,
+ const content::URLDataSource::GotDataCallback& callback)
+ : path_(path), callback_(callback) {}
+
+ virtual ~ChromeOSCreditsHandler() {}
+
+ void StartOnUIThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (path_ == kKeyboardUtilsPath) {
+ contents_ = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_KEYBOARD_UTILS_JS)
+ .as_string();
+ ResponseOnUIThread();
+ return;
+ }
+ // Load local Chrome OS credits from the disk.
+ BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE,
+ base::Bind(&ChromeOSCreditsHandler::LoadCreditsFileOnBlockingPool,
+ this),
+ base::Bind(&ChromeOSCreditsHandler::ResponseOnUIThread, this));
+ }
+
+ void LoadCreditsFileOnBlockingPool() {
+ DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
+ base::FilePath credits_file_path(chrome::kChromeOSCreditsPath);
+ if (!base::ReadFileToString(credits_file_path, &contents_)) {
+ // File with credits not found, ResponseOnUIThread will load credits
+ // from resources if contents_ is empty.
+ contents_.clear();
+ }
+ }
+
+ void ResponseOnUIThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ // If we fail to load Chrome OS credits from disk, load it from resources.
+ if (contents_.empty() && path_ != kKeyboardUtilsPath) {
+ contents_ = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_OS_CREDITS_HTML)
+ .as_string();
+ }
+ callback_.Run(base::RefCountedString::TakeString(&contents_));
+ }
+
+ // Path in the URL.
+ const std::string path_;
+
+ // Callback to run with the response.
+ content::URLDataSource::GotDataCallback callback_;
+
+ // Chrome OS credits contents that was loaded from file.
+ std::string contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeOSCreditsHandler);
+};
#endif
} // namespace
chromeos::OomPriorityManager* oom =
g_browser_process->platform_part()->oom_priority_manager();
- std::vector<string16> titles = oom->GetTabTitles();
+ std::vector<base::string16> titles = oom->GetTabTitles();
if (!titles.empty()) {
output.append("<ul>");
- std::vector<string16>::iterator it = titles.begin();
+ std::vector<base::string16>::iterator it = titles.begin();
for ( ; it != titles.end(); ++it) {
- std::string title = UTF16ToUTF8(*it);
+ std::string title = base::UTF16ToUTF8(*it);
title = net::EscapeForHTML(title);
output.append(WrapWithTag("li", title));
}
const content::URLDataSource::GotDataCallback& callback)
: profile_(profile),
callback_(callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
virtual ~AboutDnsHandler() {}
// Calls FinishOnUIThread() on completion.
void StartOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
chrome_browser_net::Predictor* predictor = profile_->GetNetworkPredictor();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
}
void StartOnIOThread(chrome_browser_net::Predictor* predictor) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
std::string data;
AppendHeader(&data, 0, "About DNS");
}
void FinishOnUIThread(const std::string& data) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string data_copy(data);
callback_.Run(base::RefCountedString::TakeString(&data_copy));
}
// if |query| is "raw", returns plain text of counter deltas.
// otherwise, returns HTML with pretty JS/HTML to display the data.
std::string AboutStats(const std::string& query) {
- // We keep the DictionaryValue tree live so that we can do delta
+ // We keep the base::DictionaryValue tree live so that we can do delta
// stats computations across runs.
- CR_DEFINE_STATIC_LOCAL(DictionaryValue, root, ());
+ CR_DEFINE_STATIC_LOCAL(base::DictionaryValue, root, ());
static base::TimeTicks last_sample_time = base::TimeTicks::Now();
base::TimeTicks now = base::TimeTicks::Now();
// We maintain two lists - one for counters and one for timers.
// Timers actually get stored on both lists.
- ListValue* counters;
+ base::ListValue* counters;
if (!root.GetList("counters", &counters)) {
- counters = new ListValue();
+ counters = new base::ListValue();
root.Set("counters", counters);
}
- ListValue* timers;
+ base::ListValue* timers;
if (!root.GetList("timers", &timers)) {
- timers = new ListValue();
+ timers = new base::ListValue();
root.Set("timers", timers);
}
name.replace(pos, 1, ":");
// Try to see if this name already exists.
- DictionaryValue* counter = NULL;
+ base::DictionaryValue* counter = NULL;
for (size_t scan_index = 0;
scan_index < counters->GetSize(); scan_index++) {
- DictionaryValue* dictionary;
+ base::DictionaryValue* dictionary;
if (counters->GetDictionary(scan_index, &dictionary)) {
std::string scan_name;
if (dictionary->GetString("name", &scan_name) && scan_name == name) {
}
if (counter == NULL) {
- counter = new DictionaryValue();
+ counter = new base::DictionaryValue();
counter->SetString("name", name);
counters->Append(counter);
}
if (query == "json" || query == kStringsJsPath) {
base::JSONWriter::WriteWithOptions(
&root,
- base::JSONWriter::OPTIONS_DO_NOT_ESCAPE |
- base::JSONWriter::OPTIONS_PRETTY_PRINT,
+ base::JSONWriter::OPTIONS_PRETTY_PRINT,
&data);
if (query == kStringsJsPath)
- data = "var templateData = " + data + ";";
+ data = "loadTimeData.data = " + data + ";";
} else if (query == "raw") {
// Dump the raw counters which have changed in text format.
data = "<pre>";
data.append(base::StringPrintf("Counter changes in the last %ldms\n",
static_cast<long int>(time_since_last_sample.InMilliseconds())));
for (size_t i = 0; i < counters->GetSize(); ++i) {
- Value* entry = NULL;
+ base::Value* entry = NULL;
bool rv = counters->Get(i, &entry);
if (!rv)
continue; // None of these should fail.
- DictionaryValue* counter = static_cast<DictionaryValue*>(entry);
+ base::DictionaryValue* counter =
+ static_cast<base::DictionaryValue*>(entry);
int delta;
rv = counter->GetInteger("delta", &delta);
if (!rv)
// as well.
for (int index = static_cast<int>(timers->GetSize())-1; index >= 0;
index--) {
- scoped_ptr<Value> value;
+ scoped_ptr<base::Value> value;
timers->Remove(index, &value);
// We don't care about the value pointer; it's still tracked
// on the counters list.
data.append(l10n_util::GetStringFUTF8(
IDS_ABOUT_LINUX_PROXY_CONFIG_BODY,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
- ASCIIToUTF16(binary.BaseName().value())));
+ base::ASCIIToUTF16(binary.BaseName().value())));
AppendFooter(&data);
return data;
}
AboutSandboxRow(&data,
std::string(),
IDS_ABOUT_SANDBOX_SECCOMP_BPF_SANDBOX,
- status & content::kSandboxLinuxSeccompBpf);
+ status & content::kSandboxLinuxSeccompBPF);
+ AboutSandboxRow(&data,
+ std::string(),
+ IDS_ABOUT_SANDBOX_YAMA_LSM,
+ status & content::kSandboxLinuxYama);
data.append("</table>");
status & content::kSandboxLinuxPIDNS &&
status & content::kSandboxLinuxNetNS;
// A second-layer sandbox is also required to be adequately sandboxed.
- bool good_layer2 = status & content::kSandboxLinuxSeccompBpf;
+ bool good_layer2 = status & content::kSandboxLinuxSeccompBPF;
bool good = good_layer1 && good_layer2;
if (good) {
// Helper for AboutMemory to bind results from a ProcessMetrics object
// to a DictionaryValue. Fills ws_usage and comm_usage so that the objects
// can be used in caller's scope (e.g for appending to a net total).
-void AboutMemoryHandler::BindProcessMetrics(DictionaryValue* data,
+void AboutMemoryHandler::BindProcessMetrics(base::DictionaryValue* data,
ProcessMemoryInformation* info) {
DCHECK(data && info);
// Helper for AboutMemory to append memory usage information for all
// sub-processes (i.e. renderers, plugins) used by Chrome.
-void AboutMemoryHandler::AppendProcess(ListValue* child_data,
+void AboutMemoryHandler::AppendProcess(base::ListValue* child_data,
ProcessMemoryInformation* info) {
DCHECK(child_data && info);
// Append a new DictionaryValue for this renderer to our list.
- DictionaryValue* child = new DictionaryValue();
+ base::DictionaryValue* child = new base::DictionaryValue();
child_data->Append(child);
BindProcessMetrics(child, info);
if (info->is_diagnostics)
child_label.append(" (diagnostics)");
child->SetString("child_name", child_label);
- ListValue* titles = new ListValue();
+ base::ListValue* titles = new base::ListValue();
child->Set("titles", titles);
for (size_t i = 0; i < info->titles.size(); ++i)
- titles->Append(new StringValue(info->titles[i]));
+ titles->Append(new base::StringValue(info->titles[i]));
}
void AboutMemoryHandler::OnDetailsAvailable() {
// the root of the JSON hierarchy for about:memory jstemplate
- scoped_ptr<DictionaryValue> root(new DictionaryValue);
- ListValue* browsers = new ListValue();
+ scoped_ptr<base::DictionaryValue> root(new base::DictionaryValue);
+ base::ListValue* browsers = new base::ListValue();
root->Set("browsers", browsers);
const std::vector<ProcessData>& browser_processes = processes();
// Aggregate per-process data into browser summary data.
- string16 log_string;
+ base::string16 log_string;
for (size_t index = 0; index < browser_processes.size(); index++) {
if (browser_processes[index].processes.empty())
continue;
}
++iterator;
}
- DictionaryValue* browser_data = new DictionaryValue();
+ base::DictionaryValue* browser_data = new base::DictionaryValue();
browsers->Append(browser_data);
browser_data->SetString("name", browser_processes[index].name);
// We log memory info as we record it.
if (!log_string.empty())
- log_string += ASCIIToUTF16(", ");
- log_string += browser_processes[index].name + ASCIIToUTF16(", ") +
+ log_string += base::ASCIIToUTF16(", ");
+ log_string += browser_processes[index].name + base::ASCIIToUTF16(", ") +
base::Int64ToString16(aggregate.working_set.priv) +
- ASCIIToUTF16(", ") +
+ base::ASCIIToUTF16(", ") +
base::Int64ToString16(aggregate.working_set.shared) +
- ASCIIToUTF16(", ") +
+ base::ASCIIToUTF16(", ") +
base::Int64ToString16(aggregate.working_set.shareable);
}
if (!log_string.empty())
VLOG(1) << "memory: " << log_string;
// Set the browser & renderer detailed process data.
- DictionaryValue* browser_data = new DictionaryValue();
+ base::DictionaryValue* browser_data = new base::DictionaryValue();
root->Set("browzr_data", browser_data);
- ListValue* child_data = new ListValue();
+ base::ListValue* child_data = new base::ListValue();
root->Set("child_data", child_data);
ProcessData process = browser_processes[0]; // Chrome is the first browser.
root->SetBoolean("show_other_browsers",
browser_defaults::kShowOtherBrowsersInAboutMemory);
- DictionaryValue load_time_data;
+ base::DictionaryValue load_time_data;
load_time_data.SetString(
"summary_desc",
l10n_util::GetStringUTF16(IDS_MEMORY_USAGE_SUMMARY_DESC));
webui::SetFontAndTextDirection(&load_time_data);
load_time_data.Set("jstemplateData", root.release());
- webui::UseVersion2 version2;
std::string data;
webui::AppendJsonJS(&load_time_data, &data);
callback_.Run(base::RefCountedString::TakeString(&data));
void AboutUIHTMLSource::StartDataRequest(
const std::string& path,
int render_process_id,
- int render_view_id,
+ int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) {
std::string response;
// Add your data source here, in alphabetical order.
if (source_name_ == chrome::kChromeUIChromeURLsHost) {
response = ChromeURLs();
} else if (source_name_ == chrome::kChromeUICreditsHost) {
- int idr = (path == kCreditsJsPath) ? IDR_CREDITS_JS : IDR_CREDITS_HTML;
+ int idr = IDR_CREDITS_HTML;
+ if (path == kCreditsJsPath)
+ idr = IDR_CREDITS_JS;
+#if defined(OS_CHROMEOS)
+ else if (path == kKeyboardUtilsPath)
+ idr = IDR_KEYBOARD_UTILS_JS;
+#endif
+
response = ResourceBundle::GetSharedInstance().GetRawDataResource(
idr).as_string();
#if defined(OS_CHROMEOS)
return;
#if defined(OS_CHROMEOS)
} else if (source_name_ == chrome::kChromeUIOSCreditsHost) {
- response = ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_OS_CREDITS_HTML).as_string();
+ ChromeOSCreditsHandler::Start(path, callback);
+ return;
#endif
#if defined(OS_LINUX) || defined(OS_OPENBSD)
} else if (source_name_ == chrome::kChromeUISandboxHost) {
#endif
} else if (source_name_ == chrome::kChromeUIStatsHost) {
response = AboutStats(path);
+#if !defined(OS_ANDROID)
} else if (source_name_ == chrome::kChromeUITermsHost) {
#if defined(OS_CHROMEOS)
ChromeOSTermsHandler::Start(path, callback);
#else
response = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
#endif
+#endif
}
FinishDataRequest(response, callback);
}
std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
- if (path == kCreditsJsPath ||
- path == kStatsJsPath ||
- path == kStringsJsPath ||
+ if (path == kCreditsJsPath ||
+ path == kKeyboardUtilsPath ||
+ path == kStatsJsPath ||
+ path == kStringsJsPath ||
path == kMemoryJsPath) {
return "application/javascript";
}