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

Unified Diff: chrome/browser/ui/app_list/arc_app_icon.h

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Discard accidental change in chrome/browser/prefs/browser_prefs.cc Created 5 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/browser/ui/app_list/arc_app_icon.h
diff --git a/chrome/browser/ui/app_list/arc_app_icon.h b/chrome/browser/ui/app_list/arc_app_icon.h
new file mode 100644
index 0000000000000000000000000000000000000000..8787342e73da64e1708adaa1caab8cee31d6379a
--- /dev/null
+++ b/chrome/browser/ui/app_list/arc_app_icon.h
@@ -0,0 +1,98 @@
+// Copyright 2015 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.
+
+#ifndef CHROME_BROWSER_UI_APP_LIST_ARC_APP_ICON_H_
+#define CHROME_BROWSER_UI_APP_LIST_ARC_APP_ICON_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
+#include "ui/base/layout.h"
+#include "ui/gfx/image/image.h"
+#include "ui/gfx/image/image_skia.h"
+
+namespace base {
+class FilePath;
+}
+
+namespace content {
+class BrowserContext;
+}
+
+// A class that provides an ImageSkia for UI code to use. It handles Arc app
Luis Héctor Chávez 2015/11/12 20:49:16 Use "ARC" consistently across this change.
khmel1 2015/11/13 15:00:55 Done.
+// icon resource loading, screen scale factor change etc. UI code that uses
+// Arc app icon should host this class.
+class ArcAppIcon {
+ public:
+ class Observer {
+ public:
+ // Invoked when a new image rep for an additional scale factor
+ // is loaded and added to |image|.
+ virtual void OnIconUpdated() = 0;
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ ArcAppIcon(content::BrowserContext* context,
+ const std::string& app_id,
+ int resource_size_in_dip,
+ Observer* observer);
+ ~ArcAppIcon();
+
+ gfx::Image image() const { return image_; }
+ const gfx::ImageSkia& image_skia() const { return image_skia_; }
+
+ // Icon loading is performed in several steps. It is initiated by
+ // LoadImageForScaleFactor request that specifies a required scale factor.
+ // ArcAppPrefs is used to resolve a path to resource. Content of file is
+ // asynchronously read in context of browser file thread. On success read,
Luis Héctor Chávez 2015/11/12 20:49:16 nit: On successful read.
khmel1 2015/11/13 15:00:55 Done.
+ // an icon data is decoded to an image in the special utility process.
+ // DecodeRequest is used to interact with the utility process, and each
+ // active request is stored at decode_requests_ vector. When decoding is
Luis Héctor Chávez 2015/11/12 20:49:16 nit: |decode_requests_|. Same below.
khmel1 2015/11/13 15:00:55 Done.
+ // complete, results are returned in context of UI thread, and corresponding
+ // request is removed from decode_requests_. In case of some requests are not
+ // completed by the time of deleting this icon, they are automatically
+ // canceled.
+ // In case of the icon file is not available this requests ArcAppPrefs to
+ // install required resource from Android side. ArcAppPrefs notifies UI items
Luis Héctor Chávez 2015/11/12 20:49:16 Try to say "ARC" instead of Android.
khmel1 2015/11/13 15:00:55 Done.
+ // that new icon is available and corresponding item should invoke
+ // LoadImageForScaleFactor again.
+ void LoadForScaleFactor(ui::ScaleFactor scale_factor);
+
+ private:
+ class Source;
+ class DecodeRequest;
+
+ void RequestIcon(ui::ScaleFactor scale_factor);
+ void ReadOnFileThread(ui::ScaleFactor scale_factor,
+ const base::FilePath& path);
+ void OnIconRead(ui::ScaleFactor scale_factor,
+ const std::string& unsafe_image_data);
+ void Update(const gfx::ImageSkia* image);
+ void DiscardDecodeRequest(DecodeRequest* request);
+
+ content::BrowserContext* context_;
+ std::string app_id_;
+ const int resource_size_in_dip_;
+ Observer* observer_;
+
+ Source* source_ = nullptr; // Owned by ImageSkia storage.
Luis Héctor Chávez 2015/11/12 20:49:16 Can this be initialized in the constructor?
xiyuan 2015/11/12 21:34:02 This is the preferred style in chromium code. See
khmel1 2015/11/13 15:00:55 Acknowledged.
khmel1 2015/11/13 15:00:55 Acknowledged.
+ gfx::ImageSkia image_skia_;
+
+ // The image wrapper around |image_skia_|.
+ // Note: this is reset each time a new representation is loaded.
+ gfx::Image image_;
+
+ // Contains pending image decode requests.
+ ScopedVector<DecodeRequest> decode_requests_;
+
+ base::WeakPtrFactory<ArcAppIcon> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcAppIcon);
+};
+
+#endif // CHROME_BROWSER_UI_APP_LIST_ARC_APP_ICON_H_

Powered by Google App Engine
This is Rietveld 408576698