0

Add flag to disable mmap in all sql connection in work build

Work Chrome runs in environment without a proper mmap support.
Disable it for all work chrome.

BUG=554269

Review URL: https://codereview.chromium.org/1637683003

Cr-Commit-Position: refs/heads/master@{#372179}
This commit is contained in:
vichang
2016-01-28 14:09:03 -08:00
committed by Commit bot
parent 12607e58c7
commit 7ce37c1ec3
6 changed files with 36 additions and 2 deletions

@ -46,6 +46,13 @@ public class ChromeVersionInfo {
|| ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_WORK; || ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_WORK;
} }
/**
* @return Whether this build is a work build.
*/
public static boolean isWorkBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_WORK;
}
/** /**
* @return Whether this is an official (i.e. Google Chrome) build. * @return Whether this is an official (i.e. Google Chrome) build.
*/ */

@ -27,10 +27,12 @@ import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.chrome.browser.ChromeApplication; import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeStrictMode; import org.chromium.chrome.browser.ChromeStrictMode;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.FileProviderHelper; import org.chromium.chrome.browser.FileProviderHelper;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.services.GoogleServicesManager; import org.chromium.chrome.browser.services.GoogleServicesManager;
import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl; import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.webapps.ActivityAssigner; import org.chromium.chrome.browser.webapps.ActivityAssigner;
import org.chromium.content.app.ContentApplication; import org.chromium.content.app.ContentApplication;
import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.BrowserStartupController;
@ -185,6 +187,12 @@ public class ChromeBrowserInitializer {
throws ProcessInitException { throws ProcessInitException {
assert ThreadUtils.runningOnUiThread() : "Tried to start the browser on the wrong thread"; assert ThreadUtils.runningOnUiThread() : "Tried to start the browser on the wrong thread";
// This has to be called to stop mmap in sql connection before any db initialized.
// It applies to Work Chrome only as mmap doesn't work properly.
if (ChromeVersionInfo.isWorkBuild()) {
FeatureUtilities.nativeSetSqlMmapDisabledByDefault();
}
final LinkedList<Runnable> initQueue = new LinkedList<Runnable>(); final LinkedList<Runnable> initQueue = new LinkedList<Runnable>();
abstract class NativeInitTask implements Runnable { abstract class NativeInitTask implements Runnable {

@ -173,4 +173,5 @@ public class FeatureUtilities {
private static native void nativeSetDocumentModeEnabled(boolean enabled); private static native void nativeSetDocumentModeEnabled(boolean enabled);
private static native void nativeSetCustomTabVisible(boolean visible); private static native void nativeSetCustomTabVisible(boolean visible);
public static native void nativeSetSqlMmapDisabledByDefault();
} }

@ -6,6 +6,8 @@
#include "jni/FeatureUtilities_jni.h" #include "jni/FeatureUtilities_jni.h"
#include "sql/connection.h"
namespace { namespace {
bool document_mode_enabled = false; bool document_mode_enabled = false;
bool custom_tab_visible = false; bool custom_tab_visible = false;
@ -39,6 +41,11 @@ static void SetCustomTabVisible(JNIEnv* env,
custom_tab_visible = visible; custom_tab_visible = visible;
} }
static void SetSqlMmapDisabledByDefault(JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
sql::Connection::set_mmap_disabled_by_default();
}
bool RegisterFeatureUtilities(JNIEnv* env) { bool RegisterFeatureUtilities(JNIEnv* env) {
return RegisterNativesImpl(env); return RegisterNativesImpl(env);
} }

@ -43,6 +43,8 @@ namespace {
// TODO(shess): Better story on this. http://crbug.com/56559 // TODO(shess): Better story on this. http://crbug.com/56559
const int kBusyTimeoutSeconds = 1; const int kBusyTimeoutSeconds = 1;
bool g_mmap_disabled_default = false;
class ScopedBusyTimeout { class ScopedBusyTimeout {
public: public:
explicit ScopedBusyTimeout(sqlite3* db) explicit ScopedBusyTimeout(sqlite3* db)
@ -254,6 +256,12 @@ bool Connection::ShouldIgnoreSqliteCompileError(int error) {
basic_error == SQLITE_CORRUPT; basic_error == SQLITE_CORRUPT;
} }
// static
void Connection::set_mmap_disabled_by_default() {
g_mmap_disabled_default = true;
}
void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
AssertIOAllowed(); AssertIOAllowed();
@ -339,7 +347,7 @@ Connection::Connection()
needs_rollback_(false), needs_rollback_(false),
in_memory_(false), in_memory_(false),
poisoned_(false), poisoned_(false),
mmap_disabled_(false), mmap_disabled_(g_mmap_disabled_default),
mmap_enabled_(false), mmap_enabled_(false),
total_changes_at_last_release_(0), total_changes_at_last_release_(0),
stats_histogram_(NULL), stats_histogram_(NULL),

@ -149,9 +149,12 @@ class SQL_EXPORT Connection {
// other platforms. // other platforms.
void set_restrict_to_user() { restrict_to_user_ = true; } void set_restrict_to_user() { restrict_to_user_ = true; }
// Call to opt out of memory-mapped file I/O. // Call to opt out of memory-mapped file I/O on per connection basis.
void set_mmap_disabled() { mmap_disabled_ = true; } void set_mmap_disabled() { mmap_disabled_ = true; }
// Call to opt out of memory-mapped file I/O on all connections.
static void set_mmap_disabled_by_default();
// Set an error-handling callback. On errors, the error number (and // Set an error-handling callback. On errors, the error number (and
// statement, if available) will be passed to the callback. // statement, if available) will be passed to the callback.
// //