diff options
author | sdefresne <sdefresne@chromium.org> | 2015-06-26 07:05:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-26 14:06:13 +0000 |
commit | 5151eeef7d28b7b89607f05c0170cd6c1c9e24e6 (patch) | |
tree | 765d221e636cf1069ef05ee0e05bdc4e6d3cb76f /ios | |
parent | ba90ff874c7c47a06be9e0554bb70342981fafea (diff) | |
download | chromium_src-5151eeef7d28b7b89607f05c0170cd6c1c9e24e6.zip chromium_src-5151eeef7d28b7b89607f05c0170cd6c1c9e24e6.tar.gz chromium_src-5151eeef7d28b7b89607f05c0170cd6c1c9e24e6.tar.bz2 |
Implement HistoryServiceFactory for iOS
Implement the factory, HistoryClient and HistoryBackendClient for iOS.
BUG=478763
Review URL: https://codereview.chromium.org/1210413003
Cr-Commit-Position: refs/heads/master@{#336365}
Diffstat (limited to 'ios')
18 files changed, 467 insertions, 78 deletions
diff --git a/ios/chrome/browser/DEPS b/ios/chrome/browser/DEPS index 23bcd91..c96f870 100644 --- a/ios/chrome/browser/DEPS +++ b/ios/chrome/browser/DEPS @@ -13,6 +13,7 @@ include_rules = [ "+components/favicon/core", "+components/favicon_base", "+components/history/core/browser", + "+components/history/ios/browser", "+components/infobars/core", "+components/keyed_service/core", "+components/keyed_service/ios", diff --git a/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm b/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm index f9c39f1..2243a01 100644 --- a/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm +++ b/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm @@ -10,6 +10,7 @@ #include "ios/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h" #include "ios/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" #include "ios/chrome/browser/favicon/favicon_service_factory.h" +#include "ios/chrome/browser/history/history_service_factory.h" #include "ios/chrome/browser/history/top_sites_factory.h" #include "ios/chrome/browser/signin/signin_error_controller_factory.h" #include "ios/chrome/browser/suggestions/suggestions_service_factory.h" @@ -34,6 +35,7 @@ void EnsureBrowserStateKeyedServiceFactoriesBuilt() { enhanced_bookmarks::EnhancedBookmarkModelFactory::GetInstance(); ios::BookmarkUndoServiceFactory::GetInstance(); ios::FaviconServiceFactory::GetInstance(); + ios::HistoryServiceFactory::GetInstance(); ios::SigninErrorControllerFactory::GetInstance(); ios::StartupTaskRunnerServiceFactory::GetInstance(); ios::TopSitesFactory::GetInstance(); diff --git a/ios/chrome/browser/favicon/favicon_service_factory.cc b/ios/chrome/browser/favicon/favicon_service_factory.cc index 014aa15..e14f9fb 100644 --- a/ios/chrome/browser/favicon/favicon_service_factory.cc +++ b/ios/chrome/browser/favicon/favicon_service_factory.cc @@ -9,9 +9,8 @@ #include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "ios/chrome/browser/favicon/favicon_client_impl.h" +#include "ios/chrome/browser/history/history_service_factory.h" #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" -#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" -#include "ios/public/provider/chrome/browser/keyed_service_provider.h" namespace ios { @@ -41,7 +40,7 @@ FaviconServiceFactory::FaviconServiceFactory() : BrowserStateKeyedServiceFactory( "FaviconService", BrowserStateDependencyManager::GetInstance()) { - DependsOn(ios::GetKeyedServiceProvider()->GetHistoryServiceFactory()); + DependsOn(ios::HistoryServiceFactory::GetInstance()); } FaviconServiceFactory::~FaviconServiceFactory() { @@ -53,7 +52,7 @@ scoped_ptr<KeyedService> FaviconServiceFactory::BuildServiceInstanceFor( ios::ChromeBrowserState::FromBrowserState(context); return make_scoped_ptr(new favicon::FaviconService( make_scoped_ptr(new FaviconClientImpl), - ios::GetKeyedServiceProvider()->GetHistoryServiceForBrowserState( + ios::HistoryServiceFactory::GetForBrowserState( browser_state, ServiceAccessType::EXPLICIT_ACCESS))); } diff --git a/ios/chrome/browser/history/history_backend_client_impl.cc b/ios/chrome/browser/history/history_backend_client_impl.cc new file mode 100644 index 0000000..4100bce --- /dev/null +++ b/ios/chrome/browser/history/history_backend_client_impl.cc @@ -0,0 +1,50 @@ +// 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 "ios/chrome/browser/history/history_backend_client_impl.h" + +#include "components/bookmarks/browser/bookmark_model.h" +#include "url/gurl.h" + +HistoryBackendClientImpl::HistoryBackendClientImpl( + bookmarks::BookmarkModel* bookmark_model) + : bookmark_model_(bookmark_model) { +} + +HistoryBackendClientImpl::~HistoryBackendClientImpl() { +} + +bool HistoryBackendClientImpl::IsBookmarked(const GURL& url) { + if (!bookmark_model_) + return false; + + // HistoryBackendClient is used to determine if an URL is bookmarked. The data + // is loaded on a separate thread and may not be done when this method is + // called, therefore blocks until the bookmarks have finished loading. + bookmark_model_->BlockTillLoaded(); + return bookmark_model_->IsBookmarked(url); +} + +void HistoryBackendClientImpl::GetBookmarks( + std::vector<history::URLAndTitle>* bookmarks) { + if (!bookmark_model_) + return; + + // HistoryBackendClient is used to determine the set of bookmarked URLs. The + // data is loaded on a separate thread and may not be done when this method is + // called, therefore blocks until the bookmarks have finished loading. + std::vector<bookmarks::BookmarkModel::URLAndTitle> url_and_titles; + bookmark_model_->BlockTillLoaded(); + bookmark_model_->GetBookmarks(&url_and_titles); + + bookmarks->reserve(bookmarks->size() + url_and_titles.size()); + for (const auto& url_and_title : url_and_titles) { + history::URLAndTitle value = {url_and_title.url, url_and_title.title}; + bookmarks->push_back(value); + } +} + +bool HistoryBackendClientImpl::ShouldReportDatabaseError() { + return false; +} diff --git a/ios/chrome/browser/history/history_backend_client_impl.h b/ios/chrome/browser/history/history_backend_client_impl.h new file mode 100644 index 0000000..421a3b3 --- /dev/null +++ b/ios/chrome/browser/history/history_backend_client_impl.h @@ -0,0 +1,37 @@ +// 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 IOS_CHROME_BROWSER_HISTORY_HISTORY_BACKEND_CLIENT_IMPL_H_ +#define IOS_CHROME_BROWSER_HISTORY_HISTORY_BACKEND_CLIENT_IMPL_H_ + +#include <vector> + +#include "base/macros.h" +#include "components/history/core/browser/history_backend_client.h" + +class GURL; + +namespace bookmarks { +class BookmarkModel; +} + +class HistoryBackendClientImpl : public history::HistoryBackendClient { + public: + explicit HistoryBackendClientImpl(bookmarks::BookmarkModel* bookmark_model); + ~HistoryBackendClientImpl() override; + + private: + // history::HistoryBackendClient implementation. + bool IsBookmarked(const GURL& url) override; + void GetBookmarks(std::vector<history::URLAndTitle>* bookmarks) override; + bool ShouldReportDatabaseError() override; + + // BookmarkModel instance providing access to bookmarks. May be null during + // testing but must outlive HistoryBackendClientImpl if non-null. + bookmarks::BookmarkModel* bookmark_model_; + + DISALLOW_COPY_AND_ASSIGN(HistoryBackendClientImpl); +}; + +#endif // IOS_CHROME_BROWSER_HISTORY_HISTORY_BACKEND_CLIENT_IMPL_H_ diff --git a/ios/chrome/browser/history/history_client_impl.cc b/ios/chrome/browser/history/history_client_impl.cc new file mode 100644 index 0000000..1765711 --- /dev/null +++ b/ios/chrome/browser/history/history_client_impl.cc @@ -0,0 +1,90 @@ +// 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 "ios/chrome/browser/history/history_client_impl.h" + +#include "base/bind.h" +#include "base/callback.h" +#include "base/logging.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/history/core/browser/history_service.h" +#include "ios/chrome/browser/history/history_backend_client_impl.h" +#include "ios/chrome/browser/history/history_utils.h" +#include "url/gurl.h" + +HistoryClientImpl::HistoryClientImpl(bookmarks::BookmarkModel* bookmark_model) + : bookmark_model_(bookmark_model), is_bookmark_model_observer_(false) { +} + +HistoryClientImpl::~HistoryClientImpl() { +} + +void HistoryClientImpl::OnHistoryServiceCreated( + history::HistoryService* history_service) { + DCHECK(!is_bookmark_model_observer_); + if (bookmark_model_) { + on_bookmarks_removed_ = + base::Bind(&history::HistoryService::URLsNoLongerBookmarked, + base::Unretained(history_service)); + favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( + base::Bind(&bookmarks::BookmarkModel::OnFaviconChanged, + base::Unretained(bookmark_model_))); + bookmark_model_->AddObserver(this); + is_bookmark_model_observer_ = true; + } +} + +void HistoryClientImpl::Shutdown() { + // It's possible that bookmarks haven't loaded and history is waiting for + // bookmarks to complete loading. In such a situation history can't shutdown + // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To + // break the deadlock we tell BookmarkModel it's about to be deleted so that + // it can release the signal history is waiting on, allowing history to + // shutdown (HistoryService::Cleanup to complete). In such a scenario history + // sees an incorrect view of bookmarks, but it's better than a deadlock. + if (bookmark_model_) { + if (is_bookmark_model_observer_) { + is_bookmark_model_observer_ = false; + bookmark_model_->RemoveObserver(this); + favicon_changed_subscription_.reset(); + on_bookmarks_removed_.Reset(); + } + bookmark_model_->Shutdown(); + } +} + +bool HistoryClientImpl::CanAddURL(const GURL& url) { + return ios::CanAddURLToHistory(url); +} + +void HistoryClientImpl::NotifyProfileError(sql::InitStatus init_status) { + // TODO(ios): error while loading the History database are not reported to + // the user on iOS. http://crbug.com/504834 + NOTIMPLEMENTED(); +} + +scoped_ptr<history::HistoryBackendClient> +HistoryClientImpl::CreateBackendClient() { + return make_scoped_ptr(new HistoryBackendClientImpl(bookmark_model_)); +} + +void HistoryClientImpl::BookmarkModelChanged() { +} + +void HistoryClientImpl::BookmarkNodeRemoved( + bookmarks::BookmarkModel* model, + const bookmarks::BookmarkNode* parent, + int old_index, + const bookmarks::BookmarkNode* node, + const std::set<GURL>& no_longer_bookmarked) { + if (!on_bookmarks_removed_.is_null()) + on_bookmarks_removed_.Run(no_longer_bookmarked); +} + +void HistoryClientImpl::BookmarkAllUserNodesRemoved( + bookmarks::BookmarkModel* model, + const std::set<GURL>& removed_urls) { + if (!on_bookmarks_removed_.is_null()) + on_bookmarks_removed_.Run(removed_urls); +} diff --git a/ios/chrome/browser/history/history_client_impl.h b/ios/chrome/browser/history/history_client_impl.h new file mode 100644 index 0000000..959c50f --- /dev/null +++ b/ios/chrome/browser/history/history_client_impl.h @@ -0,0 +1,66 @@ +// 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 IOS_CHROME_BROWSER_HISTORY_HISTORY_CLIENT_IMPL_H_ +#define IOS_CHROME_BROWSER_HISTORY_HISTORY_CLIENT_IMPL_H_ + +#include <set> + +#include "base/callback_forward.h" +#include "base/callback_list.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "components/bookmarks/browser/base_bookmark_model_observer.h" +#include "components/history/core/browser/history_client.h" + +class GURL; + +namespace bookmarks { +class BookmarkModel; +class BookmarkNode; +} + +class HistoryClientImpl : public history::HistoryClient, + public bookmarks::BaseBookmarkModelObserver { + public: + explicit HistoryClientImpl(bookmarks::BookmarkModel* bookmark_model); + ~HistoryClientImpl() override; + + private: + // history::HistoryClient implementation. + void OnHistoryServiceCreated( + history::HistoryService* history_service) override; + void Shutdown() override; + bool CanAddURL(const GURL& url) override; + void NotifyProfileError(sql::InitStatus init_status) override; + scoped_ptr<history::HistoryBackendClient> CreateBackendClient() override; + + // bookmarks::BaseBookmarkModelObserver implementation. + void BookmarkModelChanged() override; + + // bookmarks::BookmarkModelObserver implementation. + void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, + const bookmarks::BookmarkNode* parent, + int old_index, + const bookmarks::BookmarkNode* node, + const std::set<GURL>& no_longer_bookmarked) override; + void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, + const std::set<GURL>& removed_urls) override; + + // BookmarkModel instance providing access to bookmarks. May be null during + // testing but must outlive HistoryClientImpl if non-null. + bookmarks::BookmarkModel* bookmark_model_; + bool is_bookmark_model_observer_; + + // Callback invoked when URLs are removed from BookmarkModel. + base::Callback<void(const std::set<GURL>&)> on_bookmarks_removed_; + + // Subscription for notifications of changes to favicons. + scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> + favicon_changed_subscription_; + + DISALLOW_COPY_AND_ASSIGN(HistoryClientImpl); +}; + +#endif // IOS_CHROME_BROWSER_HISTORY_HISTORY_CLIENT_IMPL_H_ diff --git a/ios/chrome/browser/history/history_service_factory.cc b/ios/chrome/browser/history/history_service_factory.cc new file mode 100644 index 0000000..98e3dff --- /dev/null +++ b/ios/chrome/browser/history/history_service_factory.cc @@ -0,0 +1,95 @@ +// 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 "ios/chrome/browser/history/history_service_factory.h" + +#include "base/memory/singleton.h" +#include "base/prefs/pref_service.h" +#include "components/history/core/browser/history_database_params.h" +#include "components/history/core/browser/history_service.h" +#include "components/history/core/browser/visit_delegate.h" +#include "components/history/ios/browser/history_database_helper.h" +#include "components/keyed_service/core/service_access_type.h" +#include "components/keyed_service/ios/browser_state_dependency_manager.h" +#include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" +#include "ios/chrome/browser/history/history_client_impl.h" +#include "ios/chrome/browser/pref_names.h" +#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" +#include "ios/public/provider/chrome/browser/keyed_service_provider.h" + +namespace ios { + +// static +history::HistoryService* HistoryServiceFactory::GetForBrowserState( + ios::ChromeBrowserState* browser_state, + ServiceAccessType access_type) { + // If saving history is disabled, only allow explicit access. + if (access_type != ServiceAccessType::EXPLICIT_ACCESS && + browser_state->GetPrefs()->GetBoolean( + ios::prefs::kSavingBrowserHistoryDisabled)) { + return nullptr; + } + + return static_cast<history::HistoryService*>( + GetInstance()->GetServiceForBrowserState(browser_state, true)); +} + +// static +history::HistoryService* HistoryServiceFactory::GetForBrowserStateIfExists( + ios::ChromeBrowserState* browser_state, + ServiceAccessType access_type) { + // If saving history is disabled, only allow explicit access. + if (access_type != ServiceAccessType::EXPLICIT_ACCESS && + browser_state->GetPrefs()->GetBoolean( + ios::prefs::kSavingBrowserHistoryDisabled)) { + return nullptr; + } + + return static_cast<history::HistoryService*>( + GetInstance()->GetServiceForBrowserState(browser_state, true)); +} + +HistoryServiceFactory* HistoryServiceFactory::GetInstance() { + return Singleton<HistoryServiceFactory>::get(); +} + +HistoryServiceFactory::HistoryServiceFactory() + : BrowserStateKeyedServiceFactory( + "HistoryService", + BrowserStateDependencyManager::GetInstance()) { + DependsOn(GetKeyedServiceProvider()->GetBookmarkModelFactory()); +} + +HistoryServiceFactory::~HistoryServiceFactory() { +} + +scoped_ptr<KeyedService> HistoryServiceFactory::BuildServiceInstanceFor( + web::BrowserState* context) const { + ios::ChromeBrowserState* browser_state = + ios::ChromeBrowserState::FromBrowserState(context); + scoped_ptr<history::HistoryService> history_service( + new history::HistoryService( + make_scoped_ptr(new HistoryClientImpl( + GetKeyedServiceProvider()->GetBookmarkModelForBrowserState( + browser_state))), + nullptr)); + if (!history_service->Init( + browser_state->GetPrefs()->GetString(ios::prefs::kAcceptLanguages), + history::HistoryDatabaseParamsForPath( + browser_state->GetStatePath()))) { + return nullptr; + } + return history_service.Pass(); +} + +web::BrowserState* HistoryServiceFactory::GetBrowserStateToUse( + web::BrowserState* context) const { + return GetBrowserStateRedirectedInIncognito(context); +} + +bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { + return true; +} + +} // namespace ios diff --git a/ios/chrome/browser/history/history_service_factory.h b/ios/chrome/browser/history/history_service_factory.h new file mode 100644 index 0000000..6449603 --- /dev/null +++ b/ios/chrome/browser/history/history_service_factory.h @@ -0,0 +1,54 @@ +// 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 IOS_CHROME_BROWSER_HISTORY_HISTORY_SERVICE_FACTORY_H_ +#define IOS_CHROME_BROWSER_HISTORY_HISTORY_SERVICE_FACTORY_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "components/keyed_service/ios/browser_state_keyed_service_factory.h" + +template <typename T> +struct DefaultSingletonTraits; +enum class ServiceAccessType; + +namespace history { +class HistoryService; +} + +namespace ios { + +class ChromeBrowserState; + +// Singleton that owns all HistoryService and associates them with +// ios::ChromeBrowserState. +class HistoryServiceFactory : public BrowserStateKeyedServiceFactory { + public: + static history::HistoryService* GetForBrowserState( + ios::ChromeBrowserState* browser_state, + ServiceAccessType access_type); + static history::HistoryService* GetForBrowserStateIfExists( + ios::ChromeBrowserState* browser_state, + ServiceAccessType access_type); + static HistoryServiceFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<HistoryServiceFactory>; + + HistoryServiceFactory(); + ~HistoryServiceFactory() override; + + // BrowserStateKeyedServiceFactory implementation. + scoped_ptr<KeyedService> BuildServiceInstanceFor( + web::BrowserState* context) const override; + web::BrowserState* GetBrowserStateToUse( + web::BrowserState* context) const override; + bool ServiceIsNULLWhileTesting() const override; + + DISALLOW_COPY_AND_ASSIGN(HistoryServiceFactory); +}; + +} // namespace ios + +#endif // IOS_CHROME_BROWSER_HISTORY_HISTORY_SERVICE_FACTORY_H_ diff --git a/ios/chrome/browser/history/history_utils.cc b/ios/chrome/browser/history/history_utils.cc new file mode 100644 index 0000000..724f807 --- /dev/null +++ b/ios/chrome/browser/history/history_utils.cc @@ -0,0 +1,36 @@ +// 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 "ios/chrome/browser/history/history_utils.h" + +#include "components/dom_distiller/core/url_constants.h" +#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" +#include "url/gurl.h" +#include "url/url_constants.h" + +namespace ios { + +// Returns true if this looks like the type of URL that should be added to the +// history. This filters out URLs such a JavaScript. +bool CanAddURLToHistory(const GURL& url) { + if (!url.is_valid()) + return false; + + // TODO: We should allow ChromeUIScheme URLs if they have been explicitly + // typed. Right now, however, these are marked as typed even when triggered + // by a shortcut or menu action. + if (url.SchemeIs(url::kJavaScriptScheme) || + url.SchemeIs(dom_distiller::kDomDistillerScheme) || + url.SchemeIs(ios::GetChromeBrowserProvider()->GetChromeUIScheme())) + return false; + + // Allow all about: and chrome: URLs except about:blank, since the user may + // like to see "chrome://memory/", etc. in their history and autocomplete. + if (url == GURL(url::kAboutBlankURL)) + return false; + + return true; +} + +} // namespace ios diff --git a/ios/chrome/browser/history/history_utils.h b/ios/chrome/browser/history/history_utils.h new file mode 100644 index 0000000..b55a53b --- /dev/null +++ b/ios/chrome/browser/history/history_utils.h @@ -0,0 +1,18 @@ +// 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 IOS_CHROME_BROWSER_HISTORY_HISTORY_UTILS_H_ +#define IOS_CHROME_BROWSER_HISTORY_HISTORY_UTILS_H_ + +class GURL; + +namespace ios { + +// Returns true if this looks like the type of URL that should be added to the +// history. This filters out URLs such a JavaScript. +bool CanAddURLToHistory(const GURL& url); + +} // namespace ios + +#endif // IOS_CHROME_BROWSER_HISTORY_HISTORY_UTILS_H_ diff --git a/ios/chrome/browser/history/top_sites_factory.cc b/ios/chrome/browser/history/top_sites_factory.cc index 538cc3f..9ac5a03 100644 --- a/ios/chrome/browser/history/top_sites_factory.cc +++ b/ios/chrome/browser/history/top_sites_factory.cc @@ -5,46 +5,19 @@ #include "ios/chrome/browser/history/top_sites_factory.h" #include "base/memory/singleton.h" -#include "components/dom_distiller/core/url_constants.h" #include "components/history/core/browser/history_constants.h" #include "components/history/core/browser/top_sites_impl.h" #include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/pref_registry/pref_registry_syncable.h" +#include "ios/chrome/browser/history/history_service_factory.h" +#include "ios/chrome/browser/history/history_utils.h" #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h" -#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" -#include "ios/public/provider/chrome/browser/keyed_service_provider.h" #include "ios/web/public/web_thread.h" -#include "url/gurl.h" -#include "url/url_constants.h" namespace ios { -namespace { -// Returns true if this looks like the type of URL that should be added to the -// history. This filters out URLs such a JavaScript. -bool CanAddURLToHistory(const GURL& url) { - if (!url.is_valid()) - return false; - - // TODO: We should allow ChromeUIScheme URLs if they have been explicitly - // typed. Right now, however, these are marked as typed even when triggered - // by a shortcut or menu action. - if (url.SchemeIs(url::kJavaScriptScheme) || - url.SchemeIs(dom_distiller::kDomDistillerScheme) || - url.SchemeIs(ios::GetChromeBrowserProvider()->GetChromeUIScheme())) - return false; - - // Allow all about: and chrome: URLs except about:blank, since the user may - // like to see "chrome://memory/", etc. in their history and autocomplete. - if (url == GURL(url::kAboutBlankURL)) - return false; - - return true; -} -} // namespace - // static scoped_refptr<history::TopSites> TopSitesFactory::GetForBrowserState( ios::ChromeBrowserState* browser_state) { @@ -61,7 +34,7 @@ TopSitesFactory::TopSitesFactory() : RefcountedBrowserStateKeyedServiceFactory( "TopSites", BrowserStateDependencyManager::GetInstance()) { - DependsOn(ios::GetKeyedServiceProvider()->GetHistoryServiceFactory()); + DependsOn(ios::HistoryServiceFactory::GetInstance()); } TopSitesFactory::~TopSitesFactory() { @@ -73,7 +46,7 @@ scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( ios::ChromeBrowserState::FromBrowserState(context); scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl( browser_state->GetPrefs(), - ios::GetKeyedServiceProvider()->GetHistoryServiceForBrowserState( + ios::HistoryServiceFactory::GetForBrowserState( browser_state, ServiceAccessType::EXPLICIT_ACCESS), history::PrepopulatedPageList(), base::Bind(CanAddURLToHistory))); top_sites->Init( diff --git a/ios/chrome/browser/pref_names.cc b/ios/chrome/browser/pref_names.cc index 0ca03b3..96df13e 100644 --- a/ios/chrome/browser/pref_names.cc +++ b/ios/chrome/browser/pref_names.cc @@ -14,6 +14,7 @@ namespace prefs { // preference. const char kAcceptLanguages[] = "intl.accept_languages"; +const char kSavingBrowserHistoryDisabled[] = "history.saving_disabled"; } // namespace prefs } // namespace ios diff --git a/ios/chrome/browser/pref_names.h b/ios/chrome/browser/pref_names.h index 6885152..2b349fb 100644 --- a/ios/chrome/browser/pref_names.h +++ b/ios/chrome/browser/pref_names.h @@ -11,6 +11,7 @@ namespace prefs { // Preferences in ios::prefs:: are temporary shared with desktop Chrome. // Non-shared preferences should be in the prefs:: namespace (no ios::). extern const char kAcceptLanguages[]; +extern const char kSavingBrowserHistoryDisabled[]; } // namespace prefs } // namespace ios diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp index 89063a4..dba67ef 100644 --- a/ios/chrome/ios_chrome.gyp +++ b/ios/chrome/ios_chrome.gyp @@ -54,6 +54,7 @@ '../../components/components.gyp:enhanced_bookmarks', '../../components/components.gyp:favicon_core', '../../components/components.gyp:history_core_browser', + '../../components/components.gyp:history_ios_browser', '../../components/components.gyp:infobars_core', '../../components/components.gyp:keyed_service_core', '../../components/components.gyp:keyed_service_ios', @@ -176,6 +177,14 @@ 'browser/geolocation/location_manager.mm', 'browser/geolocation/omnibox_geolocation_config.h', 'browser/geolocation/omnibox_geolocation_config.mm', + 'browser/history/history_backend_client_impl.cc', + 'browser/history/history_backend_client_impl.h', + 'browser/history/history_client_impl.cc', + 'browser/history/history_client_impl.h', + 'browser/history/history_service_factory.cc', + 'browser/history/history_service_factory.h', + 'browser/history/history_utils.cc', + 'browser/history/history_utils.h', 'browser/history/top_sites_factory.cc', 'browser/history/top_sites_factory.h', 'browser/infobars/confirm_infobar_controller.h', diff --git a/ios/public/provider/chrome/browser/keyed_service_provider.h b/ios/public/provider/chrome/browser/keyed_service_provider.h index 5d054fd..52547da 100644 --- a/ios/public/provider/chrome/browser/keyed_service_provider.h +++ b/ios/public/provider/chrome/browser/keyed_service_provider.h @@ -23,10 +23,6 @@ namespace bookmarks { class BookmarkModel; } -namespace history { -class HistoryService; -} - namespace sync_driver { class SyncService; } @@ -99,20 +95,6 @@ class KeyedServiceProvider { virtual sync_driver::SyncService* GetSyncServiceForBrowserState( ChromeBrowserState* browser_state) = 0; - // Returns the history::HistoryService factory for dependencies. - virtual KeyedServiceBaseFactory* GetHistoryServiceFactory() = 0; - - // Returns an instance of history::HistoryService tied to |browser_state|. - virtual history::HistoryService* GetHistoryServiceForBrowserState( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) = 0; - - // Returns an instance of history::HistoryService tied to |browser_state| if - // it exists, or null otherwise. - virtual history::HistoryService* GetHistoryServiceForBrowserStateIfExists( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) = 0; - private: DISALLOW_COPY_AND_ASSIGN(KeyedServiceProvider); }; diff --git a/ios/public/test/test_keyed_service_provider.cc b/ios/public/test/test_keyed_service_provider.cc index 1722bb8..db8e40c 100644 --- a/ios/public/test/test_keyed_service_provider.cc +++ b/ios/public/test/test_keyed_service_provider.cc @@ -134,22 +134,4 @@ TestKeyedServiceProvider::GetSyncServiceForBrowserState( return FakeSyncServiceFactory::GetForBrowserState(browser_state); } -KeyedServiceBaseFactory* TestKeyedServiceProvider::GetHistoryServiceFactory() { - return MissingServiceKeyedServiceFactory::GetInstance(); -} - -history::HistoryService* -TestKeyedServiceProvider::GetHistoryServiceForBrowserState( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) { - return nullptr; -} - -history::HistoryService* -TestKeyedServiceProvider::GetHistoryServiceForBrowserStateIfExists( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) { - return nullptr; -} - } // namespace ios diff --git a/ios/public/test/test_keyed_service_provider.h b/ios/public/test/test_keyed_service_provider.h index e2e11f7..25abae3 100644 --- a/ios/public/test/test_keyed_service_provider.h +++ b/ios/public/test/test_keyed_service_provider.h @@ -36,13 +36,6 @@ class TestKeyedServiceProvider : public KeyedServiceProvider { KeyedServiceBaseFactory* GetSyncServiceFactory() override; sync_driver::SyncService* GetSyncServiceForBrowserState( ChromeBrowserState* browser_state) override; - KeyedServiceBaseFactory* GetHistoryServiceFactory() override; - history::HistoryService* GetHistoryServiceForBrowserState( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) override; - history::HistoryService* GetHistoryServiceForBrowserStateIfExists( - ChromeBrowserState* browser_state, - ServiceAccessType access_type) override; private: DISALLOW_COPY_AND_ASSIGN(TestKeyedServiceProvider); |