Chromium Code Reviews| Index: ash/common/system/tray/system_tray_controller.h |
| diff --git a/ash/common/system/tray/system_tray_controller.h b/ash/common/system/tray/system_tray_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f3b8800e471a24ce834ce523f2d74c8b4a723199 |
| --- /dev/null |
| +++ b/ash/common/system/tray/system_tray_controller.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 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 ASH_COMMON_SYSTEM_TRAY_SYSTEM_TRAY_CONTROLLER_H_ |
| +#define ASH_COMMON_SYSTEM_TRAY_SYSTEM_TRAY_CONTROLLER_H_ |
| + |
| +#include "ash/public/interfaces/system_tray.mojom.h" |
| +#include "base/i18n/time_formatting.h" |
| +#include "base/macros.h" |
| +#include "mojo/public/cpp/bindings/binding_set.h" |
| + |
| +namespace shell { |
| +class Connector; |
| +} |
| + |
| +namespace ash { |
| + |
| +// Both implements mojom::SystemTray and wraps the mojom::SystemTrayClient |
| +// interface. The wrapper makes the initial connection and handles reconnecting |
| +// on error. Implements both because it caches state pushed down from the |
| +// browser process via SystemTray so it can be synchronously queried inside ash. |
| +// |
| +// Conceptually similar to historical ash-to-chrome interfaces like |
| +// SystemTrayDelegate. Lives on the main thread. |
| +// |
| +// Only connects to the actual mojom::SystemTrayClient interface when running on |
| +// Chrome OS. In tests and on Windows all operations are no-ops. |
| +// |
| +// TODO: Consider renaming this to SystemTrayClient or renaming the current |
| +// SystemTray to SystemTrayView and making this class SystemTray. |
| +class SystemTrayController : public mojom::SystemTray { |
| + public: |
| + explicit SystemTrayController(shell::Connector* connector); |
| + ~SystemTrayController() override; |
| + |
| + // Wrappers around the mojom::SystemTrayClient interface. |
| + base::HourClockType hour_clock_type() const { return hour_clock_type_; } |
| + void ShowDateSettings(); |
| + |
| + // Binds the mojom::SystemTray interface to this object. |
| + void BindRequest(mojom::SystemTrayRequest request); |
|
Ken Rockot(use gerrit already)
2016/10/03 18:19:03
Then again... if you keep MojoInterfaceFactory as
|
| + |
| + private: |
| + // Connects or reconnects to the mojom::SystemTrayClient interface when |
| + // running on Chrome OS. Otherwise does nothing. Returns true if connected. |
| + bool ConnectToSystemTrayClient(); |
| + |
| + // Handles errors on the |system_tray_client_| interface connection. |
| + void OnClientConnectionError(); |
| + |
| + // mojom::SystemTray: |
| + void SetUse24HourClock(bool use_24_hour) override; |
| + |
| + // May be null in unit tests. |
| + shell::Connector* connector_; |
| + |
| + // Client interface in chrome browser. Only bound on Chrome OS. |
| + mojom::SystemTrayClientPtr system_tray_client_; |
| + |
| + // Bindings for the SystemTray interface. |
| + mojo::BindingSet<mojom::SystemTray> bindings_; |
| + |
| + // The type of clock hour display: 12 or 24 hour. |
| + base::HourClockType hour_clock_type_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemTrayController); |
| +}; |
| + |
| +} // namspace ash |
| + |
| +#endif // ASH_COMMON_SYSTEM_TRAY_SYSTEM_TRAY_CONTROLLER_H_ |