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 ...@@ -13,6 +13,7 @@ from util import proguard_util
_DANGEROUS_OPTIMIZATIONS = [ _DANGEROUS_OPTIMIZATIONS = [
"class/unboxing/enum",
# See crbug.com/625992 # See crbug.com/625992
"code/allocation/variable", "code/allocation/variable",
# See crbug.com/625994 # See crbug.com/625994
......
...@@ -278,6 +278,7 @@ android_library("chrome_java") { ...@@ -278,6 +278,7 @@ android_library("chrome_java") {
"//third_party/gif_player:gif_player_java", "//third_party/gif_player:gif_player_java",
"//third_party/jsr-305:jsr_305_javalib", "//third_party/jsr-305:jsr_305_javalib",
"//third_party/leakcanary:leakcanary_java", "//third_party/leakcanary:leakcanary_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//ui/android:ui_java", "//ui/android:ui_java",
"//ui/base/mojo:mojo_bindings_java", "//ui/base/mojo:mojo_bindings_java",
"//ui/gfx/geometry/mojo:mojo_java", "//ui/gfx/geometry/mojo:mojo_java",
...@@ -413,6 +414,7 @@ proto_java_library("thumbnail_cache_entry_proto_java") { ...@@ -413,6 +414,7 @@ proto_java_library("thumbnail_cache_entry_proto_java") {
sources = [ sources = [
"$proto_path/thumbnail_cache_entry.proto", "$proto_path/thumbnail_cache_entry.proto",
] ]
generate_lite = true
} }
java_cpp_template("resource_id_javagen") { java_cpp_template("resource_id_javagen") {
......
...@@ -14,7 +14,7 @@ import android.support.v4.util.AtomicFile; ...@@ -14,7 +14,7 @@ import android.support.v4.util.AtomicFile;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.protobuf.nano.MessageNano; import com.google.protobuf.ByteString;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -259,14 +259,13 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback { ...@@ -259,14 +259,13 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
for (File file : cachedFiles) { for (File file : cachedFiles) {
AtomicFile atomicFile = new AtomicFile(file); AtomicFile atomicFile = new AtomicFile(file);
try { try {
ThumbnailEntry entry = ThumbnailEntry entry = ThumbnailEntry.parseFrom(atomicFile.readFully());
MessageNano.mergeFrom(new ThumbnailEntry(), atomicFile.readFully()); if (!entry.hasContentId()) continue;
if (entry.contentId == null) continue;
String contentId = entry.contentId.id; String contentId = entry.getContentId().getId();
if (entry.sizePx == null) continue; if (!entry.hasSizePx()) continue;
int iconSizePx = entry.sizePx; int iconSizePx = entry.getSizePx();
// Update internal cache state. // Update internal cache state.
sDiskLruCache.add(Pair.create(contentId, iconSizePx)); sDiskLruCache.add(Pair.create(contentId, iconSizePx));
...@@ -312,17 +311,18 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback { ...@@ -312,17 +311,18 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
byte[] compressedBitmapBytes = baos.toByteArray(); byte[] compressedBitmapBytes = baos.toByteArray();
// Construct proto. // Construct proto.
ThumbnailEntry newEntry = new ThumbnailEntry(); ThumbnailEntry newEntry =
newEntry.contentId = new ContentId(); ThumbnailEntry.newBuilder()
newEntry.contentId.id = contentId; .setContentId(ContentId.newBuilder().setId(contentId))
newEntry.sizePx = iconSizePx; .setSizePx(iconSizePx)
newEntry.compressedPng = compressedBitmapBytes; .setCompressedPng(ByteString.copyFrom(compressedBitmapBytes))
.build();
// Write proto to disk. // Write proto to disk.
File newFile = new File(getThumbnailFilePath(contentId, iconSizePx)); File newFile = new File(getThumbnailFilePath(contentId, iconSizePx));
atomicFile = new AtomicFile(newFile); atomicFile = new AtomicFile(newFile);
fos = atomicFile.startWrite(); fos = atomicFile.startWrite();
fos.write(MessageNano.toByteArray(newEntry)); fos.write(newEntry.toByteArray());
atomicFile.finishWrite(fos); atomicFile.finishWrite(fos);
// Update internal cache state. // Update internal cache state.
...@@ -374,12 +374,11 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback { ...@@ -374,12 +374,11 @@ public class ThumbnailDiskStorage implements ThumbnailGeneratorCallback {
AtomicFile atomicFile = new AtomicFile(file); AtomicFile atomicFile = new AtomicFile(file);
fis = atomicFile.openRead(); fis = atomicFile.openRead();
ThumbnailEntry entry = ThumbnailEntry entry = ThumbnailEntry.parseFrom(atomicFile.readFully());
MessageNano.mergeFrom(new ThumbnailEntry(), atomicFile.readFully()); if (!entry.hasCompressedPng()) return null;
if (entry.compressedPng == null) return null;
bitmap = BitmapFactory.decodeByteArray( bitmap = BitmapFactory.decodeByteArray(
entry.compressedPng, 0, entry.compressedPng.length); entry.getCompressedPng().toByteArray(), 0, entry.getCompressedPng().size());
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error while reading from disk.", e); Log.e(TAG, "Error while reading from disk.", e);
} finally { } finally {
......
...@@ -11,6 +11,9 @@ package org.chromium.chrome.browser.widget; ...@@ -11,6 +11,9 @@ package org.chromium.chrome.browser.widget;
option java_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 { message ContentId {
// Required. // Required.
optional string id = 1; optional string id = 1;
...@@ -24,4 +27,4 @@ message ThumbnailEntry { ...@@ -24,4 +27,4 @@ message ThumbnailEntry {
// Required. // Required.
optional int32 size_px = 2; optional int32 size_px = 2;
optional bytes compressed_png = 3; 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