diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/arc.gypi | 2 | ||||
-rw-r--r-- | components/arc/BUILD.gn | 2 | ||||
-rw-r--r-- | components/arc/arc_bridge_service.h | 12 | ||||
-rw-r--r-- | components/arc/arc_bridge_service_impl.cc | 21 | ||||
-rw-r--r-- | components/arc/arc_bridge_service_impl.h | 5 | ||||
-rw-r--r-- | components/arc/arc_service_manager.cc | 9 | ||||
-rw-r--r-- | components/arc/arc_service_manager.h | 4 | ||||
-rw-r--r-- | components/arc/common/arc_bridge.mojom | 11 | ||||
-rw-r--r-- | components/arc/settings/arc_settings_bridge.cc | 11 | ||||
-rw-r--r-- | components/arc/settings/arc_settings_bridge.h | 26 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_instance.cc | 4 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_instance.h | 6 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_service.cc | 7 | ||||
-rw-r--r-- | components/arc/test/fake_arc_bridge_service.h | 4 |
14 files changed, 121 insertions, 3 deletions
diff --git a/components/arc.gypi b/components/arc.gypi index 62cc463..ab98050 100644 --- a/components/arc.gypi +++ b/components/arc.gypi @@ -31,6 +31,8 @@ 'arc/input/arc_input_bridge.h', 'arc/input/arc_input_bridge_impl.cc', 'arc/input/arc_input_bridge_impl.h', + 'arc/settings/arc_settings_bridge.cc', + 'arc/settings/arc_settings_bridge.h', ], }, { diff --git a/components/arc/BUILD.gn b/components/arc/BUILD.gn index 4b33a45..4f96906 100644 --- a/components/arc/BUILD.gn +++ b/components/arc/BUILD.gn @@ -17,6 +17,8 @@ static_library("arc") { "input/arc_input_bridge.h", "input/arc_input_bridge_impl.cc", "input/arc_input_bridge_impl.h", + "settings/arc_settings_bridge.cc", + "settings/arc_settings_bridge.h", ] deps = [ diff --git a/components/arc/arc_bridge_service.h b/components/arc/arc_bridge_service.h index 98902e6..f3cc81f 100644 --- a/components/arc/arc_bridge_service.h +++ b/components/arc/arc_bridge_service.h @@ -13,6 +13,7 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" +#include "base/values.h" #include "components/arc/common/arc_bridge.mojom.h" namespace base { @@ -205,6 +206,17 @@ class ArcBridgeService { // When the result comes back, Observer::OnUpdateProcessList() is called. virtual bool RequestProcessList() = 0; + // Send an Android broadcast message to the Android package and class + // specified. The 'extras' DictionaryValue will be converted to an Android + // Bundle accessible by the broadcast receiver. + // + // Note: Broadcasts can only be sent to whitelisted packages. Packages can be + // added to the whitelist in ArcBridgeService.java in the Android source. + virtual bool SendBroadcast(const std::string& action, + const std::string& package, + const std::string& clazz, + const base::DictionaryValue& extras) = 0; + protected: ArcBridgeService(); diff --git a/components/arc/arc_bridge_service_impl.cc b/components/arc/arc_bridge_service_impl.cc index d5485b4..38aed8b 100644 --- a/components/arc/arc_bridge_service_impl.cc +++ b/components/arc/arc_bridge_service_impl.cc @@ -8,6 +8,7 @@ #include <utility> #include "base/command_line.h" +#include "base/json/json_writer.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/sequenced_task_runner.h" @@ -120,6 +121,26 @@ bool ArcBridgeServiceImpl::RegisterInputDevice(const std::string& name, return true; } +bool ArcBridgeServiceImpl::SendBroadcast(const std::string& action, + const std::string& package, + const std::string& clazz, + const base::DictionaryValue& extras) { + DCHECK(CalledOnValidThread()); + if (action.empty() || package.empty() || clazz.empty()) { + LOG(ERROR) << "SendBroadcast failed: Invalid parameter"; + return false; + } + std::string extras_json; + bool write_success = base::JSONWriter::Write(extras, &extras_json); + DCHECK(write_success); + if (state() != State::READY) { + LOG(ERROR) << "Called SendBroadcast when the service is not ready"; + return false; + } + instance_ptr_->SendBroadcast(action, package, clazz, extras_json); + return true; +} + bool ArcBridgeServiceImpl::SendNotificationEventToAndroid( const std::string& key, ArcNotificationEvent event) { DCHECK(CalledOnValidThread()); diff --git a/components/arc/arc_bridge_service_impl.h b/components/arc/arc_bridge_service_impl.h index 8c744e1..969e0cb 100644 --- a/components/arc/arc_bridge_service_impl.h +++ b/components/arc/arc_bridge_service_impl.h @@ -40,6 +40,11 @@ class ArcBridgeServiceImpl : public ArcBridgeService, const std::string& device_type, base::ScopedFD fd) override; + bool SendBroadcast(const std::string& action, + const std::string& package, + const std::string& clazz, + const base::DictionaryValue& extras) override; + bool SendNotificationEventToAndroid(const std::string& key, ArcNotificationEvent event) override; diff --git a/components/arc/arc_service_manager.cc b/components/arc/arc_service_manager.cc index 2fc0e00..68f01cb1 100644 --- a/components/arc/arc_service_manager.cc +++ b/components/arc/arc_service_manager.cc @@ -9,6 +9,7 @@ #include "components/arc/arc_bridge_bootstrap.h" #include "components/arc/arc_bridge_service_impl.h" #include "components/arc/input/arc_input_bridge.h" +#include "components/arc/settings/arc_settings_bridge.h" namespace arc { @@ -19,12 +20,16 @@ ArcServiceManager* g_arc_service_manager = nullptr; } // namespace -ArcServiceManager::ArcServiceManager() +ArcServiceManager::ArcServiceManager( + scoped_ptr<ArcSettingsBridge> settings_bridge) : arc_bridge_service_( - new ArcBridgeServiceImpl(ArcBridgeBootstrap::Create())) { + new ArcBridgeServiceImpl(ArcBridgeBootstrap::Create())), + arc_settings_bridge_(std::move(settings_bridge)) { DCHECK(!g_arc_service_manager); arc_input_bridge_ = ArcInputBridge::Create(arc_bridge_service_.get()); g_arc_service_manager = this; + + arc_settings_bridge_->StartObservingBridgeServiceChanges(); } ArcServiceManager::~ArcServiceManager() { diff --git a/components/arc/arc_service_manager.h b/components/arc/arc_service_manager.h index ed4b434..07d6273 100644 --- a/components/arc/arc_service_manager.h +++ b/components/arc/arc_service_manager.h @@ -13,12 +13,13 @@ namespace arc { class ArcBridgeService; class ArcInputBridge; +class ArcSettingsBridge; // Manages creation and destruction of services that communicate with the ARC // instance via the ArcBridgeService. class ArcServiceManager { public: - ArcServiceManager(); + explicit ArcServiceManager(scoped_ptr<ArcSettingsBridge> settings_bridge); virtual ~ArcServiceManager(); // |arc_bridge_service| can only be accessed on the thread that this @@ -33,6 +34,7 @@ class ArcServiceManager { base::ThreadChecker thread_checker_; scoped_ptr<ArcBridgeService> arc_bridge_service_; scoped_ptr<ArcInputBridge> arc_input_bridge_; + scoped_ptr<ArcSettingsBridge> arc_settings_bridge_; DISALLOW_COPY_AND_ASSIGN(ArcServiceManager); }; diff --git a/components/arc/common/arc_bridge.mojom b/components/arc/common/arc_bridge.mojom index f555fbcc..b2e0060 100644 --- a/components/arc/common/arc_bridge.mojom +++ b/components/arc/common/arc_bridge.mojom @@ -263,4 +263,15 @@ interface ArcBridgeInstance { // Requests ARC instance to return the current process list. RequestProcessList(); + + // Send an Android broadcast message to the Android package and class + // specified. Data can be sent as extras by including a JSON map string which + // will be automatically converted to a bundle accessible by the receiver. + // + // Note: Broadcasts can only be sent to whitelisted packages. Packages can be + // added to the whitelist in ArcBridgeService.java in the Android source. + SendBroadcast(string action, + string package, + string cls, + string extras); }; diff --git a/components/arc/settings/arc_settings_bridge.cc b/components/arc/settings/arc_settings_bridge.cc new file mode 100644 index 0000000..649ddbe --- /dev/null +++ b/components/arc/settings/arc_settings_bridge.cc @@ -0,0 +1,11 @@ +// 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/settings/arc_settings_bridge.h" + +namespace arc { + +ArcSettingsBridge::~ArcSettingsBridge() {} + +} // namespace arc diff --git a/components/arc/settings/arc_settings_bridge.h b/components/arc/settings/arc_settings_bridge.h new file mode 100644 index 0000000..ba774c1 --- /dev/null +++ b/components/arc/settings/arc_settings_bridge.h @@ -0,0 +1,26 @@ +// 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_SETTINGS_ARC_SETTINGS_BRIDGE_H_ +#define COMPONENTS_ARC_SETTINGS_ARC_SETTINGS_BRIDGE_H_ + +namespace arc { + +// We want ArcServiceManager to own the ArcSettingsBridge but ArcSettingsBridge +// depends on code in chrome/ which is not accessible from components/. Since +// ArcSettingsBridge interacts with the bridge through the global Get function, +// session manager only needs to see a limited interface. +// +// Full implementation at chrome/browser/chromeos/arc/arc_settings_bridge_impl.h +class ArcSettingsBridge { + public: + virtual ~ArcSettingsBridge() = 0; + + // Starts listening to state changes of the ArcBridgeService + virtual void StartObservingBridgeServiceChanges() = 0; +}; + +} // namespace arc + +#endif // COMPONENTS_ARC_SETTINGS_ARC_SETTINGS_BRIDGE_H_ diff --git a/components/arc/test/fake_arc_bridge_instance.cc b/components/arc/test/fake_arc_bridge_instance.cc index ffba237..e0c1813 100644 --- a/components/arc/test/fake_arc_bridge_instance.cc +++ b/components/arc/test/fake_arc_bridge_instance.cc @@ -33,6 +33,10 @@ void FakeArcBridgeInstance::LaunchApp(const mojo::String& package, void FakeArcBridgeInstance::RequestAppIcon(const mojo::String& package, const mojo::String& activity, ScaleFactor scale_factor) {} +void FakeArcBridgeInstance::SendBroadcast(const mojo::String& action, + const mojo::String& package, + const mojo::String& clazz, + const mojo::String& extras) {} void FakeArcBridgeInstance::RequestProcessList() {} diff --git a/components/arc/test/fake_arc_bridge_instance.h b/components/arc/test/fake_arc_bridge_instance.h index 82bad56..81de1f1 100644 --- a/components/arc/test/fake_arc_bridge_instance.h +++ b/components/arc/test/fake_arc_bridge_instance.h @@ -34,8 +34,14 @@ class FakeArcBridgeInstance : public ArcBridgeInstance { void RequestAppIcon(const mojo::String& package, const mojo::String& activity, ScaleFactor scale_factor) override; + void RequestProcessList() override; + void SendBroadcast(const mojo::String& action, + const mojo::String& package, + const mojo::String& clazz, + const mojo::String& extras) override; + private: // Mojo endpoints. mojo::Binding<ArcBridgeInstance> binding_; diff --git a/components/arc/test/fake_arc_bridge_service.cc b/components/arc/test/fake_arc_bridge_service.cc index 2c69080..a73bfb4 100644 --- a/components/arc/test/fake_arc_bridge_service.cc +++ b/components/arc/test/fake_arc_bridge_service.cc @@ -34,6 +34,13 @@ bool FakeArcBridgeService::RegisterInputDevice(const std::string& name, return true; } +bool FakeArcBridgeService::SendBroadcast(const std::string& action, + const std::string& package, + const std::string& clazz, + const base::DictionaryValue& extras) { + return true; +} + bool FakeArcBridgeService::SendNotificationEventToAndroid( const std::string& key, ArcNotificationEvent event) { diff --git a/components/arc/test/fake_arc_bridge_service.h b/components/arc/test/fake_arc_bridge_service.h index 70d862e..0d2bb07 100644 --- a/components/arc/test/fake_arc_bridge_service.h +++ b/components/arc/test/fake_arc_bridge_service.h @@ -71,6 +71,10 @@ class FakeArcBridgeService : public ArcBridgeService { bool RegisterInputDevice(const std::string& name, const std::string& device_type, base::ScopedFD fd) override; + bool SendBroadcast(const std::string& action, + const std::string& package, + const std::string& clazz, + const base::DictionaryValue& extras) override; bool RefreshAppList() override; bool LaunchApp(const std::string& package, const std::string& activity) override; |