summaryrefslogtreecommitdiffstats
path: root/components/offline_pages/offline_page_model.h
diff options
context:
space:
mode:
authorfgorski <fgorski@chromium.org>2015-07-14 17:28:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-15 00:29:02 +0000
commit8b49cda8a1c4430599292ce3e006aee12a2ac559 (patch)
tree07ca36f249792ed61a2f09f2139426816c762b95 /components/offline_pages/offline_page_model.h
parent29770eb5442ccf1c2765273330102690b76461c6 (diff)
downloadchromium_src-8b49cda8a1c4430599292ce3e006aee12a2ac559.zip
chromium_src-8b49cda8a1c4430599292ce3e006aee12a2ac559.tar.gz
chromium_src-8b49cda8a1c4430599292ce3e006aee12a2ac559.tar.bz2
Offline page model save page functionality
* Implementation of the Save functionality for OfflinePageModel. * Implementation of tests for save functionality. * Handling of multiple requests at the same time. BUG=491352 R=jianli@chromium.org,dimich@chromium.org Review URL: https://codereview.chromium.org/1232093004 Cr-Commit-Position: refs/heads/master@{#338783}
Diffstat (limited to 'components/offline_pages/offline_page_model.h')
-rw-r--r--components/offline_pages/offline_page_model.h65
1 files changed, 49 insertions, 16 deletions
diff --git a/components/offline_pages/offline_page_model.h b/components/offline_pages/offline_page_model.h
index c31434e..c7fdb01 100644
--- a/components/offline_pages/offline_page_model.h
+++ b/components/offline_pages/offline_page_model.h
@@ -5,15 +5,20 @@
#ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
-#include <vector>
-
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/offline_pages/offline_page_archiver.h"
class GURL;
+namespace base {
+class SingleThreadTaskRunner;
+} // namespace base
+
namespace offline_pages {
struct OfflinePageItem;
@@ -48,8 +53,9 @@ class OfflinePageModel : public KeyedService {
// a Client pointer as a parameter will return their results using one of the
// methods on the Client interface.
class Client {
+ public:
// Result of deleting an offline page.
- enum DeletePageResult {
+ enum class DeletePageResult {
DELETE_PAGE_SUCCESS,
DELETE_PAGE_CANCELLED,
DELETE_PAGE_DB_FAILURE,
@@ -57,18 +63,21 @@ class OfflinePageModel : public KeyedService {
};
// Result of loading all pages.
- enum LoadResult {
+ enum class LoadResult {
LOAD_SUCCESS,
LOAD_CANCELLED,
LOAD_DB_FAILURE,
};
// Result of saving a page offline.
- enum SavePageResult {
- SAVE_PAGE_SUCCESS,
- SAVE_PAGE_CANCELLED,
- SAVE_PAGE_DB_FAILURE,
- SAVE_PAGE_ALREADY_EXISTS,
+ enum class SavePageResult {
+ SUCCESS,
+ CANCELLED,
+ DEVICE_FULL,
+ CONTENT_UNAVAILABLE,
+ ARCHIVE_CREATION_FAILED,
+ DB_FAILURE,
+ ALREADY_EXISTS,
};
virtual ~Client() {}
@@ -84,18 +93,21 @@ class OfflinePageModel : public KeyedService {
// Callback to LoadAllPages call.
virtual void OnLoadAllPagesDone(
LoadResult result,
- const std::vector<OfflinePageItem>& offline_pages) = 0;
+ std::vector<OfflinePageItem>* offline_pages) = 0;
};
- OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store,
- OfflinePageArchiver* archiver);
+ OfflinePageModel(
+ scoped_ptr<OfflinePageMetadataStore> store,
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
~OfflinePageModel() override;
// KeyedService implementation.
void Shutdown() override;
// Attempts to save a page addressed by |url| offline.
- void SavePage(const GURL& url, Client* client);
+ void SavePage(const GURL& url,
+ scoped_ptr<OfflinePageArchiver> archiver,
+ const base::WeakPtr<Client>& client);
// Deletes an offline page related to the passed |url|.
void DeletePage(const GURL& url, Client* client);
@@ -107,16 +119,37 @@ class OfflinePageModel : public KeyedService {
OfflinePageMetadataStore* GetStoreForTesting();
private:
+ typedef ScopedVector<OfflinePageArchiver> PendingArchivers;
+
// OfflinePageArchiver callback.
- void OnCreateArchiveDone(OfflinePageArchiver::ArchiverResult result,
+ void OnCreateArchiveDone(const GURL& requested_url,
+ const base::WeakPtr<Client>& client,
+ OfflinePageArchiver* archiver,
+ OfflinePageArchiver::ArchiverResult result,
+ const GURL& url,
+ const base::string16& title,
const base::FilePath& file_path,
int64 file_size);
+ // OfflinePageMetadataStore callbacks.
+ void OnAddOfflinePageDone(OfflinePageArchiver* archiver,
+ const base::WeakPtr<Client>& client,
+ bool success);
+
+ void InformSavePageDone(const base::WeakPtr<Client>& client,
+ Client::SavePageResult result);
+
+ void DeletePendingArchiver(OfflinePageArchiver* archiver);
+
// Persistent store for offline page metadata.
scoped_ptr<OfflinePageMetadataStore> store_;
- // Offline page archiver. Outlives the model. Owned by the embedder.
- OfflinePageArchiver* archiver_;
+ // Pending archivers owned by this model.
+ PendingArchivers pending_archivers_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
};