Commit 65ae1de2 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[protobuf] Convert thumbnail_cache_entry from nano to lite

This is the first CL in a sequence that converts all java
protobuf uses from nano to lite. It disables one proguard
optimization that breaks with lite-generated code.

Bug: 782237
Change-Id: Ifed32f216dacad69c1f32e903d8d30070070404b
Reviewed-on: https://chromium-review.googlesource.com/808684Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543317}
parent 5ee6d001
......@@ -13,6 +13,7 @@ from util import proguard_util
_DANGEROUS_OPTIMIZATIONS = [
"class/unboxing/enum",
# See crbug.com/625992
"code/allocation/variable",
# See crbug.com/625994
......
......@@ -278,6 +278,7 @@ android_library("chrome_java") {
"//third_party/gif_player:gif_player_java",
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/leakcanary:leakcanary_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//ui/android:ui_java",
"//ui/base/mojo:mojo_bindings_java",
"//ui/gfx/geometry/mojo:mojo_java",
......@@ -413,6 +414,7 @@ proto_java_library("thumbnail_cache_entry_proto_java") {
sources = [
"$proto_path/thumbnail_cache_entry.proto",
]
generate_lite = true
}
java_cpp_template("resource_id_javagen") {
......
......@@ -14,7 +14,7 @@ import android.support.v4.util.AtomicFile;
import android.support.v4.util.Pair;
import android.text.TextUtils;
import com.google.protobuf.nano.MessageNano;
import com.google.protobuf.ByteString;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -259,14 +259,13 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
for (File file : cachedFiles) {
AtomicFile atomicFile = new AtomicFile(file);
try {
ThumbnailEntry entry =
MessageNano.mergeFrom(new ThumbnailEntry(), atomicFile.readFully());
if (entry.contentId == null) continue;
ThumbnailEntry entry = ThumbnailEntry.parseFrom(atomicFile.readFully());
if (!entry.hasContentId()) continue;
String contentId = entry.contentId.id;
if (entry.sizePx == null) continue;
String contentId = entry.getContentId().getId();
if (!entry.hasSizePx()) continue;
int iconSizePx = entry.sizePx;
int iconSizePx = entry.getSizePx();
// Update internal cache state.
sDiskLruCache.add(Pair.create(contentId, iconSizePx));
......@@ -312,17 +311,18 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
byte[] compressedBitmapBytes = baos.toByteArray();
// Construct proto.
ThumbnailEntry newEntry = new ThumbnailEntry();
newEntry.contentId = new ContentId();
newEntry.contentId.id = contentId;
newEntry.sizePx = iconSizePx;
newEntry.compressedPng = compressedBitmapBytes;
ThumbnailEntry newEntry =
ThumbnailEntry.newBuilder()
.setContentId(ContentId.newBuilder().setId(contentId))
.setSizePx(iconSizePx)
.setCompressedPng(ByteString.copyFrom(compressedBitmapBytes))
.build();
// Write proto to disk.
File newFile = new File(getThumbnailFilePath(contentId, iconSizePx));
atomicFile = new AtomicFile(newFile);
fos = atomicFile.startWrite();
fos.write(MessageNano.toByteArray(newEntry));
fos.write(newEntry.toByteArray());
atomicFile.finishWrite(fos);
// Update internal cache state.
......@@ -374,12 +374,11 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
AtomicFile atomicFile = new AtomicFile(file);
fis = atomicFile.openRead();
ThumbnailEntry entry =
MessageNano.mergeFrom(new ThumbnailEntry(), atomicFile.readFully());
if (entry.compressedPng == null) return null;
ThumbnailEntry entry = ThumbnailEntry.parseFrom(atomicFile.readFully());
if (!entry.hasCompressedPng()) return null;
bitmap = BitmapFactory.decodeByteArray(
entry.compressedPng, 0, entry.compressedPng.length);
entry.getCompressedPng().toByteArray(), 0, entry.getCompressedPng().size());
} catch (IOException e) {
Log.e(TAG, "Error while reading from disk.", e);
} finally {
......
......@@ -11,6 +11,9 @@ package org.chromium.chrome.browser.widget;
option java_package = "org.chromium.chrome.browser.widget";
// TODO(jkrcal): Remove when protobuf 4.0 is out, https://crbug.com/800281.
option optimize_for = LITE_RUNTIME;
message ContentId {
// Required.
optional string id = 1;
......@@ -24,4 +27,4 @@ message ThumbnailEntry {
// Required.
optional int32 size_px = 2;
optional bytes compressed_png = 3;
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment