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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java

Issue 63483007: Refactor Android printing code to make it more testable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add license to PrintingControllerFactory Created 7 years, 1 month 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/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java b/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java
new file mode 100644
index 0000000000000000000000000000000000000000..a5223085261bb18448887a753216cd539047fcf8
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/printing/TabPrinter.java
@@ -0,0 +1,52 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.printing;
+
+import android.text.TextUtils;
+
+import org.chromium.chrome.browser.TabBase;
+import org.chromium.printing.Printable;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * Wraps printing related functionality of a {@link TabBase} object.
+ *
+ * This class doesn't have any lifetime expectations with regards to Tab, since we keep a weak
+ * reference.
+ */
+public class TabPrinter implements Printable {
+ private static String sDefaultTitle;
+
+ private final WeakReference<TabBase> mTab;
+
+ public TabPrinter(TabBase tab) {
+ mTab = new WeakReference<TabBase>(tab);
+ }
+
+ public static void setDefaultTitle(String defaultTitle) {
+ sDefaultTitle = defaultTitle;
+ }
+
+ @Override
+ public boolean print() {
+ TabBase tab = mTab.get();
+ return tab != null && tab.print();
+ }
+
+ @Override
+ public String getTitle() {
+ TabBase tab = mTab.get();
+ if (tab == null) return sDefaultTitle;
+
+ String title = tab.getTitle();
+ if (!TextUtils.isEmpty(title)) return title;
+
+ String url = tab.getUrl();
+ if (!TextUtils.isEmpty(url)) return url;
+
+ return sDefaultTitle;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698