Home | History | Annotate | Download | only in shell
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MOJO_SHELL_KEEP_ALIVE_H_
      6 #define MOJO_SHELL_KEEP_ALIVE_H_
      7 
      8 #include "base/basictypes.h"
      9 
     10 namespace mojo {
     11 namespace shell {
     12 
     13 class Context;
     14 class KeepAlive;
     15 
     16 class KeepAliveCounter {
     17  public:
     18   KeepAliveCounter() : count_(0) {
     19   }
     20  private:
     21   friend class KeepAlive;
     22   int count_;
     23 };
     24 
     25 // Instantiate this class to extend the lifetime of the thread associated
     26 // with |context| (i.e., the shell's UI thread). Must only be used from
     27 // the shell's UI thread.
     28 class KeepAlive {
     29  public:
     30   explicit KeepAlive(Context* context);
     31   ~KeepAlive();
     32 
     33  private:
     34   static void MaybeQuit(Context* context);
     35 
     36   Context* context_;
     37 
     38   DISALLOW_COPY_AND_ASSIGN(KeepAlive);
     39 };
     40 
     41 }  // namespace shell
     42 }  // namespace mojo
     43 
     44 #endif  // MOJO_SHELL_KEEP_ALIVE_H_
     45