ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / components / offline_pages / offline_page_model.h
blob8716a0b8f6546034ee562a67547225596a754d49
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/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/offline_pages/offline_page_archiver.h"
19 class GURL;
21 namespace offline_pages {
23 struct OfflinePageItem;
24 class OfflinePageMetadataStore;
26 // Service for saving pages offline, storing the offline copy and metadata, and
27 // retrieving them upon request.
29 // Caller of |SavePage|, |DeletePage| and |LoadAllPages| should provide
30 // implementation of |Client|, which will be then used to return a result of
31 // respective calls.
33 // Example usage:
34 // class ArchiverImpl : public OfflinePageArchiver {
35 // // This is a class that knows how to create archiver
36 // void CreateArchiver(...) override;
37 // ...
38 // }
40 // // In code using the OfflinePagesModel to save a page:
41 // scoped_ptr<ArchiverImpl> archiver(new ArchiverImpl());
42 // // Callback is of type SavePageCallback.
43 // model->SavePage(url, archiver.Pass(), callback);
45 // TODO(fgorski): Things to describe:
46 // * how to cancel requests and what to expect
47 class OfflinePageModel : public KeyedService {
48 public:
49 // Result of saving a page offline.
50 enum class SavePageResult {
51 SUCCESS,
52 CANCELLED,
53 DEVICE_FULL,
54 CONTENT_UNAVAILABLE,
55 ARCHIVE_CREATION_FAILED,
56 STORE_FAILURE,
57 ALREADY_EXISTS,
60 // Result of deleting an offline page.
61 enum class DeletePageResult {
62 SUCCESS,
63 CANCELLED,
64 STORE_FAILURE,
65 NOT_FOUND,
68 // Result of loading all pages.
69 enum class LoadResult {
70 SUCCESS,
71 CANCELLED,
72 STORE_FAILURE,
75 typedef base::Callback<void(SavePageResult)> SavePageCallback;
76 typedef base::Callback<void(DeletePageResult)> DeletePageCallback;
77 typedef base::Callback<void(LoadResult, const std::vector<OfflinePageItem>&)>
78 LoadAllPagesCallback;
80 explicit OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store);
81 ~OfflinePageModel() override;
83 // KeyedService implementation.
84 void Shutdown() override;
86 // Attempts to save a page addressed by |url| offline.
87 void SavePage(const GURL& url,
88 scoped_ptr<OfflinePageArchiver> archiver,
89 const SavePageCallback& callback);
91 // Deletes an offline page related to the passed |url|.
92 void DeletePage(const GURL& url, const DeletePageCallback& callback);
94 // Loads all of the available offline pages.
95 void LoadAllPages(const LoadAllPagesCallback& callback);
97 // Methods for testing only:
98 OfflinePageMetadataStore* GetStoreForTesting();
100 private:
101 typedef ScopedVector<OfflinePageArchiver> PendingArchivers;
103 // OfflinePageArchiver callback.
104 void OnCreateArchiveDone(const GURL& requested_url,
105 const SavePageCallback& callback,
106 OfflinePageArchiver* archiver,
107 OfflinePageArchiver::ArchiverResult result,
108 const GURL& url,
109 const base::string16& title,
110 const base::FilePath& file_path,
111 int64 file_size);
113 // OfflinePageMetadataStore callbacks.
114 void OnAddOfflinePageDone(OfflinePageArchiver* archiver,
115 const SavePageCallback& callback,
116 bool success);
117 void OnLoadDone(const LoadAllPagesCallback& callback,
118 bool success,
119 const std::vector<OfflinePageItem>& offline_pages);
121 void InformSavePageDone(const SavePageCallback& callback,
122 SavePageResult result);
124 void DeletePendingArchiver(OfflinePageArchiver* archiver);
126 // Persistent store for offline page metadata.
127 scoped_ptr<OfflinePageMetadataStore> store_;
129 // Pending archivers owned by this model.
130 PendingArchivers pending_archivers_;
132 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
134 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
137 } // namespace offline_pages
139 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_