diff options
author | fgorski <fgorski@chromium.org> | 2015-06-10 00:45:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-10 07:45:46 +0000 |
commit | 2475986c9476407f0cec00d2eb660b480db30aae (patch) | |
tree | 57c2e3ed3eb08b44302eafa6952142196bef3ee6 | |
parent | 4d0ac15c70965c05e6905e5bf144cd8decf768c7 (diff) | |
download | chromium_src-2475986c9476407f0cec00d2eb660b480db30aae.zip chromium_src-2475986c9476407f0cec00d2eb660b480db30aae.tar.gz chromium_src-2475986c9476407f0cec00d2eb660b480db30aae.tar.bz2 |
[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}
-rw-r--r-- | components/BUILD.gn | 1 | ||||
-rw-r--r-- | components/components_tests.gyp | 5 | ||||
-rw-r--r-- | components/offline_pages.gypi | 2 | ||||
-rw-r--r-- | components/offline_pages/BUILD.gn | 16 | ||||
-rw-r--r-- | components/offline_pages/offline_page_metadata_store.cc | 15 | ||||
-rw-r--r-- | components/offline_pages/offline_page_metadata_store.h | 48 | ||||
-rw-r--r-- | components/offline_pages/offline_page_model.cc | 8 | ||||
-rw-r--r-- | components/offline_pages/offline_page_model.h | 10 | ||||
-rw-r--r-- | components/offline_pages/offline_page_model_unittest.cc | 68 |
9 files changed, 170 insertions, 3 deletions
diff --git a/components/BUILD.gn b/components/BUILD.gn index 52379bf..8b26bd5 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -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", diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 303f10d..1cdfd6e 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -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', diff --git a/components/offline_pages.gypi b/components/offline_pages.gypi index 4afb2fc..3f217ed 100644 --- a/components/offline_pages.gypi +++ b/components/offline_pages.gypi @@ -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', ], }, ], diff --git a/components/offline_pages/BUILD.gn b/components/offline_pages/BUILD.gn index 17c32e9..e4de8cc 100644 --- a/components/offline_pages/BUILD.gn +++ b/components/offline_pages/BUILD.gn @@ -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", + ] +} diff --git a/components/offline_pages/offline_page_metadata_store.cc b/components/offline_pages/offline_page_metadata_store.cc new file mode 100644 index 0000000..e5cf058 --- /dev/null +++ b/components/offline_pages/offline_page_metadata_store.cc @@ -0,0 +1,15 @@ +// 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 diff --git a/components/offline_pages/offline_page_metadata_store.h b/components/offline_pages/offline_page_metadata_store.h new file mode 100644 index 0000000..6d5cc07 --- /dev/null +++ b/components/offline_pages/offline_page_metadata_store.h @@ -0,0 +1,48 @@ +// 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_ diff --git a/components/offline_pages/offline_page_model.cc b/components/offline_pages/offline_page_model.cc index afb51c9..5fd54d0 100644 --- a/components/offline_pages/offline_page_model.cc +++ b/components/offline_pages/offline_page_model.cc @@ -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 diff --git a/components/offline_pages/offline_page_model.h b/components/offline_pages/offline_page_model.h index 7e57a14..d32ace1 100644 --- a/components/offline_pages/offline_page_model.h +++ b/components/offline_pages/offline_page_model.h @@ -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); }; diff --git a/components/offline_pages/offline_page_model_unittest.cc b/components/offline_pages/offline_page_model_unittest.cc new file mode 100644 index 0000000..b6119ef --- /dev/null +++ b/components/offline_pages/offline_page_model_unittest.cc @@ -0,0 +1,68 @@ +// 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 |