From 7011310bdcc948d5aa81e259f0a0a2acebd486e0 Mon Sep 17 00:00:00 2001
From: "cimamoglu@chromium.org"
 <cimamoglu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Tue, 6 May 2014 10:31:31 +0000
Subject: Use a framework method to decrease code duplication in
 SyncStatusHelper

Use StrictMode.allowThreadDiskWrites instead of
temporarilyAllowDiskWritesAndDiskReads. The former method does exactly
the same thing.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268481 0039d316-1c4b-4281-b951-d872f2087c98
---
 .../chromium/sync/notifier/SyncStatusHelper.java   | 29 ++++------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

(limited to 'sync/android')

diff --git a/sync/android/java/src/org/chromium/sync/notifier/SyncStatusHelper.java b/sync/android/java/src/org/chromium/sync/notifier/SyncStatusHelper.java
index 0db47f8..569848f 100644
--- a/sync/android/java/src/org/chromium/sync/notifier/SyncStatusHelper.java
+++ b/sync/android/java/src/org/chromium/sync/notifier/SyncStatusHelper.java
@@ -103,7 +103,7 @@ public class SyncStatusHelper {
 
             mAccount = account;
 
-            StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads();
+            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
             mSyncAutomatically = mSyncContentResolverDelegate.getSyncAutomatically(
                     account, mContractAuthority);
             mIsSyncable = mSyncContentResolverDelegate.getIsSyncable(account, mContractAuthority);
@@ -116,7 +116,7 @@ public class SyncStatusHelper {
         @VisibleForTesting
         protected void setIsSyncableInternal(Account account) {
             mIsSyncable = 1;
-            StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads();
+            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
             mSyncContentResolverDelegate.setIsSyncable(account, mContractAuthority, 1);
             StrictMode.setThreadPolicy(oldPolicy);
             mDidUpdate = true;
@@ -125,7 +125,7 @@ public class SyncStatusHelper {
         @VisibleForTesting
         protected void setSyncAutomaticallyInternal(Account account, boolean value) {
             mSyncAutomatically = value;
-            StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads();
+            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
             mSyncContentResolverDelegate.setSyncAutomatically(account, mContractAuthority, value);
             StrictMode.setThreadPolicy(oldPolicy);
             mDidUpdate = true;
@@ -186,7 +186,7 @@ public class SyncStatusHelper {
     }
 
     private void updateMasterSyncAutomaticallySetting() {
-        StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads();
+        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
         synchronized (mCachedSettings) {
             mCachedMasterSyncAutomatically = mSyncContentResolverDelegate
                     .getMasterSyncAutomatically();
@@ -371,7 +371,7 @@ public class SyncStatusHelper {
             mCachedSettings.setIsSyncable(account);
         }
 
-        StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads();
+        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
         // Disable the syncability of Chrome for all other accounts. Don't use
         // our cache as we're touching many accounts that aren't signed in, so this saves
         // extra calls to Android sync configuration.
@@ -414,25 +414,6 @@ public class SyncStatusHelper {
         }
     }
 
-    /**
-     * Sets a new StrictMode.ThreadPolicy based on the current one, but allows disk reads
-     * and disk writes.
-     *
-     * The return value is the old policy, which must be applied after the disk access is finished,
-     * by using StrictMode.setThreadPolicy(oldPolicy).
-     *
-     * @return the policy before allowing reads and writes.
-     */
-    private static StrictMode.ThreadPolicy temporarilyAllowDiskWritesAndDiskReads() {
-        StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
-        StrictMode.ThreadPolicy.Builder newPolicy =
-                new StrictMode.ThreadPolicy.Builder(oldPolicy);
-        newPolicy.permitDiskReads();
-        newPolicy.permitDiskWrites();
-        StrictMode.setThreadPolicy(newPolicy.build());
-        return oldPolicy;
-    }
-
     private boolean getAndClearDidUpdateStatus() {
         boolean didGetStatusUpdate;
         synchronized (mCachedSettings) {
-- 
cgit v1.1