diff options
author | khmel <khmel@chromium.org> | 2015-12-04 08:24:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-04 16:26:12 +0000 |
commit | d7c5a3215244c5aa2165b6284bc8d19d5792af8c (patch) | |
tree | 04461d8498ad0c52fd98d50763138fc4f05793d7 /components | |
parent | b4e689e5049a21c645f215e8a01c28c6fad22b7f (diff) | |
download | chromium_src-d7c5a3215244c5aa2165b6284bc8d19d5792af8c.zip chromium_src-d7c5a3215244c5aa2165b6284bc8d19d5792af8c.tar.gz chromium_src-d7c5a3215244c5aa2165b6284bc8d19d5792af8c.tar.bz2 |
arc-app-launcher: Minimal support for ARC app launcher.
This provides extension to app_list model that manages arc
apps. It includes preference based service that interacts
with arc bridge and supports an arc app life cycle; app list
model builder for arc apps; arc list item. legacy
ExtensionAppModelBuilder and new ArcAppModelBuilder are
refactored in order to inherit common code.
BUG=558209
TEST=Build and deploy android, chrome, chromium CLs. Apps
appear in chromium app launcher. Once clicked, app
is started in Android window.
TEST=unit_tests with enable_arc=1 Debug/Release
Review URL: https://codereview.chromium.org/1413153007
Cr-Commit-Position: refs/heads/master@{#363220}
Diffstat (limited to 'components')
-rw-r--r-- | components/arc.gypi | 16 | ||||
-rw-r--r-- | components/arc/BUILD.gn | 13 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_service.cc | 145 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_service.h | 119 | ||||
-rw-r--r-- | components/test/data/arc/icon_100p.png | bin | 0 -> 2794 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_125p.png | bin | 0 -> 3952 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_133p.png | bin | 0 -> 4303 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_140p.png | bin | 0 -> 4499 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_150p.png | bin | 0 -> 4861 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_180p.png | bin | 0 -> 5573 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_200p.png | bin | 0 -> 5679 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_250p.png | bin | 0 -> 6221 bytes | |||
-rw-r--r-- | components/test/data/arc/icon_300p.png | bin | 0 -> 3548 bytes |
13 files changed, 293 insertions, 0 deletions
diff --git a/components/arc.gypi b/components/arc.gypi index 7ad1264..7105b7b 100644 --- a/components/arc.gypi +++ b/components/arc.gypi @@ -32,5 +32,21 @@ 'arc/common/arc_notification_types.cc', ], }, + { + # GN version: //components/arc_test_support + 'target_name': 'arc_test_support', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../base/base.gyp:base', + 'arc', + ], + 'sources': [ + 'arc/test/fake_arc_bridge_service.cc', + 'arc/test/fake_arc_bridge_service.h', + ], + }, ], } diff --git a/components/arc/BUILD.gn b/components/arc/BUILD.gn index fe11655..6ab9270 100644 --- a/components/arc/BUILD.gn +++ b/components/arc/BUILD.gn @@ -20,6 +20,19 @@ static_library("arc") { ] } +static_library("arc_test_support") { + testonly = true + sources = [ + "test/fake_arc_bridge_service.cc", + "test/fake_arc_bridge_service.h", + ] + + deps = [ + ":arc", + "//base", + ] +} + source_set("unit_tests") { testonly = true sources = [ 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 0000000..ace3acf --- /dev/null +++ b/components/arc/test/fake_arc_bridge_service.cc @@ -0,0 +1,145 @@ +// 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 "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/path_service.h" + +namespace arc { + +FakeArcBridgeService::FakeArcBridgeService() { +} + +FakeArcBridgeService::~FakeArcBridgeService() { + if (state() != State::STOPPED) { + SetState(State::STOPPED); + } +} + +void FakeArcBridgeService::DetectAvailability() { +} + +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::SendNotificationEventToAndroid( + const std::string& key, + ArcNotificationEvent event) { + return true; +} + +bool FakeArcBridgeService::RefreshAppList() { + ++refresh_app_list_count_; + return true; +} + +bool FakeArcBridgeService::LaunchApp(const std::string& package, + const std::string& activity) { + launch_requests_.push_back(new Request(package, activity)); + return true; +} + +bool FakeArcBridgeService::RequestAppIcon(const std::string& package, + const std::string& activity, + ScaleFactor scale_factor) { + icon_requests_.push_back(new IconRequest(package, activity, scale_factor)); + return true; +} + +void FakeArcBridgeService::SetReady() { + SetState(State::READY); +} + +void FakeArcBridgeService::SetStopped() { + SetState(State::STOPPED); +} + +bool FakeArcBridgeService::HasObserver(const Observer* observer) { + return observer_list().HasObserver(observer); +} + +bool FakeArcBridgeService::HasAppObserver(const AppObserver* observer) { + return app_observer_list().HasObserver(observer); +} + +void FakeArcBridgeService::SendRefreshAppList( + const std::vector<AppInfo>& apps) { + FOR_EACH_OBSERVER(AppObserver, app_observer_list(), OnAppListRefreshed(apps)); +} + +bool FakeArcBridgeService::GenerateAndSendIcon( + const AppInfo& app, + ScaleFactor scale_factor, + std::string* png_data_as_string) { + CHECK(png_data_as_string != nullptr); + std::string icon_file_name; + switch(scale_factor) { + case SCALE_FACTOR_100P: + icon_file_name = "icon_100p.png"; + break; + case SCALE_FACTOR_125P: + icon_file_name = "icon_125p.png"; + break; + case SCALE_FACTOR_133P: + icon_file_name = "icon_133p.png"; + break; + case SCALE_FACTOR_140P: + icon_file_name = "icon_140p.png"; + break; + case SCALE_FACTOR_150P: + icon_file_name = "icon_150p.png"; + break; + case SCALE_FACTOR_180P: + icon_file_name = "icon_180p.png"; + break; + case SCALE_FACTOR_200P: + icon_file_name = "icon_200p.png"; + break; + case SCALE_FACTOR_250P: + icon_file_name = "icon_250p.png"; + break; + case SCALE_FACTOR_300P: + icon_file_name = "icon_300p.png"; + break; + default: + NOTREACHED(); + return false; + } + + base::FilePath base_path; + CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &base_path)); + base::FilePath icon_file_path = base_path + .AppendASCII("components") + .AppendASCII("test") + .AppendASCII("data") + .AppendASCII("arc") + .AppendASCII(icon_file_name); + CHECK(base::PathExists(icon_file_path)); + CHECK(base::ReadFileToString(icon_file_path, png_data_as_string)); + + std::vector<uint8_t> png_data(png_data_as_string->begin(), + png_data_as_string->end()); + + FOR_EACH_OBSERVER(AppObserver, + app_observer_list(), + OnAppIcon(app.package, + app.activity, + scale_factor, + png_data)); + + return true; +} + +} // namespace arc diff --git a/components/arc/test/fake_arc_bridge_service.h b/components/arc/test/fake_arc_bridge_service.h new file mode 100644 index 0000000..ef4e20d --- /dev/null +++ b/components/arc/test/fake_arc_bridge_service.h @@ -0,0 +1,119 @@ +// 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 COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ +#define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ + +#include <string> +#include <vector> + +#include "base/macros.h" +#include "base/memory/scoped_vector.h" +#include "components/arc/arc_bridge_service.h" + +namespace arc { + +class FakeArcBridgeService : public ArcBridgeService { + public: + class Request { + public: + Request(const std::string& package, const std::string& activity) + : package_(package), + activity_(activity) { + } + + ~Request() { + } + + const std::string& package() const { return package_; } + + const std::string& activity() const { return activity_; } + + bool IsForApp(const AppInfo& app_info) const { + return package_ == app_info.package && activity_ == app_info.activity; + } + + private: + std::string package_; + std::string activity_; + + DISALLOW_COPY_AND_ASSIGN(Request); + }; + + class IconRequest : public Request { + public: + IconRequest(const std::string& package, + const std::string& activity, + ScaleFactor scale_factor) + : Request(package, activity), + scale_factor_(scale_factor) { + } + + ~IconRequest() { + } + + int scale_factor() const { return scale_factor_; } + + private: + int scale_factor_; + + DISALLOW_COPY_AND_ASSIGN(IconRequest); + }; + + FakeArcBridgeService(); + ~FakeArcBridgeService() override; + + // arc::ArcBridgeService + void DetectAvailability() override; + void HandleStartup() override; + void Shutdown() override; + bool RegisterInputDevice(const std::string& name, + const std::string& device_type, + base::ScopedFD fd) override; + bool RefreshAppList() override; + bool LaunchApp(const std::string& package, + const std::string& activity) override; + bool RequestAppIcon(const std::string& package, + const std::string& activity, + ScaleFactor scale_factor) override; + bool SendNotificationEventToAndroid(const std::string& key, + ArcNotificationEvent event) override; + + int refresh_app_list_count() const { return refresh_app_list_count_; } + + const ScopedVector<Request>& launch_requests() const { + return launch_requests_; + } + + const ScopedVector<IconRequest>& icon_requests() const { + return icon_requests_; + } + + void SetReady(); + + void SetStopped(); + + bool HasObserver(const Observer* observer); + bool HasAppObserver(const AppObserver* observer); + + void SendRefreshAppList(const std::vector<AppInfo>& apps); + + bool GenerateAndSendIcon(const AppInfo& app, + ScaleFactor scale_factor, + std::string* png_data); + + private: + // Number of RefreshAppList calls. + int refresh_app_list_count_ = 0; + // Keeps information about launch requests. + ScopedVector<Request> launch_requests_; + // Keeps information about icon load requests. + ScopedVector<IconRequest> icon_requests_; + + DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeService); +}; + +} // namespace arc + +#endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_SERVICE_H_ diff --git a/components/test/data/arc/icon_100p.png b/components/test/data/arc/icon_100p.png Binary files differnew file mode 100644 index 0000000..80a5d68 --- /dev/null +++ b/components/test/data/arc/icon_100p.png diff --git a/components/test/data/arc/icon_125p.png b/components/test/data/arc/icon_125p.png Binary files differnew file mode 100644 index 0000000..c9bae8e --- /dev/null +++ b/components/test/data/arc/icon_125p.png diff --git a/components/test/data/arc/icon_133p.png b/components/test/data/arc/icon_133p.png Binary files differnew file mode 100644 index 0000000..565bbac --- /dev/null +++ b/components/test/data/arc/icon_133p.png diff --git a/components/test/data/arc/icon_140p.png b/components/test/data/arc/icon_140p.png Binary files differnew file mode 100644 index 0000000..f85cae5 --- /dev/null +++ b/components/test/data/arc/icon_140p.png diff --git a/components/test/data/arc/icon_150p.png b/components/test/data/arc/icon_150p.png Binary files differnew file mode 100644 index 0000000..e3471fd --- /dev/null +++ b/components/test/data/arc/icon_150p.png diff --git a/components/test/data/arc/icon_180p.png b/components/test/data/arc/icon_180p.png Binary files differnew file mode 100644 index 0000000..91c8dcb --- /dev/null +++ b/components/test/data/arc/icon_180p.png diff --git a/components/test/data/arc/icon_200p.png b/components/test/data/arc/icon_200p.png Binary files differnew file mode 100644 index 0000000..be3aa10 --- /dev/null +++ b/components/test/data/arc/icon_200p.png diff --git a/components/test/data/arc/icon_250p.png b/components/test/data/arc/icon_250p.png Binary files differnew file mode 100644 index 0000000..4843664 --- /dev/null +++ b/components/test/data/arc/icon_250p.png diff --git a/components/test/data/arc/icon_300p.png b/components/test/data/arc/icon_300p.png Binary files differnew file mode 100644 index 0000000..d0afd96 --- /dev/null +++ b/components/test/data/arc/icon_300p.png |