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

Unified Diff: chrome/browser/android/offline_pages/offline_page_bridge.cc

Issue 1307753002: [Offline pages] Adding capability to free up space used by Offline pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Converting jlongarray to std::vector<int64> Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/offline_page_bridge.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_bridge.cc b/chrome/browser/android/offline_pages/offline_page_bridge.cc
index 27c315f7fc6789bc6f56f77b086a77f8017fec12..bc7e611779a74a19884fde69e1d41fcf2f162b68 100644
--- a/chrome/browser/android/offline_pages/offline_page_bridge.cc
+++ b/chrome/browser/android/offline_pages/offline_page_bridge.cc
@@ -4,7 +4,9 @@
#include "chrome/browser/android/offline_pages/offline_page_bridge.h"
+#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
+#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
@@ -32,26 +34,35 @@ namespace android {
namespace {
-void SavePageCallback(ScopedJavaGlobalRef<jobject>* j_callback_obj,
+void SavePageCallback(const ScopedJavaGlobalRef<jobject>& j_callback_obj,
const GURL& url,
OfflinePageModel::SavePageResult result) {
JNIEnv* env = base::android::AttachCurrentThread();
- scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr(j_callback_obj);
-
Java_SavePageCallback_onSavePageDone(
- env, j_callback_ptr->obj(), static_cast<int>(result),
+ env, j_callback_obj.obj(), static_cast<int>(result),
ConvertUTF8ToJavaString(env, url.spec()).obj());
}
-void DeletePageCallback(ScopedJavaGlobalRef<jobject>* j_callback_obj,
+void DeletePageCallback(const ScopedJavaGlobalRef<jobject>& j_callback_obj,
OfflinePageModel::DeletePageResult result) {
JNIEnv* env = base::android::AttachCurrentThread();
- scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_ptr(j_callback_obj);
-
Java_DeletePageCallback_onDeletePageDone(
- env, j_callback_ptr->obj(), static_cast<int>(result));
+ env, j_callback_obj.obj(), static_cast<int>(result));
+}
+
+void ToJavaOfflinePageList(JNIEnv* env,
+ jobject j_result_obj,
+ const std::vector<OfflinePageItem>& offline_pages) {
+ for (const OfflinePageItem& offline_page : offline_pages) {
+ Java_OfflinePageBridge_createOfflinePageAndAddToList(
+ env, j_result_obj,
+ ConvertUTF8ToJavaString(env, offline_page.url.spec()).obj(),
+ offline_page.bookmark_id,
+ ConvertUTF8ToJavaString(env, offline_page.GetOfflineURL().spec()).obj(),
+ offline_page.file_size);
+ }
}
} // namespace
@@ -88,15 +99,17 @@ void OfflinePageBridge::GetAllPages(JNIEnv* env,
DCHECK(j_result_obj);
const std::vector<OfflinePageItem>& offline_pages =
offline_page_model_->GetAllPages();
+ ToJavaOfflinePageList(env, j_result_obj, offline_pages);
+}
- for (const OfflinePageItem& offline_page : offline_pages) {
- Java_OfflinePageBridge_createOfflinePageAndAddToList(
- env, j_result_obj,
- ConvertUTF8ToJavaString(env, offline_page.url.spec()).obj(),
- offline_page.bookmark_id,
- ConvertUTF8ToJavaString(env, offline_page.GetOfflineURL().spec()).obj(),
- offline_page.file_size);
- }
+void OfflinePageBridge::GetPagesToCleanUp(JNIEnv* env,
+ jobject obj,
+ jobject j_result_obj) {
+ DCHECK(offline_page_model_->is_loaded());
+ DCHECK(j_result_obj);
+ const std::vector<OfflinePageItem>& offline_pages =
+ offline_page_model_->GetPagesToCleanUp();
+ ToJavaOfflinePageList(env, j_result_obj, offline_pages);
}
ScopedJavaLocalRef<jobject> OfflinePageBridge::GetPageByBookmarkId(
@@ -122,9 +135,8 @@ void OfflinePageBridge::SavePage(JNIEnv* env,
DCHECK(j_callback_obj);
DCHECK(j_web_contents);
- scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_obj_ptr(
- new ScopedJavaGlobalRef<jobject>());
- j_callback_obj_ptr->Reset(env, j_callback_obj);
+ ScopedJavaGlobalRef<jobject> j_callback_ref;
+ j_callback_ref.Reset(env, j_callback_obj);
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(j_web_contents);
@@ -136,7 +148,7 @@ void OfflinePageBridge::SavePage(JNIEnv* env,
offline_page_model_->SavePage(
url, bookmark_id, archiver.Pass(),
- base::Bind(&SavePageCallback, j_callback_obj_ptr.release(), url));
+ base::Bind(&SavePageCallback, j_callback_ref, url));
}
void OfflinePageBridge::DeletePage(JNIEnv* env,
@@ -145,12 +157,29 @@ void OfflinePageBridge::DeletePage(JNIEnv* env,
jlong bookmark_id) {
DCHECK(j_callback_obj);
- scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback_obj_ptr(
- new ScopedJavaGlobalRef<jobject>());
- j_callback_obj_ptr->Reset(env, j_callback_obj);
+ ScopedJavaGlobalRef<jobject> j_callback_ref;
+ j_callback_ref.Reset(env, j_callback_obj);
offline_page_model_->DeletePageByBookmarkId(bookmark_id, base::Bind(
- &DeletePageCallback, j_callback_obj_ptr.release()));
+ &DeletePageCallback, j_callback_ref));
+}
+
+void OfflinePageBridge::DeletePages(JNIEnv* env,
+ jobject obj,
+ jobject j_callback_obj,
+ jlongArray bookmark_ids_array) {
+ DCHECK(j_callback_obj);
+
+ ScopedJavaGlobalRef<jobject> j_callback_ref;
+ j_callback_ref.Reset(env, j_callback_obj);
+
+ std::vector<int64> bookmark_ids;
+ base::android::JavaLongArrayToInt64Vector(env, bookmark_ids_array,
+ &bookmark_ids);
+
+ offline_page_model_->DeletePagesByBookmarkId(
+ bookmark_ids,
+ base::Bind(&DeletePageCallback, j_callback_ref));
}
void OfflinePageBridge::NotifyIfDoneLoading() const {
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_bridge.h ('k') | components/offline_pages/offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698