Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/android/offline_pages/background_scheduler_bridge.cc

Issue 2054913002: hook up background task's "startProcessing" from Java to request_coordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per DougArnett Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #include "base/android/callback_android.h" 5 #include "base/android/callback_android.h"
6 #include "base/android/scoped_java_ref.h" 6 #include "base/android/scoped_java_ref.h"
7 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h" 7 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h"
8 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 8 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_android.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "components/offline_pages/background/request_coordinator.h" 12 #include "components/offline_pages/background/request_coordinator.h"
13 #include "jni/BackgroundSchedulerBridge_jni.h" 13 #include "jni/BackgroundSchedulerBridge_jni.h"
14 14
15 using base::android::ScopedJavaGlobalRef; 15 using base::android::ScopedJavaGlobalRef;
16 16
17 namespace offline_pages { 17 namespace offline_pages {
18 namespace android { 18 namespace android {
19 19
20 namespace { 20 namespace {
21 21
22 // C++ callback that delegates to Java callback. 22 // C++ callback that delegates to Java callback.
23 void ProcessingDoneCallback( 23 void ProcessingDoneCallback(
24 const ScopedJavaGlobalRef<jobject>& j_callback_obj, jboolean result) { 24 const ScopedJavaGlobalRef<jobject>& j_callback_obj, bool result) {
25 base::android::RunCallbackAndroid(j_callback_obj, result); 25 base::android::RunCallbackAndroid(j_callback_obj, result);
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 // JNI call to start request processing. 30 // JNI call to start request processing.
31 static jboolean StartProcessing( 31 static jboolean StartProcessing(
32 JNIEnv* env, 32 JNIEnv* env,
33 const JavaParamRef<jclass>& jcaller, 33 const JavaParamRef<jclass>& jcaller,
34 const JavaParamRef<jobject>& j_callback_obj) { 34 const JavaParamRef<jobject>& j_callback_obj) {
35 ScopedJavaGlobalRef<jobject> j_callback_ref; 35 ScopedJavaGlobalRef<jobject> j_callback_ref;
36 j_callback_ref.Reset(env, j_callback_obj); 36 j_callback_ref.Reset(env, j_callback_obj);
37
38 // Lookup/create RequestCoordinator KeyedService and call StartProcessing on
39 // it with bound j_callback_obj.
40 Profile* profile = ProfileManager::GetLastUsedProfile();
41 RequestCoordinator* coordinator =
42 RequestCoordinatorFactory::GetInstance()->
43 GetForBrowserContext(profile);
44 DVLOG(2) << "resource_coordinator: " << coordinator;
45 coordinator->StartProcessing(
46 base::Bind(&ProcessingDoneCallback, j_callback_ref));
47
48
37 base::Bind(&ProcessingDoneCallback, j_callback_ref); 49 base::Bind(&ProcessingDoneCallback, j_callback_ref);
38 // TODO(dougarnett): lookup/create RequestCoordinator KeyedService 50 // TODO(dougarnett): lookup/create RequestCoordinator KeyedService
39 // and call StartProcessing on it with bound j_callback_obj. 51 // and call StartProcessing on it with bound j_callback_obj.
40 return false; 52 return false;
41 } 53 }
42 54
43 void BackgroundSchedulerBridge::Schedule( 55 void BackgroundSchedulerBridge::Schedule(
44 const TriggerCondition& trigger_condition) { 56 const TriggerCondition& trigger_condition) {
45 JNIEnv* env = base::android::AttachCurrentThread(); 57 JNIEnv* env = base::android::AttachCurrentThread();
46 // TODO(dougarnett): pass trigger_condition. 58 // TODO(dougarnett): pass trigger_condition.
47 Java_BackgroundSchedulerBridge_schedule(env); 59 Java_BackgroundSchedulerBridge_schedule(env);
48 } 60 }
49 61
50 void BackgroundSchedulerBridge::Unschedule() { 62 void BackgroundSchedulerBridge::Unschedule() {
51 JNIEnv* env = base::android::AttachCurrentThread(); 63 JNIEnv* env = base::android::AttachCurrentThread();
52 Java_BackgroundSchedulerBridge_unschedule(env); 64 Java_BackgroundSchedulerBridge_unschedule(env);
53 } 65 }
54 66
55 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { 67 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) {
56 return RegisterNativesImpl(env); 68 return RegisterNativesImpl(env);
57 } 69 }
58 70
59 } // namespace android 71 } // namespace android
60 } // namespace offline_pages 72 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698