summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/services/console_service_provider.h
blob: 290be23e7b076f122bd40adf60c23b47eb0880c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2014 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 CHROMEOS_DBUS_SERVICES_CONSOLE_SERVICE_PROVIDER_H_
#define CHROMEOS_DBUS_SERVICES_CONSOLE_SERVICE_PROVIDER_H_

#include <string>

#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/services/cros_dbus_service.h"
#include "dbus/exported_object.h"

namespace chromeos {

// This class provides an API for external apps to notify
// chrome that it should release control of the display server.
// The main client is the console application.  This can
// also be used by crouton to take over the display.
class CHROMEOS_EXPORT ConsoleServiceProvider
    : public CrosDBusService::ServiceProviderInterface {
 public:
  class Delegate {
   public:
    virtual ~Delegate() {}

    // Performs the actual work needed by the provider methods with the same
    // names.
    virtual void TakeDisplayOwnership() = 0;
    virtual void ReleaseDisplayOwnership() = 0;
  };

  explicit ConsoleServiceProvider(scoped_ptr<Delegate> delegate);
  ~ConsoleServiceProvider() override;

  // CrosDBusService::ServiceProviderInterface overrides:
  void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;

 private:
  // This method will get called when a external process no longer needs
  // control of the display and Chrome can take ownership.
  void TakeDisplayOwnership(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  // This method will get called when a external process needs control of
  // the display and needs Chrome to release ownership.
  void ReleaseDisplayOwnership(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  // This method is called when a dbus method is exported.  If the export of the
  // method is successful, |success| will be true.  It will be false
  // otherwise.
  void OnExported(const std::string& interface_name,
                  const std::string& method_name,
                  bool success);

  scoped_ptr<Delegate> delegate_;
  base::WeakPtrFactory<ConsoleServiceProvider> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ConsoleServiceProvider);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_SERVICES_CONSOLE_SERVICE_PROVIDER_H_