| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.chrome.browser.omaha; | 5 package org.chromium.chrome.browser.omaha; |
| 6 | 6 |
| 7 import android.app.Service; | |
| 8 import android.content.Context; | 7 import android.content.Context; |
| 9 | 8 |
| 10 import org.chromium.chrome.browser.omaha.OmahaClient.PostResult; | 9 import org.chromium.chrome.browser.omaha.OmahaBase.PostResult; |
| 11 | 10 |
| 12 /** Delegates calls out from the OmahaClient. */ | 11 /** Delegates calls out from {@link OmahaBase}. */ |
| 13 public abstract class OmahaDelegate { | 12 public abstract class OmahaDelegate { |
| 14 protected final Context mContext; | |
| 15 private RequestGenerator mRequestGenerator; | 13 private RequestGenerator mRequestGenerator; |
| 16 | 14 |
| 17 OmahaDelegate(Context context) { | 15 OmahaDelegate() {} |
| 18 mContext = context; | |
| 19 } | |
| 20 | 16 |
| 21 /** @return Context that is used to interact with the system. */ | 17 /** @return Context that is used to interact with the system. */ |
| 22 Context getContext() { | 18 abstract Context getContext(); |
| 23 return mContext; | |
| 24 } | |
| 25 | 19 |
| 26 /** @return Whether Chrome is installed as part of the system image. */ | 20 /** @return Whether Chrome is installed as part of the system image. */ |
| 27 abstract boolean isInSystemImage(); | 21 abstract boolean isInSystemImage(); |
| 28 | 22 |
| 29 /** @return The scheduler used to trigger jobs. */ | 23 /** @return The scheduler used to trigger jobs. */ |
| 30 abstract ExponentialBackoffScheduler getScheduler(); | 24 abstract ExponentialBackoffScheduler getScheduler(); |
| 31 | 25 |
| 32 /** @return The {@link RequestGenerator} used to create Omaha XML. */ | 26 /** @return The {@link RequestGenerator} used to create Omaha XML. */ |
| 33 final RequestGenerator getRequestGenerator() { | 27 final RequestGenerator getRequestGenerator() { |
| 34 if (mRequestGenerator == null) mRequestGenerator = createRequestGenerato
r(getContext()); | 28 if (mRequestGenerator == null) mRequestGenerator = createRequestGenerato
r(getContext()); |
| 35 return mRequestGenerator; | 29 return mRequestGenerator; |
| 36 } | 30 } |
| 37 | 31 |
| 38 /** @return A UUID that can be used to identify particular requests. */ | 32 /** @return A UUID that can be used to identify particular requests. */ |
| 39 abstract String generateUUID(); | 33 abstract String generateUUID(); |
| 40 | 34 |
| 41 /** Determine whether or not Chrome is currently being used actively. */ | 35 /** Determine whether or not Chrome is currently being used actively. */ |
| 42 abstract boolean isChromeBeingUsed(); | 36 abstract boolean isChromeBeingUsed(); |
| 43 | 37 |
| 44 /** | 38 /** |
| 45 * Schedules the {@link Service} to run again at the given time. | 39 * Schedules the Omaha client to run again. |
| 46 * @param service Service that is doing the scheduling. | 40 * @param currentTimestampMs Current time. |
| 47 * @param nextTimestampMs When the service should be run again. | 41 * @param nextTimestampMs When the service should be run again. |
| 48 */ | 42 */ |
| 49 abstract void scheduleService(Service service, long nextTimestampMs); | 43 abstract void scheduleService(long currentTimestampMs, long nextTimestampMs)
; |
| 50 | 44 |
| 51 /** Creates a {@link RequestGenerator}. */ | 45 /** Creates a {@link RequestGenerator}. */ |
| 52 abstract RequestGenerator createRequestGenerator(Context context); | 46 abstract RequestGenerator createRequestGenerator(Context context); |
| 53 | 47 |
| 54 /** | 48 /** |
| 55 * Called when {@link OmahaClient#registerNewRequest} finishes. | 49 * Called when {@link OmahaBase#registerNewRequest} finishes. |
| 56 * @param timestampRequestMs When the next active user request should be gen
erated. | 50 * @param timestampRequestMs When the next active user request should be gen
erated. |
| 57 * @param timestampPostMs Earliest time the next POST should be allowed. | 51 * @param timestampPostMs Earliest time the next POST should be allowed. |
| 58 */ | 52 */ |
| 59 void onRegisterNewRequestDone(long timestampRequestMs, long timestampPostMs)
{} | 53 void onRegisterNewRequestDone(long timestampRequestMs, long timestampPostMs)
{} |
| 60 | 54 |
| 61 /** | 55 /** |
| 62 * Called when {@link OmahaClient#handlePostRequest} finishes. | 56 * Called when {@link OmahaBase#handlePostRequest} finishes. |
| 63 * @param result See {@link PostResult}. | 57 * @param result See {@link PostResult}. |
| 64 * @param installEventWasSent Whether or not an install event was sent. | 58 * @param installEventWasSent Whether or not an install event was sent. |
| 65 */ | 59 */ |
| 66 void onHandlePostRequestDone(@PostResult int result, boolean installEventWas
Sent) {} | 60 void onHandlePostRequestDone(@PostResult int result, boolean installEventWas
Sent) {} |
| 67 | 61 |
| 68 /** | 62 /** |
| 69 * Called when {@link OmahaClient#generateAndPostRequest} finishes. | 63 * Called when {@link OmahaBase#generateAndPostRequest} finishes. |
| 70 * @param succeeded Whether or not the post was successfully received by the
server. | 64 * @param succeeded Whether or not the post was successfully received by the
server. |
| 71 */ | 65 */ |
| 72 void onGenerateAndPostRequestDone(boolean succeeded) {} | 66 void onGenerateAndPostRequestDone(boolean succeeded) {} |
| 73 | 67 |
| 74 /** | 68 /** |
| 75 * Called when {@link OmahaClient#saveState} finishes. | 69 * Called when {@link OmahaBase#saveState} finishes. |
| 76 * @param timestampRequestMs When the next active user request should be gen
erated. | 70 * @param timestampRequestMs When the next active user request should be gen
erated. |
| 77 * @param timestampPostMs Earliest time the next POST should be allowed. | 71 * @param timestampPostMs Earliest time the next POST should be allowed. |
| 78 */ | 72 */ |
| 79 void onSaveStateDone(long timestampRequestMs, long timestampPostMs) {} | 73 void onSaveStateDone(long timestampRequestMs, long timestampPostMs) {} |
| 80 } | 74 } |
| OLD | NEW |