Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.offlinepages; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.os.Bundle; | |
| 9 | |
| 10 import org.chromium.base.Log; | |
| 11 import org.chromium.chrome.browser.profiles.Profile; | |
| 12 | |
| 13 import java.util.concurrent.CountDownLatch; | |
| 14 | |
| 15 /** | |
| 16 * Handles servicing of background offlining requests coming via the GCMNetworkM anager. | |
|
dougarnett
2016/05/20 22:17:32
nit: GcmNetworkManager is the actual capitalizatio
Pete Williamson
2016/05/23 19:36:31
Done.
| |
| 17 */ | |
| 18 public class BackgroundTask implements BackgroundSchedulerBridge.ProcessingDoneC allback { | |
| 19 private static final String TAG = "BackgroundTask"; | |
| 20 /** | |
| 21 * Triggers processing of background offlining requests. This is called whe n | |
| 22 * system conditions are appropriate for background offlining, typically fro m the | |
| 23 * GcmTaskService onRunTask() method. In response, we will start the | |
| 24 * task processing by passing the call along to the C++ RequestCoordinator. | |
| 25 * | |
| 26 * @returns true for success | |
| 27 */ | |
| 28 public boolean processBackgroundReqeusts(Context context, Bundle bundle) { | |
|
dougarnett
2016/05/20 22:17:32
spelling of Requests
Pete Williamson
2016/05/23 19:36:31
Done.
| |
| 29 mProcessingDoneLatch = new CountDownLatch(1); | |
| 30 | |
| 31 // TODO(petewil): Decode the TriggerConditions from the bundle. | |
| 32 | |
| 33 // TODO(petewil): We only have a context. Is this a reasonable way to g et a profile? | |
| 34 Profile profile = Profile.getLastUsedProfile(); | |
| 35 if (profile.isOffTheRecord()) { | |
| 36 profile = profile.getOriginalProfile(); | |
| 37 } | |
| 38 | |
| 39 // Make sure the bridge has a pointer to the proper profile and context. | |
| 40 BackgroundSchedulerBridge.getForProfile(profile, context); | |
| 41 // Pass the activation on to the bridge to the C++ RequestCoordinator. | |
| 42 BackgroundSchedulerBridge.startProcessing(context, this); | |
| 43 | |
| 44 // Gather UMA data to measure how often the user's machine is amenable t o background | |
| 45 // loading when we wake to do a task. | |
| 46 OfflinePageUtils.recordWakeupUMA(context); | |
| 47 | |
| 48 // Wait for callback async completion before returning. This is importa nt so | |
| 49 // we don't start the next GCM task until we are done with this one. It also | |
| 50 // rate limits our pre-render calls, and holds the wake lock for us. | |
| 51 try { | |
| 52 // TODO(petewil): Add a timeout here in case pre-rendering hangs. | |
| 53 mProcessingDoneLatch.await(); | |
|
dewittj
2016/05/20 21:52:31
Based on the call flow, this will block the UI thr
dougarnett
2016/05/20 22:30:18
Nice catch!
We might want a thread check enteri
Pete Williamson
2016/05/23 19:36:31
The intent is for this to block the incoming threa
Pete Williamson
2016/05/23 19:36:31
Check addded.
dougarnett
2016/05/24 16:27:58
Added comment to the runOnUiThread call to make th
dewittj
2016/05/24 16:56:19
Can you point me to where this promise is made? I
| |
| 54 } catch (InterruptedException e) { | |
| 55 Log.w(TAG, "IncomingTask interrupted, returning to GcmNetworkManager "); | |
| 56 return false; | |
| 57 } | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Callback function which indicates completion of background work. | |
| 63 * @param result - TODO(petewil): What is this for again? What does true me an? | |
| 64 */ | |
| 65 public void onProcessingDone(boolean result) { | |
| 66 mProcessingDoneLatch.countDown(); | |
| 67 } | |
| 68 | |
| 69 private CountDownLatch mProcessingDoneLatch; | |
| 70 } | |
| OLD | NEW |