Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Add flag to disable mmap in all sql connection in work build
Browse files Browse the repository at this point in the history
Work Chrome runs in environment without a proper mmap support.
Disable it for all work chrome.

BUG=554269
TBR=shess@chromium.org,vichang@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#372179}
(cherry picked from commit 7ce37c1)

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

Cr-Commit-Position: refs/branch-heads/2623@{#193}
Cr-Branched-From: 92d7753-refs/heads/master@{#369907}
  • Loading branch information
yfriedman committed Jan 29, 2016
1 parent ccc8d90 commit bf25518
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public static boolean isStableBuild() {
|| 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeStrictMode;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.FileProviderHelper;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.services.GoogleServicesManager;
import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.content.app.ContentApplication;
import org.chromium.content.browser.BrowserStartupController;
import org.chromium.content.browser.DeviceUtils;
Expand Down Expand Up @@ -183,6 +185,12 @@ public void handlePostNativeStartup(final boolean isAsync, final BrowserParts de
throws ProcessInitException {
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>();

abstract class NativeInitTask implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@ public void onCommandLineReset() {

private static native void nativeSetDocumentModeEnabled(boolean enabled);
private static native void nativeSetCustomTabVisible(boolean visible);
public static native void nativeSetSqlMmapDisabledByDefault();
}
7 changes: 7 additions & 0 deletions chrome/browser/android/feature_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "jni/FeatureUtilities_jni.h"

#include "sql/connection.h"

namespace {
bool document_mode_enabled = false;
bool custom_tab_visible = false;
Expand Down Expand Up @@ -39,6 +41,11 @@ static void SetCustomTabVisible(JNIEnv* env,
custom_tab_visible = visible;
}

static void SetSqlMmapDisabledByDefault(JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
sql::Connection::set_mmap_disabled_by_default();
}

bool RegisterFeatureUtilities(JNIEnv* env) {
return RegisterNativesImpl(env);
}
10 changes: 9 additions & 1 deletion sql/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace {
// TODO(shess): Better story on this. http://crbug.com/56559
const int kBusyTimeoutSeconds = 1;

bool g_mmap_disabled_default = false;

class ScopedBusyTimeout {
public:
explicit ScopedBusyTimeout(sqlite3* db)
Expand Down Expand Up @@ -254,6 +256,12 @@ bool Connection::ShouldIgnoreSqliteCompileError(int error) {
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) {
AssertIOAllowed();

Expand Down Expand Up @@ -339,7 +347,7 @@ Connection::Connection()
needs_rollback_(false),
in_memory_(false),
poisoned_(false),
mmap_disabled_(false),
mmap_disabled_(g_mmap_disabled_default),
mmap_enabled_(false),
total_changes_at_last_release_(0),
stats_histogram_(NULL),
Expand Down
5 changes: 4 additions & 1 deletion sql/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ class SQL_EXPORT Connection {
// other platforms.
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; }

// 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
// statement, if available) will be passed to the callback.
//
Expand Down

0 comments on commit bf25518

Please sign in to comment.