// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef EXTENSIONS_BROWSER_BAD_MESSAGE_H_ #define EXTENSIONS_BROWSER_BAD_MESSAGE_H_ namespace content { class RenderProcessHost; } // Comparison of `extensions::bad_message::ReceivedBadMessage` vs // `mojo::ReportBadMessage`: // // * Both are an acceptable way to terminate a renderer process that has // sent a malformed IPC. // * `extensions::bad_message::ReceivedBadMessage` has the following advantages: // * Simplicity // * Granular UMA (which may help with gathering go/chrometto traces when // investigating unexpected reports of malformed IPCs) // * `mojo::ReportBadMessage` has the following advantages: // * Can be used without knowing the `RenderProcessHost` or // `render_process_id` (`mojo::RenderProcessHost` can be called at any // time when synchronously handling a mojo method call; asynchronous bad // message report is possible via `mojo::GetBadMessageCallback`). // * It is less tightly coupled with the //extensions layer (i.e. moving // the code to another layer or component is easier with // `mojo::ReportBadMessage`). namespace extensions::bad_message { // The browser process often chooses to terminate a renderer if it receives // a bad IPC message. The reasons are tracked for metrics. // // See also content/browser/bad_message.h. // // NOTE: Do not remove or reorder elements in this list. Add new entries at the // end. Items may be renamed but do not change the values. We rely on the enum // values in histograms. enum BadMessageReason { … }; // Called when the browser receives a bad IPC message from a normal or an // extension renderer. Logs the event, records a histogram metric for the // |reason|, and terminates the process for |host|/|render_process_id|. void ReceivedBadMessage(content::RenderProcessHost* host, BadMessageReason reason); // Same as ReceivedBadMessage above, but takes a render process id. Non-existent // render process ids are ignored. void ReceivedBadMessage(int render_process_id, BadMessageReason reason); } // namespace extensions::bad_message #endif // EXTENSIONS_BROWSER_BAD_MESSAGE_H_