summaryrefslogtreecommitdiffstats
path: root/mojo/application/public/cpp/application_delegate.h
blob: a3784908739a9e8ca9212c7b73d47114b5d09aca (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
// 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 MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_DELEGATE_H_
#define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_DELEGATE_H_

#include <string>

#include "mojo/public/cpp/system/macros.h"

namespace mojo {

class ApplicationConnection;
class ApplicationImpl;

// An abstract class that the application may subclass to control various
// behaviors of ApplicationImpl.
class ApplicationDelegate {
 public:
  ApplicationDelegate();
  virtual ~ApplicationDelegate();

  // Called exactly once before any other method.
  virtual void Initialize(ApplicationImpl* app);

  // Override this method to configure what services a connection supports when
  // being connected to from an app.
  // Return false to reject the connection entirely.
  virtual bool ConfigureIncomingConnection(ApplicationConnection* connection);

  // Override this method to configure what services a connection supports when
  // connecting to another app.
  // Return false to reject the connection entirely.
  virtual bool ConfigureOutgoingConnection(ApplicationConnection* connection);

  // Called when the shell connection has a connection error.
  //
  // Return true to shutdown the application. Return false to skip shutting
  // down the connection, but user is then required to call
  // ApplicationImpl::QuitNow() when done.
  virtual bool OnShellConnectionError();

  // Called before ApplicationImpl::Terminate(). After returning from this call
  // the delegate can no longer rely on the main run loop still running.
  virtual void Quit();

 private:
  MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationDelegate);
};

}  // namespace mojo

#endif  // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_DELEGATE_H_