Page Speed Optimization Libraries  1.5.27.2
net/instaweb/util/public/client_state.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_CLIENT_STATE_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_CLIENT_STATE_H_
00021 
00022 #include "net/instaweb/util/public/abstract_client_state.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/scoped_ptr.h"
00025 #include "net/instaweb/util/public/string.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027 
00028 #include "testing/gtest/include/gtest/gtest_prod.h"
00029 
00030 namespace net_instaweb {
00031 
00032 class ClientStateMsg;
00033 class PropertyCache;
00034 class PropertyPage;
00035 class Timer;
00036 
00041 class ClientState : public AbstractClientState {
00042  public:
00044   static const char kClientStateCohort[];
00046   static const char kClientStatePropertyValue[];
00048   static const uint32 kClientStateMaxUrls;
00050   static const int64 kClientStateExpiryTimeThresholdMs;
00051 
00052   ClientState();
00053   virtual ~ClientState();
00054 
00055   virtual bool InCache(const GoogleString& url);
00056   virtual void Set(const GoogleString& url, int64 expire_ms);
00057   virtual void Clear();
00058   virtual const GoogleString& ClientId() const { return client_id_; }
00059   virtual bool InitFromPropertyCache(
00060       const GoogleString& client_id,
00061       PropertyCache* property_cache,
00062       PropertyPage* property_page,
00063       Timer* timer);
00064   virtual void WriteBackToPropertyCache();
00065 
00066  private:
00068   void Pack(ClientStateMsg* proto);
00071   bool Unpack(const ClientStateMsg& proto);
00072 
00074   GoogleString client_id_;
00076   Timer* timer_;
00078   int64 create_time_ms_;
00082   scoped_ptr<PropertyPage> property_page_;
00083   PropertyCache* property_cache_;
00085   StringVector recent_urls_;
00086 
00087   friend class ClientStateTest;
00088   FRIEND_TEST(ClientStateTest, PackUnpackWorks);
00089   FRIEND_TEST(ClientStateTest, PropertyCacheWorks);
00090 
00091   DISALLOW_COPY_AND_ASSIGN(ClientState);
00092 };
00093 
00094 }  
00095 
00096 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_CLIENT_STATE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines