| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 68   class Delegate { | 68   class Delegate { | 
| 69    protected: | 69    protected: | 
| 70     friend class ActivityDatabase; | 70     friend class ActivityDatabase; | 
| 71 | 71 | 
| 72     // A Delegate is never directly deleted; it should instead delete itself | 72     // A Delegate is never directly deleted; it should instead delete itself | 
| 73     // after any final cleanup when OnDatabaseClose() is invoked. | 73     // after any final cleanup when OnDatabaseClose() is invoked. | 
| 74     virtual ~Delegate() {} | 74     virtual ~Delegate() {} | 
| 75 | 75 | 
| 76     // Initializes the database schema; this gives a policy a chance to create | 76     // Initializes the database schema; this gives a policy a chance to create | 
| 77     // or update database tables as needed.  Should return true on success. | 77     // or update database tables as needed.  Should return true on success. | 
|  | 78     // Will be called from within a database transaction. | 
| 78     virtual bool InitDatabase(sql::Connection* db) = 0; | 79     virtual bool InitDatabase(sql::Connection* db) = 0; | 
| 79 | 80 | 
| 80     // Requests that the policy flush any pending actions to the database. | 81     // Requests that the policy flush any pending actions to the database. | 
| 81     // Should return true on success or false on a database error. | 82     // Should return true on success or false on a database error.  Will not be | 
|  | 83     // called from a transaction (the implementation may wish to use a | 
|  | 84     // transaction for the flush). | 
| 82     virtual bool FlushDatabase(sql::Connection* db) = 0; | 85     virtual bool FlushDatabase(sql::Connection* db) = 0; | 
| 83 | 86 | 
| 84     // Called if the database encounters a permanent error; the policy should | 87     // Called if the database encounters a permanent error; the policy should | 
| 85     // not expect to make any future writes to the database and may want to | 88     // not expect to make any future writes to the database and may want to | 
| 86     // discard any queued data. | 89     // discard any queued data. | 
| 87     virtual void OnDatabaseFailure() = 0; | 90     virtual void OnDatabaseFailure() = 0; | 
| 88 | 91 | 
| 89     // Called by ActivityDatabase just before the ActivityDatabase object is | 92     // Called by ActivityDatabase just before the ActivityDatabase object is | 
| 90     // deleted.  The database will make no further callbacks after invoking | 93     // deleted.  The database will make no further callbacks after invoking | 
| 91     // this method, so it is an appropriate time for the policy to delete | 94     // this method, so it is an appropriate time for the policy to delete | 
| 92     // itself. | 95     // itself. | 
| 93     virtual void OnDatabaseClose() = 0; | 96     virtual void OnDatabaseClose() = 0; | 
| 94   }; | 97   }; | 
| 95 | 98 | 
|  | 99   // Value to be passed to AdviseFlush below to force a database flush. | 
|  | 100   static const int kFlushImmediately = -1; | 
|  | 101 | 
| 96   // Need to call Init to actually use the ActivityDatabase.  The Delegate | 102   // Need to call Init to actually use the ActivityDatabase.  The Delegate | 
| 97   // provides hooks for an ActivityLogPolicy to control the database schema and | 103   // provides hooks for an ActivityLogPolicy to control the database schema and | 
| 98   // reads/writes. | 104   // reads/writes. | 
| 99   explicit ActivityDatabase(Delegate* delegate); | 105   explicit ActivityDatabase(Delegate* delegate); | 
| 100 | 106 | 
| 101   // Opens the DB.  This invokes OnDatabaseInit in the delegate to create or | 107   // Opens the DB.  This invokes OnDatabaseInit in the delegate to create or | 
| 102   // update the database schema if needed. | 108   // update the database schema if needed. | 
| 103   void Init(const base::FilePath& db_name); | 109   void Init(const base::FilePath& db_name); | 
| 104 | 110 | 
| 105   // An ActivityLogPolicy should call this to kill the ActivityDatabase. | 111   // An ActivityLogPolicy should call this to kill the ActivityDatabase. | 
| 106   void Close(); | 112   void Close(); | 
| 107 | 113 | 
| 108   // Inform the database that there may be additional data which could be | 114   // Inform the database that there may be additional data which could be | 
| 109   // written out. | 115   // written out.  The size parameter should indicate (approximately) how many | 
| 110   // TODO(mvrable): Add a method to force a database flush, or perhaps pass | 116   // records are queued to be written; the database may use this information to | 
| 111   // hints to the database about how much data is queued up so the database can | 117   // schedule a flush early if too much data is queueing up.  A value of | 
| 112   // flush before the timeout if there is a large amount of data? | 118   // kFlushImmediately will force an immediate call into | 
| 113   void NotifyAction(); | 119   // Delegate::FlushDatabase(); otherwise, it is up to the database to | 
|  | 120   // determine when to flush. | 
|  | 121   void AdviseFlush(int size); | 
| 114 | 122 | 
| 115   // Turns off batch I/O writing mode. This should only be used in unit tests, | 123   // Turns off batch I/O writing mode. This should only be used in unit tests, | 
| 116   // browser tests, or in our special --enable-extension-activity-log-testing | 124   // browser tests, or in our special --enable-extension-activity-log-testing | 
| 117   // policy state. | 125   // policy state. | 
| 118   void SetBatchModeForTesting(bool batch_mode); | 126   void SetBatchModeForTesting(bool batch_mode); | 
| 119 | 127 | 
| 120   bool is_db_valid() const { return valid_db_; } | 128   bool is_db_valid() const { return valid_db_; } | 
| 121 | 129 | 
| 122   // A helper method for initializing or upgrading a database table.  The | 130   // A helper method for initializing or upgrading a database table.  The | 
| 123   // content_fields array should list the names of all of the columns in the | 131   // content_fields array should list the names of all of the columns in the | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 181   sql::Connection db_; | 189   sql::Connection db_; | 
| 182   bool valid_db_; | 190   bool valid_db_; | 
| 183   bool batch_mode_; | 191   bool batch_mode_; | 
| 184   base::RepeatingTimer<ActivityDatabase> timer_; | 192   base::RepeatingTimer<ActivityDatabase> timer_; | 
| 185   bool already_closed_; | 193   bool already_closed_; | 
| 186   bool did_init_; | 194   bool did_init_; | 
| 187 | 195 | 
| 188   friend class ActivityLogDatabasePolicy; | 196   friend class ActivityLogDatabasePolicy; | 
| 189   FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOff); | 197   FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOff); | 
| 190   FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOn); | 198   FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeOn); | 
|  | 199   FRIEND_TEST_ALL_PREFIXES(ActivityDatabaseTest, BatchModeFlush); | 
| 191   DISALLOW_COPY_AND_ASSIGN(ActivityDatabase); | 200   DISALLOW_COPY_AND_ASSIGN(ActivityDatabase); | 
| 192 }; | 201 }; | 
| 193 | 202 | 
| 194 }  // namespace extensions | 203 }  // namespace extensions | 
| 195 #endif  // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 204 #endif  // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ | 
| OLD | NEW | 
|---|