1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_ANDROID_EVALUATION_OFFLINE_PAGE_EVALUATION_BRIDGE_H_
#define CHROME_BROWSER_OFFLINE_PAGES_ANDROID_EVALUATION_OFFLINE_PAGE_EVALUATION_BRIDGE_H_
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "components/offline_pages/core/background/request_coordinator.h"
#include "components/offline_pages/core/background/request_notifier.h"
#include "components/offline_pages/core/offline_event_logger.h"
#include "components/offline_pages/core/offline_page_model.h"
namespace content {
class BrowserContext;
}
namespace offline_pages {
namespace android {
/**
* Bridge for exposing native implementation which are used by evaluation.
*/
class OfflinePageEvaluationBridge : public OfflinePageModel::Observer,
public RequestCoordinator::Observer,
public OfflineEventLogger::Client {
public:
OfflinePageEvaluationBridge(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
content::BrowserContext* browser_context,
OfflinePageModel* offline_page_model,
RequestCoordinator* request_coordinator);
OfflinePageEvaluationBridge(const OfflinePageEvaluationBridge&) = delete;
OfflinePageEvaluationBridge& operator=(const OfflinePageEvaluationBridge&) =
delete;
~OfflinePageEvaluationBridge() override;
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
// OfflinePageModel::Observer implementation.
void OfflinePageModelLoaded(OfflinePageModel* model) override;
void OfflinePageAdded(OfflinePageModel* model,
const OfflinePageItem& added_page) override;
void OfflinePageDeleted(const OfflinePageItem& item) override;
// RequestCoordinator::Observer implementation.
void OnAdded(const SavePageRequest& request) override;
void OnCompleted(const SavePageRequest& request,
RequestNotifier::BackgroundSavePageResult status) override;
void OnChanged(const SavePageRequest& request) override;
void OnNetworkProgress(const SavePageRequest& request,
int64_t received_bytes) override;
// OfflineEventLogger::Client implementation.
void CustomLog(const std::string& message) override;
// Gets all pages in offline page model.
void GetAllPages(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& j_result_obj,
const base::android::JavaParamRef<jobject>& j_callback_obj);
// Return true if processing starts and callback is expected to be called.
// False otherwise.
bool PushRequestProcessing(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& j_callback_obj);
// Gets all the requests in the queue.
void GetRequestsInQueue(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jobject>& j_callback_obj);
// Removes the requests from the queue.
void RemoveRequestsFromQueue(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jlongArray>& j_request_ids,
const base::android::JavaParamRef<jobject>& j_callback_obj);
void SavePageLater(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
std::string& url,
std::string& name_space,
std::string& client_id,
jboolean user_requested);
private:
void NotifyIfDoneLoading() const;
base::android::ScopedJavaLocalRef<jobject> CreateClientId(
JNIEnv* env,
const ClientId& clientId) const;
JavaObjectWeakGlobalRef weak_java_ref_;
// Not owned.
content::BrowserContext* browser_context_;
// Not owned.
OfflinePageModel* offline_page_model_;
// Not owned.
RequestCoordinator* request_coordinator_;
};
} // namespace android
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_ANDROID_EVALUATION_OFFLINE_PAGE_EVALUATION_BRIDGE_H_
|