| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/history/history_client_impl.h" | 5 #include "ios/chrome/browser/history/history_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/bookmarks/browser/bookmark_model.h" | 10 #include "components/bookmarks/browser/bookmark_model.h" |
| 11 #include "components/history/core/browser/history_service.h" | 11 #include "components/history/core/browser/history_service.h" |
| 12 #include "ios/chrome/browser/history/history_backend_client_impl.h" | 12 #include "ios/chrome/browser/history/history_backend_client_impl.h" |
| 13 #include "ios/chrome/browser/history/history_utils.h" | 13 #include "ios/chrome/browser/history/history_utils.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 HistoryClientImpl::HistoryClientImpl(bookmarks::BookmarkModel* bookmark_model) | 16 HistoryClientImpl::HistoryClientImpl(bookmarks::BookmarkModel* bookmark_model) |
| 17 : bookmark_model_(bookmark_model), is_bookmark_model_observer_(false) { | 17 : bookmark_model_(bookmark_model), is_bookmark_model_observer_(false) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 HistoryClientImpl::~HistoryClientImpl() { | 20 HistoryClientImpl::~HistoryClientImpl() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void HistoryClientImpl::OnHistoryServiceCreated( | 23 void HistoryClientImpl::OnHistoryServiceCreated( |
| 24 history::HistoryService* history_service) { | 24 history::HistoryService* history_service) { |
| 25 DCHECK(!is_bookmark_model_observer_); | 25 DCHECK(!is_bookmark_model_observer_); |
| 26 if (bookmark_model_) { | 26 if (bookmark_model_) { |
| 27 on_bookmarks_removed_ = | 27 on_bookmarks_removed_ = |
| 28 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, | 28 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, |
| 29 base::Unretained(history_service)); | 29 base::Unretained(history_service)); |
| 30 favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( | 30 favicons_changed_subscription_ = |
| 31 base::Bind(&bookmarks::BookmarkModel::OnFaviconChanged, | 31 history_service->AddFaviconsChangedCallback( |
| 32 base::Unretained(bookmark_model_))); | 32 base::Bind(&bookmarks::BookmarkModel::OnFaviconsChanged, |
| 33 base::Unretained(bookmark_model_))); |
| 33 bookmark_model_->AddObserver(this); | 34 bookmark_model_->AddObserver(this); |
| 34 is_bookmark_model_observer_ = true; | 35 is_bookmark_model_observer_ = true; |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 void HistoryClientImpl::Shutdown() { | 39 void HistoryClientImpl::Shutdown() { |
| 39 // It's possible that bookmarks haven't loaded and history is waiting for | 40 // It's possible that bookmarks haven't loaded and history is waiting for |
| 40 // bookmarks to complete loading. In such a situation history can't shutdown | 41 // bookmarks to complete loading. In such a situation history can't shutdown |
| 41 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 42 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To |
| 42 // break the deadlock we tell BookmarkModel it's about to be deleted so that | 43 // break the deadlock we tell BookmarkModel it's about to be deleted so that |
| 43 // it can release the signal history is waiting on, allowing history to | 44 // it can release the signal history is waiting on, allowing history to |
| 44 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 45 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
| 45 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 46 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
| 46 if (bookmark_model_) { | 47 if (bookmark_model_) { |
| 47 if (is_bookmark_model_observer_) { | 48 if (is_bookmark_model_observer_) { |
| 48 is_bookmark_model_observer_ = false; | 49 is_bookmark_model_observer_ = false; |
| 49 bookmark_model_->RemoveObserver(this); | 50 bookmark_model_->RemoveObserver(this); |
| 50 favicon_changed_subscription_.reset(); | 51 favicons_changed_subscription_.reset(); |
| 51 on_bookmarks_removed_.Reset(); | 52 on_bookmarks_removed_.Reset(); |
| 52 } | 53 } |
| 53 bookmark_model_->Shutdown(); | 54 bookmark_model_->Shutdown(); |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool HistoryClientImpl::CanAddURL(const GURL& url) { | 58 bool HistoryClientImpl::CanAddURL(const GURL& url) { |
| 58 return ios::CanAddURLToHistory(url); | 59 return ios::CanAddURLToHistory(url); |
| 59 } | 60 } |
| 60 | 61 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 78 if (!on_bookmarks_removed_.is_null()) | 79 if (!on_bookmarks_removed_.is_null()) |
| 79 on_bookmarks_removed_.Run(no_longer_bookmarked); | 80 on_bookmarks_removed_.Run(no_longer_bookmarked); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void HistoryClientImpl::BookmarkAllUserNodesRemoved( | 83 void HistoryClientImpl::BookmarkAllUserNodesRemoved( |
| 83 bookmarks::BookmarkModel* model, | 84 bookmarks::BookmarkModel* model, |
| 84 const std::set<GURL>& removed_urls) { | 85 const std::set<GURL>& removed_urls) { |
| 85 if (!on_bookmarks_removed_.is_null()) | 86 if (!on_bookmarks_removed_.is_null()) |
| 86 on_bookmarks_removed_.Run(removed_urls); | 87 on_bookmarks_removed_.Run(removed_urls); |
| 87 } | 88 } |
| OLD | NEW |