Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
central_controller_callback.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc.
16 
17 #ifndef PAGESPEED_CONTROLLER_CENTRAL_CONTROLLER_CALLBACK_H_
18 #define PAGESPEED_CONTROLLER_CENTRAL_CONTROLLER_CALLBACK_H_
19 
20 #include "base/logging.h"
25 
26 namespace net_instaweb {
27 
58 
59 template <typename TransactionContext>
61  public:
62  virtual ~CentralControllerCallback();
63 
68  void SetTransactionContext(TransactionContext* ctx);
69 
70  protected:
71  explicit CentralControllerCallback(Sequence* sequence);
72 
76  virtual void Run() ;
77  virtual void Cancel() ;
78 
79  private:
82  virtual void RunImpl(scoped_ptr<TransactionContext>* context) = 0;
83  virtual void CancelImpl() = 0;
84 
86  void RunAfterRequeue();
87  void CancelAfterRequeue();
88 
89  Sequence* sequence_;
91 
92 
93 };
94 
95 template <typename TransactionContext>
97  Sequence* sequence) : sequence_(sequence) {
99 }
100 
101 template <typename TransactionContext>
102 CentralControllerCallback<TransactionContext>::~CentralControllerCallback() { }
103 
104 template <typename TransactionContext>
106  CHECK(context_ != NULL);
109  sequence_->Add(MakeFunction(this,
112 }
113 
114 template <typename TransactionContext>
118  sequence_->Add(MakeFunction(this,
121 }
122 
123 template <typename TransactionContext>
126  CHECK(context_ != NULL);
127  RunImpl(&context_);
128  delete this;
129 }
130 
131 template <typename TransactionContext>
132 void CentralControllerCallback<TransactionContext>::CancelAfterRequeue() {
133  CancelImpl();
134  delete this;
135 }
136 
137 template <typename TransactionContext>
139  TransactionContext* context) {
140  CHECK(context_ == NULL);
141  context_.reset(context);
142 }
143 
144 }
145 
146 #endif
Function * MakeFunction(C *object, void(C::*run)())
Makes a Function* that calls a 0-arg class method.
Definition: function.h:291
virtual void Run()
Definition: central_controller_callback.h:105
virtual void Cancel()
Definition: central_controller_callback.h:115
void SetTransactionContext(TransactionContext *ctx)
Definition: central_controller_callback.h:138
Definition: sequence.h:33
Definition: function.h:47
void set_delete_after_callback(bool x)
Definition: function.h:80
Definition: central_controller_callback.h:60