Remove unused did_first_* fields from InternalDocumentStateData.
[chromium-blink-merge.git] / components / webdata / common / web_data_service_base.h
blobde5a3e9dae5a929675763f417ff5a1a91ce900dc
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_
8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/ref_counted_delete_on_message_loop.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/webdata/common/webdata_export.h"
14 #include "sql/init_status.h"
16 class WebDatabase;
17 class WebDatabaseService;
18 class WebDatabaseTable;
20 namespace base {
21 // TODO(skyostil): Migrate to SingleThreadTaskRunner (crbug.com/465354).
22 class SingleThreadTaskRunner;
23 class Thread;
26 // Base for WebDataService class hierarchy.
27 // WebDataServiceBase is destroyed on the UI thread.
28 class WEBDATA_EXPORT WebDataServiceBase
29 : public base::RefCountedDeleteOnMessageLoop<WebDataServiceBase> {
30 public:
31 // All requests return an opaque handle of the following type.
32 typedef int Handle;
34 // Users of this class may provide a callback to handle errors
35 // (e.g. by showing a UI). The callback is called only on error, and
36 // takes a single parameter, the sql::InitStatus value from trying
37 // to open the database.
38 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback?
39 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback;
41 typedef base::Closure DBLoadedCallback;
43 // |callback| will only be invoked on error, and only if
44 // |callback.is_null()| evaluates to false.
46 // The ownership of |wdbs| is shared, with the primary owner being the
47 // WebDataServiceWrapper, and secondary owners being subclasses of
48 // WebDataServiceBase, which receive |wdbs| upon construction. The
49 // WebDataServiceWrapper handles the initializing and shutting down and of
50 // the |wdbs| object.
51 // WebDataServiceBase is destroyed on |ui_thread|.
52 WebDataServiceBase(
53 scoped_refptr<WebDatabaseService> wdbs,
54 const ProfileErrorCallback& callback,
55 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread);
57 // Cancel any pending request. You need to call this method if your
58 // WebDataServiceConsumer is about to be deleted.
59 virtual void CancelRequest(Handle h);
61 // Shutdown the web data service. The service can no longer be used after this
62 // call.
63 virtual void ShutdownOnUIThread();
65 // Initializes the web data service.
66 virtual void Init();
68 // Unloads the database and shuts down service.
69 void ShutdownDatabase();
71 // Register a callback to be notified that the database has loaded. Multiple
72 // callbacks may be registered, and each will be called at most once
73 // (following a successful database load), then cleared.
74 // Note: if the database load is already complete, then the callback will NOT
75 // be stored or called.
76 virtual void RegisterDBLoadedCallback(const DBLoadedCallback& callback);
78 // Returns true if the database load has completetd successfully, and
79 // ShutdownOnUIThread has not yet been called.
80 virtual bool IsDatabaseLoaded();
82 // Returns a pointer to the DB (used by SyncableServices). May return NULL if
83 // the database is not loaded or otherwise unavailable. Must be called on
84 // DBThread.
85 virtual WebDatabase* GetDatabase();
87 protected:
88 friend class base::RefCountedDeleteOnMessageLoop<WebDataServiceBase>;
89 friend class base::DeleteHelper<WebDataServiceBase>;
91 virtual ~WebDataServiceBase();
93 // Our database service.
94 scoped_refptr<WebDatabaseService> wdbs_;
96 private:
97 ProfileErrorCallback profile_error_callback_;
99 DISALLOW_COPY_AND_ASSIGN(WebDataServiceBase);
102 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_