sqlite: Restrict temporary storage to in-memory.

This unifies SQLite's behavior across Android and other operating
systems.

Bug: 43939
Change-Id: I873f1b283e7bcfd6875302163c350b1eb20b7fe2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1146493
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Chris Mumford <cmumford@google.com>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660309}
diff --git a/components/history/core/browser/in_memory_database.cc b/components/history/core/browser/in_memory_database.cc
index bc037b7..f8d2dcd 100644
--- a/components/history/core/browser/in_memory_database.cc
+++ b/components/history/core/browser/in_memory_database.cc
@@ -30,9 +30,6 @@
   // No reason to leave data behind in memory when rows are removed.
   ignore_result(db_.Execute("PRAGMA auto_vacuum=1"));
 
-  // Ensure this is really an in-memory-only cache.
-  ignore_result(db_.Execute("PRAGMA temp_store=MEMORY"));
-
   // Create the URL table, but leave it empty for now.
   if (!CreateURLTable(false)) {
     NOTREACHED() << "Unable to create table";
diff --git a/third_party/sqlite/BUILD.gn b/third_party/sqlite/BUILD.gn
index 096c158..c18755f 100644
--- a/third_party/sqlite/BUILD.gn
+++ b/third_party/sqlite/BUILD.gn
@@ -166,6 +166,13 @@
 
     # Uses isnan() in the C99 standard library.
     "SQLITE_HAVE_ISNAN",
+
+    # Forces SQLite to only store temporary data in memory.
+    #
+    # This is the only supported setting on Android. Using it everywhere removes
+    # a source of cross-platform variation, and saves us from having to reason
+    # about SQLite storing data in the operating system's temporary directory.
+    "SQLITE_TEMP_STORE=3",
   ]
 
   # On OSX, SQLite has extra logic for detecting the use of network
@@ -348,7 +355,6 @@
     defines += [
       "SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576",
       "SQLITE_DEFAULT_AUTOVACUUM=1",
-      "SQLITE_TEMP_STORE=3",
     ]
   }