Home | History | Annotate | Download | only in gin
      1 // Copyright 2013 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 GIN_PER_CONTEXT_DATA_H_
      6 #define GIN_PER_CONTEXT_DATA_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/supports_user_data.h"
     10 #include "gin/gin_export.h"
     11 #include "v8/include/v8.h"
     12 
     13 namespace gin {
     14 
     15 class ContextHolder;
     16 class Runner;
     17 
     18 // There is one instance of PerContextData per v8::Context managed by Gin. This
     19 // class stores all the Gin-related data that varies per context. Arbitrary data
     20 // can be associated with this class by way of the SupportsUserData methods.
     21 // Instances of this class (and any associated user data) are destroyed before
     22 // the associated v8::Context.
     23 class GIN_EXPORT PerContextData : public base::SupportsUserData {
     24  public:
     25   PerContextData(ContextHolder* context_holder,
     26                  v8::Handle<v8::Context> context);
     27   virtual ~PerContextData();
     28 
     29   // Can return NULL after the ContextHolder has detached from context.
     30   static PerContextData* From(v8::Handle<v8::Context> context);
     31 
     32   // The Runner associated with this context. To execute script in this context,
     33   // please use the appropriate API on Runner.
     34   Runner* runner() const { return runner_; }
     35   void set_runner(Runner* runner) { runner_ = runner; }
     36 
     37   ContextHolder* context_holder() { return context_holder_; }
     38 
     39  private:
     40   ContextHolder* context_holder_;
     41   Runner* runner_;
     42 
     43   DISALLOW_COPY_AND_ASSIGN(PerContextData);
     44 };
     45 
     46 }  // namespace gin
     47 
     48 #endif  // GIN_PER_CONTEXT_DATA_H_
     49