| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PREDICTORS_PREDICTOR_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_PREDICTORS_PREDICTOR_DATABASE_H_ |
| 6 #define CHROME_BROWSER_PREDICTORS_PREDICTOR_DATABASE_H_ | 6 #define CHROME_BROWSER_PREDICTORS_PREDICTOR_DATABASE_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/profiles/profile_keyed_service.h" | 11 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 10 | 12 |
| 11 class Profile; | |
| 12 | |
| 13 namespace sql { | 13 namespace sql { |
| 14 class Connection; | 14 class Connection; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace predictors { | 17 namespace predictors { |
| 18 | 18 |
| 19 class AutocompleteActionPredictorTable; | 19 class AutocompleteActionPredictorTable; |
| 20 class PredictorDatabaseInternal; | 20 class PredictorDatabaseInternal; |
| 21 class ResourcePrefetchPredictorTables; | 21 class ResourcePrefetchPredictorTables; |
| 22 | 22 |
| 23 class PredictorDatabase : public ProfileKeyedService { | 23 // Refcounted as it is created, initialized and destroyed on a different thread |
| 24 // to the DB thread that is required for all methods performing database access. |
| 25 class PredictorDatabase |
| 26 : public base::RefCountedThreadSafe<PredictorDatabase> { |
| 24 public: | 27 public: |
| 25 explicit PredictorDatabase(Profile* profile); | 28 explicit PredictorDatabase(const FilePath& path, |
| 29 bool is_resource_prefetch_predictor_enabled); |
| 26 virtual ~PredictorDatabase(); | 30 virtual ~PredictorDatabase(); |
| 27 | 31 |
| 28 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table(); | 32 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table(); |
| 29 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables(); | 33 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables(); |
| 30 | 34 |
| 35 // Cancels pending DB transactions. Should only be called on the UI thread. |
| 36 void SetCancelled(); |
| 37 |
| 31 // Used for testing. | 38 // Used for testing. |
| 32 sql::Connection* GetDatabase(); | 39 sql::Connection* GetDatabase(); |
| 33 | 40 |
| 34 private: | 41 private: |
| 35 // ProfileKeyedService | 42 friend class base::RefCountedThreadSafe<PredictorDatabase>; |
| 36 virtual void Shutdown() OVERRIDE; | |
| 37 | 43 |
| 38 scoped_refptr<PredictorDatabaseInternal> db_; | 44 // Opens the database file. Separated from the constructor to ease |
| 45 // construction/destruction of this object on one thread but database access |
| 46 // on the DB thread. |
| 47 void Initialize(); |
| 48 void LogDatabaseStats(); // DB Thread. |
| 49 |
| 50 FilePath db_path_; |
| 51 bool is_resource_prefetch_predictor_enabled_; |
| 52 scoped_ptr<sql::Connection> db_; |
| 53 |
| 54 // TODO(shishir): These tables may not need to be refcounted. Maybe move them |
| 55 // to using a WeakPtr instead. |
| 56 scoped_refptr<AutocompleteActionPredictorTable> autocomplete_table_; |
| 57 scoped_refptr<ResourcePrefetchPredictorTables> resource_prefetch_tables_; |
| 39 | 58 |
| 40 DISALLOW_COPY_AND_ASSIGN(PredictorDatabase); | 59 DISALLOW_COPY_AND_ASSIGN(PredictorDatabase); |
| 41 }; | 60 }; |
| 42 | 61 |
| 43 } // namespace predictors | 62 } // namespace predictors |
| 44 | 63 |
| 45 #endif // CHROME_BROWSER_PREDICTORS_PREDICTOR_DATABASE_H_ | 64 #endif // CHROME_BROWSER_PREDICTORS_PREDICTOR_DATABASE_H_ |
| OLD | NEW |