| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.content.ContentResolver; | 7 import android.content.ContentResolver; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.database.ContentObserver; | 9 import android.database.ContentObserver; |
| 10 import android.database.Cursor; | 10 import android.database.Cursor; |
| 11 import android.database.SQLException; | 11 import android.database.SQLException; |
| 12 import android.net.Uri; | 12 import android.net.Uri; |
| 13 import android.os.AsyncTask; | 13 import android.os.AsyncTask; |
| 14 import android.os.Handler; | 14 import android.os.Handler; |
| 15 import android.util.Log; | 15 import android.util.Log; |
| 16 | 16 |
| 17 import org.chromium.base.CommandLine; | 17 import org.chromium.base.CommandLine; |
| 18 import org.chromium.base.ThreadUtils; |
| 18 | 19 |
| 19 import java.lang.reflect.Field; | 20 import java.lang.reflect.Field; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Controls data reduction proxy. | 23 * Controls data reduction proxy. |
| 23 */ | 24 */ |
| 24 public final class AwDataReductionProxyManager { | 25 public final class AwDataReductionProxyManager { |
| 25 // The setting Uri. Used when querying GoogleSettings. | 26 // The setting Uri. Used when querying GoogleSettings. |
| 26 // TODO: This GoogleSettings Uri does not exist yet! | 27 // TODO: This GoogleSettings Uri does not exist yet! |
| 27 private static final Uri CONTENT_URI = Uri.parse("content://com.google.setti
ngs/partner"); | 28 private static final Uri CONTENT_URI = Uri.parse("content://com.google.setti
ngs/partner"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } catch (IllegalAccessException ex) { | 102 } catch (IllegalAccessException ex) { |
| 102 Log.e(TAG, "No DRP key due to exception:" + ex); | 103 Log.e(TAG, "No DRP key due to exception:" + ex); |
| 103 } catch (NullPointerException ex) { | 104 } catch (NullPointerException ex) { |
| 104 Log.e(TAG, "No DRP key due to exception:" + ex); | 105 Log.e(TAG, "No DRP key due to exception:" + ex); |
| 105 } | 106 } |
| 106 return null; | 107 return null; |
| 107 } | 108 } |
| 108 | 109 |
| 109 private static void applyDataReductionProxySettingsAsync( | 110 private static void applyDataReductionProxySettingsAsync( |
| 110 final Context context, final String key) { | 111 final Context context, final String key) { |
| 111 AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>
() { | 112 AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { |
| 112 @Override | 113 @Override |
| 113 protected Boolean doInBackground(Void... params) { | 114 public void run() { |
| 114 return isDataReductionProxyEnabled(context); | 115 final boolean enabled = isDataReductionProxyEnabled(context); |
| 116 |
| 117 ThreadUtils.runOnUiThread(new Runnable() { |
| 118 @Override |
| 119 public void run() { |
| 120 if (enabled) { |
| 121 // Set the data reduction proxy key. |
| 122 AwContentsStatics.setDataReductionProxyKey(key); |
| 123 } |
| 124 AwContentsStatics.setDataReductionProxyEnabled(enabled); |
| 125 } |
| 126 }); |
| 115 } | 127 } |
| 116 @Override | 128 }); |
| 117 protected void onPostExecute(Boolean enabled) { | |
| 118 if (enabled) { | |
| 119 // Set the data reduction proxy key. | |
| 120 AwContentsStatics.setDataReductionProxyKey(key); | |
| 121 } | |
| 122 AwContentsStatics.setDataReductionProxyEnabled(enabled); | |
| 123 } | |
| 124 }; | |
| 125 task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
| 126 } | 129 } |
| 127 | 130 |
| 128 private static boolean isDataReductionProxyEnabled(Context context) { | 131 private static boolean isDataReductionProxyEnabled(Context context) { |
| 129 return getProxySetting(context.getContentResolver(), WEBVIEW_DATA_REDUCT
ION_PROXY) != 0; | 132 return getProxySetting(context.getContentResolver(), WEBVIEW_DATA_REDUCT
ION_PROXY) != 0; |
| 130 } | 133 } |
| 131 | 134 |
| 132 // Read query setting from GoogleSettings. | 135 // Read query setting from GoogleSettings. |
| 133 private static int getProxySetting(ContentResolver resolver, String name) { | 136 private static int getProxySetting(ContentResolver resolver, String name) { |
| 134 String value = null; | 137 String value = null; |
| 135 Cursor c = null; | 138 Cursor c = null; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 147 try { | 150 try { |
| 148 if (value != null) { | 151 if (value != null) { |
| 149 enabled = Integer.parseInt(value); | 152 enabled = Integer.parseInt(value); |
| 150 } | 153 } |
| 151 } catch (NumberFormatException e) { | 154 } catch (NumberFormatException e) { |
| 152 Log.e(TAG, "cannot parse" + value, e); | 155 Log.e(TAG, "cannot parse" + value, e); |
| 153 } | 156 } |
| 154 return enabled; | 157 return enabled; |
| 155 } | 158 } |
| 156 } | 159 } |
| OLD | NEW |