Add a stub __cxa_demangle to disable LLVM's demangler.
[chromium-blink-merge.git] / components / offline_pages / offline_page_model.h
blob9abdad2470267f3d0679b00a9a1f6ce70477d74e
1 // Copyright 2015 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_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
8 #include <vector>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/offline_pages/offline_page_archiver.h"
15 class GURL;
17 namespace offline_pages {
19 struct OfflinePageItem;
20 class OfflinePageMetadataStore;
22 // Service for saving pages offline, storing the offline copy and metadata, and
23 // retrieving them upon request.
25 // Caller of |SavePage|, |DeletePage| and |LoadAllPages| should provide
26 // implementation of |Client|, which will be then used to return a result of
27 // respective calls.
29 // Example usage:
30 // class ModelClient : public OfflinePageModel::Client {
31 // ...
32 // void OnSavePageDone(SavePageResult result) override {
33 // // handles errors or completes the save.
34 // }
35 // const GURL& url() const { return url_; }
36 // private:
37 // GURL url_;
38 // };
40 // scoped_ptr<ModelClient> client(new ModelClient());
41 // model->SavePage(client->url(), client);
43 // TODO(fgorski): Things to describe:
44 // * how to cancel requests and what to expect
45 class OfflinePageModel : public KeyedService,
46 public OfflinePageArchiver::Client {
47 public:
48 // Interface for clients of OfflinePageModel. Methods on the model accepting
49 // a Client pointer as a parameter will return their results using one of the
50 // methods on the Client interface.
51 class Client {
52 // Result of deleting an offline page.
53 enum DeletePageResult {
54 DELETE_PAGE_SUCCESS,
55 DELETE_PAGE_CANCELLED,
56 DELETE_PAGE_DB_FAILURE,
57 DELETE_PAGE_DOES_NOT_EXIST,
60 // Result of loading all pages.
61 enum LoadResult {
62 LOAD_SUCCESS,
63 LOAD_CANCELLED,
64 LOAD_DB_FAILURE,
67 // Result of saving a page offline.
68 enum SavePageResult {
69 SAVE_PAGE_SUCCESS,
70 SAVE_PAGE_CANCELLED,
71 SAVE_PAGE_DB_FAILURE,
72 SAVE_PAGE_ALREADY_EXISTS,
75 virtual ~Client() {}
77 // Callback to SavePage call.
78 // TODO(fgorski): Should we return a copy of the record or depend on the
79 // client to call |LoadAllPages| to see things refreshed?
80 virtual void OnSavePageDone(SavePageResult result) = 0;
82 // Callback to DeletePage call.
83 virtual void OnDeletePageDone(DeletePageResult result) = 0;
85 // Callback to LoadAllPages call.
86 virtual void OnLoadAllPagesDone(
87 LoadResult result,
88 const std::vector<OfflinePageItem>& offline_pages) = 0;
91 OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store,
92 OfflinePageArchiver* archiver);
93 ~OfflinePageModel() override;
95 // KeyedService implementation.
96 void Shutdown() override;
98 // OfflinePageArchiver::Client implementation.
99 void OnCreateArchiveDone(OfflinePageArchiver::Request* request,
100 OfflinePageArchiver::ArchiverResult error,
101 const base::FilePath& file_path) override;
103 // Attempts to save a page addressed by |url| offline.
104 void SavePage(const GURL& url, Client* client);
106 // Deletes an offline page related to the passed |url|.
107 void DeletePage(const GURL& url, Client* client);
109 // Loads all of the available offline pages.
110 void LoadAllPages(Client* client);
112 // Methods for testing only:
113 OfflinePageMetadataStore* GetStoreForTesting();
115 private:
116 // Persistent store for offline page metadata.
117 scoped_ptr<OfflinePageMetadataStore> store_;
119 // Offline page archiver. Outlives the model. Owned by the embedder.
120 OfflinePageArchiver* archiver_;
122 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
125 } // namespace offline_pages
127 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_