From 38424588fa4fa84b31c85034f4e427f67398a912 Mon Sep 17 00:00:00 2001 From: jamescook Date: Tue, 11 Nov 2014 15:48:06 -0800 Subject: [PATCH] app_shell: Connect shell.gcd app API to Chrome OS privetd DBus API privetd is a Chrome OS local disovery and setup daemon. This connects the shell.gcd app_shell API to the DBus methods to get setup status. BUG=428853,428848 TEST=app_shell_unittests Review URL: https://codereview.chromium.org/687823007 Cr-Commit-Position: refs/heads/master@{#303750} --- extensions/shell/BUILD.gn | 6 ++++-- extensions/shell/app_shell.gyp | 15 +++++++++------ .../shell/browser/api/shell_gcd/shell_gcd_api.cc | 18 +++++++++++++----- .../shell/browser/api/shell_gcd/shell_gcd_api.h | 5 ++++- .../api/shell_gcd/shell_gcd_api_unittest.cc | 22 +++++++++++++++++++++- extensions/shell/common/api/schemas.gni | 3 +++ extensions/shell/common/api/schemas.gypi | 20 ++++++++++++++++---- 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/extensions/shell/BUILD.gn b/extensions/shell/BUILD.gn index 7d436ce19e3d..a97dfd28adb2 100644 --- a/extensions/shell/BUILD.gn +++ b/extensions/shell/BUILD.gn @@ -58,8 +58,6 @@ source_set("app_shell_lib") { "app/shell_main_delegate.h", "browser/api/identity/identity_api.cc", "browser/api/identity/identity_api.h", - "browser/api/shell_gcd/shell_gcd_api.cc", - "browser/api/shell_gcd/shell_gcd_api.h", "browser/api/shell_window/shell_window_api.cc", "browser/api/shell_window/shell_window_api.h", "browser/default_shell_browser_main_delegate.cc", @@ -135,6 +133,10 @@ source_set("app_shell_lib") { "//ui/chromeos:ui_chromeos", "//ui/display", ] + sources += [ + "browser/api/shell_gcd/shell_gcd_api.cc", + "browser/api/shell_gcd/shell_gcd_api.h", + ] } } diff --git a/extensions/shell/app_shell.gyp b/extensions/shell/app_shell.gyp index 6e1ee7595973..0f4e94984a16 100644 --- a/extensions/shell/app_shell.gyp +++ b/extensions/shell/app_shell.gyp @@ -52,8 +52,6 @@ 'app/shell_main_delegate.h', 'browser/api/identity/identity_api.cc', 'browser/api/identity/identity_api.h', - 'browser/api/shell_gcd/shell_gcd_api.cc', - 'browser/api/shell_gcd/shell_gcd_api.h', 'browser/api/shell_window/shell_window_api.cc', 'browser/api/shell_window/shell_window_api.h', 'browser/shell_browser_context_keyed_service_factories.cc', @@ -130,6 +128,10 @@ '<(DEPTH)/ui/chromeos/ui_chromeos.gyp:ui_chromeos', '<(DEPTH)/ui/display/display.gyp:display', ], + 'sources': [ + 'browser/api/shell_gcd/shell_gcd_api.cc', + 'browser/api/shell_gcd/shell_gcd_api.h', + ], }], ['disable_nacl==0 and OS=="linux"', { 'dependencies': [ @@ -250,17 +252,15 @@ 'sources': [ '../test/extensions_unittests_main.cc', 'browser/api/identity/identity_api_unittest.cc', - 'browser/api/shell_gcd/shell_gcd_api_unittest.cc', 'browser/api/shell_window/shell_window_api_unittest.cc', 'browser/shell_audio_controller_chromeos_unittest.cc', 'browser/shell_desktop_controller_unittest.cc', - 'browser/shell_nacl_browser_delegate_unittest.cc', 'browser/shell_oauth2_token_service_unittest.cc', 'common/shell_content_client_unittest.cc' ], 'conditions': [ - ['disable_nacl==1', { - 'sources!': [ + ['disable_nacl==0', { + 'sources': [ 'browser/shell_nacl_browser_delegate_unittest.cc', ], }], @@ -268,6 +268,9 @@ 'dependencies': [ '<(DEPTH)/chromeos/chromeos.gyp:chromeos_test_support_without_gmock', ], + 'sources': [ + 'browser/api/shell_gcd/shell_gcd_api_unittest.cc', + ], }], ['OS=="win" and win_use_allocator_shim==1', { 'dependencies': [ diff --git a/extensions/shell/browser/api/shell_gcd/shell_gcd_api.cc b/extensions/shell/browser/api/shell_gcd/shell_gcd_api.cc index ae1dd4b2a128..2cbb133a6b32 100644 --- a/extensions/shell/browser/api/shell_gcd/shell_gcd_api.cc +++ b/extensions/shell/browser/api/shell_gcd/shell_gcd_api.cc @@ -5,9 +5,11 @@ #include "extensions/shell/browser/api/shell_gcd/shell_gcd_api.h" #include "base/values.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/privet_daemon_client.h" #include "extensions/shell/common/api/shell_gcd.h" -namespace shell_gcd = extensions::shell::api::shell_gcd; +namespace gcd = extensions::shell::api::shell_gcd; namespace extensions { @@ -18,10 +20,16 @@ ShellGcdGetSetupStatusFunction::~ShellGcdGetSetupStatusFunction() { } ExtensionFunction::ResponseAction ShellGcdGetSetupStatusFunction::Run() { - // TODO(jamescook): Implement this. - shell_gcd::SetupStatus status = shell_gcd::SETUP_STATUS_COMPLETED; - return RespondNow( - ArgumentList(shell_gcd::GetSetupStatus::Results::Create(status))); + // |this| is refcounted so we don't need the usual DBus callback WeakPtr. + chromeos::DBusThreadManager::Get()->GetPrivetDaemonClient()->GetSetupStatus( + base::Bind(&ShellGcdGetSetupStatusFunction::OnSetupStatus, this)); + return RespondLater(); +} + +void ShellGcdGetSetupStatusFunction::OnSetupStatus( + const std::string& status_string) { + gcd::SetupStatus status = gcd::ParseSetupStatus(status_string); + Respond(ArgumentList(gcd::GetSetupStatus::Results::Create(status))); } } // namespace extensions diff --git a/extensions/shell/browser/api/shell_gcd/shell_gcd_api.h b/extensions/shell/browser/api/shell_gcd/shell_gcd_api.h index b93392845f10..defcd9b9321d 100644 --- a/extensions/shell/browser/api/shell_gcd/shell_gcd_api.h +++ b/extensions/shell/browser/api/shell_gcd/shell_gcd_api.h @@ -10,7 +10,7 @@ namespace extensions { -// TODO(jamescook): Write this function. It needs to talk to privet via DBus. +// See shell_gcd.idl for documentation. class ShellGcdGetSetupStatusFunction : public UIThreadExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("shell.gcd.getSetupStatus", UNKNOWN); @@ -24,6 +24,9 @@ class ShellGcdGetSetupStatusFunction : public UIThreadExtensionFunction { ResponseAction Run() override; private: + // Callback for status from DBus call to GCD privet daemon. + void OnSetupStatus(const std::string& status_string); + DISALLOW_COPY_AND_ASSIGN(ShellGcdGetSetupStatusFunction); }; diff --git a/extensions/shell/browser/api/shell_gcd/shell_gcd_api_unittest.cc b/extensions/shell/browser/api/shell_gcd/shell_gcd_api_unittest.cc index 382a92440d86..a22c9f2f1e6a 100644 --- a/extensions/shell/browser/api/shell_gcd/shell_gcd_api_unittest.cc +++ b/extensions/shell/browser/api/shell_gcd/shell_gcd_api_unittest.cc @@ -8,11 +8,31 @@ #include "base/memory/scoped_ptr.h" #include "base/values.h" +#include "chromeos/dbus/dbus_thread_manager.h" #include "extensions/browser/api_unittest.h" namespace extensions { -using ShellGcdApiTest = ApiUnitTest; +class ShellGcdApiTest : public ApiUnitTest { + public: + ShellGcdApiTest() {} + ~ShellGcdApiTest() override {} + + // testing::Test overrides: + void SetUp() override { + ApiUnitTest::SetUp(); + chromeos::DBusThreadManager::Initialize(); + } + + void TearDown() override { + chromeos::DBusThreadManager::Shutdown(); + ApiUnitTest::TearDown(); + } + + private: + + DISALLOW_COPY_AND_ASSIGN(ShellGcdApiTest); +}; TEST_F(ShellGcdApiTest, GetBootstrapStatus) { // Function succeeds and returns a result (for its callback). diff --git a/extensions/shell/common/api/schemas.gni b/extensions/shell/common/api/schemas.gni index 27dd0b8f1e57..b3b6db40fe6c 100644 --- a/extensions/shell/common/api/schemas.gni +++ b/extensions/shell/common/api/schemas.gni @@ -9,6 +9,9 @@ gypi_values = exec_script( [ "schemas.gypi" ]) sources = gypi_values.schema_files +if (is_chromeos) { + sources += gypi_values.chromeos_schema_files +} uncompiled_sources = gypi_values.non_compiled_schema_files diff --git a/extensions/shell/common/api/schemas.gypi b/extensions/shell/common/api/schemas.gypi index d2b0da8662a1..f995048068ea 100644 --- a/extensions/shell/common/api/schemas.gypi +++ b/extensions/shell/common/api/schemas.gypi @@ -7,16 +7,28 @@ '<@(schema_files)', ], 'variables': { - 'chromium_code': 1, - 'non_compiled_schema_files': [ - ], 'schema_files': [ 'identity.idl', - 'shell_gcd.idl', 'shell_window.idl', ], + 'non_compiled_schema_files': [ + ], + # Chrome OS specific APIs. + 'chromeos_schema_files': [ + 'shell_gcd.idl', + ], + + 'chromium_code': 1, 'cc_dir': 'extensions/shell/common/api', 'root_namespace': 'extensions::shell::api::%(namespace)s', 'impl_dir_': 'extensions/shell/browser/api', + + 'conditions': [ + ['chromeos==1', { + 'schema_files': [ + '<@(chromeos_schema_files)', + ], + }], + ], }, } -- 2.11.4.GIT