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

Unified Diff: components/arc/test/fake_arc_bridge_service.cc

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit comment addressed 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: components/arc/test/fake_arc_bridge_service.cc
diff --git a/components/arc/test/fake_arc_bridge_service.cc b/components/arc/test/fake_arc_bridge_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dfc10ce9e9e5a2e3b33918f563d0369c4b0db531
--- /dev/null
+++ b/components/arc/test/fake_arc_bridge_service.cc
@@ -0,0 +1,120 @@
+// 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.
+
+#include "components/arc/test/fake_arc_bridge_service.h"
+
+#include "chrome/browser/ui/app_list/arc_app_list_prefs.h"
+#include "ui/app_list/app_list_constants.h"
+#include "ui/gfx/codec/png_codec.h"
+
+FakeArcBridgeService::FakeArcBridgeService()
+ : refresh_apps_count_(0) {
+}
+
+FakeArcBridgeService::~FakeArcBridgeService() {
+ if (state() != State::STOPPED) {
+ SetState(State::STOPPED);
+ }
+}
+
+void FakeArcBridgeService::HandleStartup() {
+}
+
+void FakeArcBridgeService::Shutdown() {
+}
+
+bool FakeArcBridgeService::RegisterInputDevice(const std::string& name,
+ const std::string& device_type,
+ base::ScopedFD fd) {
+ return true;
+}
+
+bool FakeArcBridgeService::RefreshApps() {
+ ++refresh_apps_count_;
+ return true;
+}
+
+bool FakeArcBridgeService::LaunchApp(const std::string& package,
+ const std::string& activity) {
+ launch_requests_.push_back(ArcAppListPrefs::GetAppId(package, activity));
+ return true;
+}
+
+bool FakeArcBridgeService::RequestIcon(const std::string& package,
+ const std::string& activity,
+ int scale_factor) {
+ IconRequest request;
+ request.package = package;
+ request.activity = activity;
+ request.scale_factor = scale_factor;
+ icon_requests_.push_back(request);
+ return true;
+}
+
+void FakeArcBridgeService::SetReady() {
+ SetState(State::READY);
+}
+
+void FakeArcBridgeService::SetStopped() {
+ SetState(State::STOPPED);
+}
+
+bool FakeArcBridgeService::HasObserver(const Observer* observer) const {
+ return observer_list_.HasObserver(observer);
+}
+
+void FakeArcBridgeService::SendRefreshApps(size_t size, const AppInfo* apps) {
+ std::vector<std::string> names(size);
+ std::vector<std::string> packages(size);
+ std::vector<std::string> activities(size);
+ for (size_t i = 0; i < size; ++i) {
+ names[i] = apps[i].name;
+ packages[i] = apps[i].package;
+ activities[i] = apps[i].activity;
+ }
+
+ FOR_EACH_OBSERVER(Observer,
+ observer_list_,
+ OnAppsRefreshed(names, packages, activities));
+}
+
+bool FakeArcBridgeService::GenerateAndSendIcon(
+ const AppInfo& app,
+ ui::ScaleFactor scale_factor,
+ std::vector<unsigned char>* png_data) {
+ const float scale = ui::GetScaleForScaleFactor(scale_factor);
+ const int icon_size = static_cast<int>(
+ app_list::kGridIconDimension * scale + 0.5f);
+
+ const int row_width = icon_size * 4;
+ const int data_size = icon_size * row_width;
+
+ // Generate random content.
+ std::vector<unsigned char> pixels(data_size);
+ for (int i = 0; i < icon_size; ++i) {
+ memset(&pixels[i * row_width], rand(), row_width);
+ }
+
+ if (!gfx::PNGCodec::Encode(&pixels[0],
+ gfx::PNGCodec::FORMAT_RGBA,
+ gfx::Size(icon_size, icon_size),
+ row_width,
+ false,
+ std::vector<gfx::PNGCodec::Comment>(),
+ png_data)) {
+ return false;
+ }
+
+ FOR_EACH_OBSERVER(Observer,
+ observer_list_,
+ OnAppIcon(app.package,
+ app.activity,
+ scale_factor,
+ *png_data));
+ return true;
+}
+
+std::string FakeArcBridgeService::AppInfo::id() const {
+ return ArcAppListPrefs::GetAppId(package, activity);
+}

Powered by Google App Engine
This is Rietveld 408576698