Commit 2475986c authored by fgorski's avatar fgorski Committed by Commit bot

[Offline] Creates metadata store interface for offline pages

Offline pages metadata store:
* Creates interface for the store
* The following actions are available on the store:
  - AddOfflinePage,
  - RemoveOfflinePage,
  - Load,
* Updates to the components_unittests to include offline
  pages

BUG=491352

Review URL: https://codereview.chromium.org/1160283003

Cr-Commit-Position: refs/heads/master@{#333697}
parent 4d0ac15c
......@@ -289,6 +289,7 @@ test("components_unittests") {
"//components/login:unit_tests",
"//components/metrics:unit_tests",
"//components/mime_util:unit_tests",
"//components/offline_pages:unit_tests",
"//components/omnibox:unit_tests",
"//components/packed_ct_ev_whitelist:unit_tests",
"//components/undo:unit_tests",
......
......@@ -330,6 +330,9 @@
'network_time_unittest_sources': [
'network_time/network_time_tracker_unittest.cc',
],
'offline_page_unittest_sources': [
'offline_pages/offline_page_model_unittest.cc',
],
'omnibox_unittest_sources': [
'omnibox/answers_cache_unittest.cc',
'omnibox/autocomplete_input_unittest.cc',
......@@ -694,6 +697,7 @@
'<@(metrics_unittest_sources)',
'<@(mime_util_unittest_sources)',
'<@(network_time_unittest_sources)',
'<@(offline_page_unittest_sources)',
'<@(omnibox_unittest_sources)',
'<@(os_crypt_unittest_sources)',
'<@(packed_ct_ev_whitelist_unittest_sources)',
......@@ -796,6 +800,7 @@
'components.gyp:metrics_profiler',
'components.gyp:metrics_test_support',
'components.gyp:network_time',
'components.gyp:offline_pages',
'components.gyp:omnibox',
'components.gyp:omnibox_test_support',
'components.gyp:os_crypt',
......
......@@ -22,6 +22,8 @@
'offline_pages/offline_page_item.h',
'offline_pages/offline_page_model.cc',
'offline_pages/offline_page_model.h',
'offline_pages/offline_page_metadata_store.cc',
'offline_pages/offline_page_metadata_store.h',
],
},
],
......
......@@ -2,11 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# GYP: //components/offline_pages.gypi:offline_pages'
# GYP: //components/offline_pages.gypi:offline_pages
static_library("offline_pages") {
sources = [
"offline_page_item.cc",
"offline_page_item.h",
"offline_page_metadata_store.cc",
"offline_page_metadata_store.h",
"offline_page_model.cc",
"offline_page_model.h",
]
......@@ -18,3 +20,15 @@ static_library("offline_pages") {
"//url",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"offline_page_model_unittest.cc",
]
deps = [
":offline_pages",
"//testing/gtest",
]
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_pages/offline_page_metadata_store.h"
namespace offline_pages {
OfflinePageMetadataStore::OfflinePageMetadataStore() {
}
OfflinePageMetadataStore::~OfflinePageMetadataStore() {
}
} // namespace offline_pages
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_
#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_
#include <vector>
#include "base/callback.h"
class GURL;
namespace offline_pages {
struct OfflinePageItem;
// OfflinePageMetadataStore keeps metadata for the offline pages.
// Ability to create multiple instances of the store as well as behavior of
// asynchronous operations when the object is being destroyed, before such
// operation finishes will depend on implementation. It should be possbile to
// issue multiple asynchronous operations in parallel.
class OfflinePageMetadataStore {
public:
typedef base::Callback<void(bool, const std::vector<OfflinePageItem>&)>
LoadCallback;
typedef base::Callback<void(bool)> UpdateCallback;
OfflinePageMetadataStore();
virtual ~OfflinePageMetadataStore();
// Get all of the offline pages from the store.
virtual void Load(const LoadCallback& callback) = 0;
// Asynchronously adds offline page metadata to the store for a given URL.
// Result of the update is passed in callback.
virtual void AddOfflinePage(const OfflinePageItem& offline_page,
const UpdateCallback& callback) = 0;
// Asynchronously removes offline page metadata from the store.
// Result of the update is passed in callback.
virtual void RemoveOfflinePage(const GURL& page_url,
const UpdateCallback& callback) = 0;
};
} // namespace offline_pages
#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_
......@@ -6,11 +6,13 @@
#include "base/logging.h"
#include "components/offline_pages/offline_page_item.h"
#include "components/offline_pages/offline_page_metadata_store.h"
#include "url/gurl.h"
namespace offline_pages {
OfflinePageModel::OfflinePageModel() {
OfflinePageModel::OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store)
: store_(store.Pass()) {
}
OfflinePageModel::~OfflinePageModel() {
......@@ -29,4 +31,8 @@ std::vector<OfflinePageItem> OfflinePageModel::GetAllOfflinePages() {
return std::vector<OfflinePageItem>();
}
OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() {
return store_.get();
}
} // namespace offline_pages
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
class GURL;
......@@ -15,12 +16,13 @@ class GURL;
namespace offline_pages {
struct OfflinePageItem;
class OfflinePageMetadataStore;
// Serivce for saving pages offline, storing the offline copy and metadata, and
// retrieving them upon request.
class OfflinePageModel : public KeyedService {
public:
OfflinePageModel();
explicit OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store);
~OfflinePageModel() override;
// KeyedService:
......@@ -32,7 +34,13 @@ class OfflinePageModel : public KeyedService {
// Gets a set of all offline pages metadata.
std::vector<OfflinePageItem> GetAllOfflinePages();
// Methods for testing only:
OfflinePageMetadataStore* GetStoreForTesting();
private:
// Persistent store for offline page metadata.
scoped_ptr<OfflinePageMetadataStore> store_;
DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
};
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_pages/offline_page_model.h"
#include "components/offline_pages/offline_page_metadata_store.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace offline_pages {
namespace {
class OfflinePageTestStore : public OfflinePageMetadataStore {
public:
~OfflinePageTestStore() override;
// OfflinePageMetadataStore overrides:
void Load(const LoadCallback& callback) override;
void AddOfflinePage(const OfflinePageItem& offline_page,
const UpdateCallback& callback) override;
void RemoveOfflinePage(const GURL& page_url,
const UpdateCallback& callback) override;
};
OfflinePageTestStore::~OfflinePageTestStore() {
}
void OfflinePageTestStore::Load(const LoadCallback& callback) {
}
void OfflinePageTestStore::AddOfflinePage(const OfflinePageItem& offline_page,
const UpdateCallback& callback) {
}
void OfflinePageTestStore::RemoveOfflinePage(const GURL& page_url,
const UpdateCallback& callback) {
}
class OfflinePageModelTest : public testing::Test {
public:
OfflinePageModelTest();
~OfflinePageModelTest() override;
scoped_ptr<OfflinePageMetadataStore> BuildStore();
};
OfflinePageModelTest::OfflinePageModelTest() {
}
OfflinePageModelTest::~OfflinePageModelTest() {
}
scoped_ptr<OfflinePageMetadataStore> OfflinePageModelTest::BuildStore() {
return scoped_ptr<OfflinePageMetadataStore>(new OfflinePageTestStore());
}
TEST_F(OfflinePageModelTest, Initialize) {
scoped_ptr<OfflinePageMetadataStore> store = BuildStore();
OfflinePageMetadataStore* store_ptr = store.get();
OfflinePageModel model(store.Pass());
EXPECT_EQ(store_ptr, model.GetStoreForTesting());
}
} // namespace
} // namespace offline_pages
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment