| OLD | NEW | 
| (Empty) |  | 
 |   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 COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 
 |   6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 
 |   7  | 
 |   8 #include "base/basictypes.h" | 
 |   9 #include "base/memory/ref_counted.h" | 
 |  10 #include "base/memory/scoped_ptr.h" | 
 |  11 #include "base/threading/thread_checker.h" | 
 |  12  | 
 |  13 class GURL; | 
 |  14  | 
 |  15 namespace base { | 
 |  16 class FilePath; | 
 |  17 class Time; | 
 |  18 } | 
 |  19  | 
 |  20 namespace sql { | 
 |  21 class Connection; | 
 |  22 } | 
 |  23  | 
 |  24 namespace precache { | 
 |  25  | 
 |  26 class PrecacheURLTable; | 
 |  27  | 
 |  28 // Class that tracks information related to precaching. This class can be | 
 |  29 // constructed or destroyed on any threads, but all other methods must be called | 
 |  30 // on the same thread (e.g. the DB thread). | 
 |  31 class PrecacheDatabase : public base::RefCountedThreadSafe<PrecacheDatabase> { | 
 |  32  public: | 
 |  33   // A PrecacheDatabase can be constructed on any thread. | 
 |  34   PrecacheDatabase(); | 
 |  35  | 
 |  36   // Initializes the precache database, using the specified database file path. | 
 |  37   // Init must be called before any other methods. | 
 |  38   bool Init(const base::FilePath& db_path); | 
 |  39  | 
 |  40   // Deletes precache history from the precache URL table that is more than 60 | 
 |  41   // days older than |current_time|. | 
 |  42   void DeleteExpiredPrecacheHistory(const base::Time& current_time); | 
 |  43  | 
 |  44   // Report precache-related metrics in response to a URL being fetched, where | 
 |  45   // the fetch was motivated by precaching. | 
 |  46   void RecordURLPrecached(const GURL& url, const base::Time& fetch_time, | 
 |  47                           int64 size, bool was_cached); | 
 |  48  | 
 |  49   // Report precache-related metrics in response to a URL being fetched, where | 
 |  50   // the fetch was not motivated by precaching. |is_connection_cellular| | 
 |  51   // indicates whether the current network connection is a cellular network. | 
 |  52   void RecordURLFetched(const GURL& url, const base::Time& fetch_time, | 
 |  53                         int64 size, bool was_cached, | 
 |  54                         bool is_connection_cellular); | 
 |  55  | 
 |  56  private: | 
 |  57   friend class base::RefCountedThreadSafe<PrecacheDatabase>; | 
 |  58   friend class PrecacheDatabaseTest; | 
 |  59  | 
 |  60   ~PrecacheDatabase(); | 
 |  61  | 
 |  62   bool IsDatabaseAccessible() const; | 
 |  63  | 
 |  64   scoped_ptr<sql::Connection> db_; | 
 |  65  | 
 |  66   // Table that keeps track of URLs that are in the cache because of precaching, | 
 |  67   // and wouldn't be in the cache otherwise. | 
 |  68   scoped_ptr<PrecacheURLTable> precache_url_table_; | 
 |  69  | 
 |  70   // ThreadChecker used to ensure that all methods other than the constructor | 
 |  71   // or destructor are called on the same thread. | 
 |  72   base::ThreadChecker thread_checker_; | 
 |  73  | 
 |  74   DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); | 
 |  75 }; | 
 |  76  | 
 |  77 }  // namespace precache | 
 |  78  | 
 |  79 #endif  // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 
| OLD | NEW |