| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/history/chrome_history_client.h" | 5 #include "chrome/browser/history/chrome_history_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 7 #include "chrome/browser/history/chrome_history_backend_client.h" | 9 #include "chrome/browser/history/chrome_history_backend_client.h" |
| 8 #include "chrome/browser/history/history_utils.h" | 10 #include "chrome/browser/history/history_utils.h" |
| 9 #include "chrome/browser/ui/profile_error_dialog.h" | 11 #include "chrome/browser/ui/profile_error_dialog.h" |
| 10 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
| 11 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 12 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 13 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/history/core/browser/history_service.h" |
| 14 | 17 |
| 15 ChromeHistoryClient::ChromeHistoryClient( | 18 ChromeHistoryClient::ChromeHistoryClient( |
| 16 bookmarks::BookmarkModel* bookmark_model) | 19 bookmarks::BookmarkModel* bookmark_model) |
| 17 : bookmark_model_(bookmark_model) { | 20 : bookmark_model_(bookmark_model) { |
| 21 if (bookmark_model_) |
| 22 bookmark_model_->AddObserver(this); |
| 18 } | 23 } |
| 19 | 24 |
| 20 ChromeHistoryClient::~ChromeHistoryClient() { | 25 ChromeHistoryClient::~ChromeHistoryClient() { |
| 21 } | 26 } |
| 22 | 27 |
| 28 void ChromeHistoryClient::Init(history::HistoryService* history_service) { |
| 29 if (bookmark_model_) { |
| 30 favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( |
| 31 base::Bind(&bookmarks::BookmarkModel::OnFaviconChanged, |
| 32 base::Unretained(bookmark_model_))); |
| 33 } |
| 34 on_bookmarks_removed_ = |
| 35 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, |
| 36 base::Unretained(history_service)); |
| 37 } |
| 38 |
| 23 void ChromeHistoryClient::Shutdown() { | 39 void ChromeHistoryClient::Shutdown() { |
| 40 favicon_changed_subscription_.reset(); |
| 41 on_bookmarks_removed_ = base::Callback<void(const std::set<GURL>&)>(); |
| 42 |
| 24 // It's possible that bookmarks haven't loaded and history is waiting for | 43 // It's possible that bookmarks haven't loaded and history is waiting for |
| 25 // bookmarks to complete loading. In such a situation history can't shutdown | 44 // bookmarks to complete loading. In such a situation history can't shutdown |
| 26 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 45 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To |
| 27 // break the deadlock we tell BookmarkModel it's about to be deleted so that | 46 // break the deadlock we tell BookmarkModel it's about to be deleted so that |
| 28 // it can release the signal history is waiting on, allowing history to | 47 // it can release the signal history is waiting on, allowing history to |
| 29 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 48 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
| 30 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 49 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
| 31 if (bookmark_model_) | 50 if (bookmark_model_) { |
| 51 bookmark_model_->RemoveObserver(this); |
| 32 bookmark_model_->Shutdown(); | 52 bookmark_model_->Shutdown(); |
| 53 } |
| 33 } | 54 } |
| 34 | 55 |
| 35 bool ChromeHistoryClient::CanAddURL(const GURL& url) { | 56 bool ChromeHistoryClient::CanAddURL(const GURL& url) { |
| 36 return CanAddURLToHistory(url); | 57 return CanAddURLToHistory(url); |
| 37 } | 58 } |
| 38 | 59 |
| 39 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { | 60 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { |
| 40 ShowProfileErrorDialog( | 61 ShowProfileErrorDialog( |
| 41 PROFILE_ERROR_HISTORY, | 62 PROFILE_ERROR_HISTORY, |
| 42 (init_status == sql::INIT_FAILURE) ? | 63 (init_status == sql::INIT_FAILURE) ? |
| 43 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 64 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
| 44 } | 65 } |
| 45 | 66 |
| 46 scoped_ptr<history::HistoryBackendClient> | 67 scoped_ptr<history::HistoryBackendClient> |
| 47 ChromeHistoryClient::CreateBackendClient() { | 68 ChromeHistoryClient::CreateBackendClient() { |
| 48 return make_scoped_ptr(new ChromeHistoryBackendClient(bookmark_model_)); | 69 return make_scoped_ptr(new ChromeHistoryBackendClient(bookmark_model_)); |
| 49 } | 70 } |
| 71 |
| 72 void ChromeHistoryClient::BookmarkModelChanged() { |
| 73 } |
| 74 |
| 75 void ChromeHistoryClient::BookmarkNodeRemoved( |
| 76 bookmarks::BookmarkModel* bookmark_model, |
| 77 const bookmarks::BookmarkNode* parent, |
| 78 int old_index, |
| 79 const bookmarks::BookmarkNode* node, |
| 80 const std::set<GURL>& removed_urls) { |
| 81 BaseBookmarkModelObserver::BookmarkNodeRemoved(bookmark_model, parent, |
| 82 old_index, node, removed_urls); |
| 83 if (!on_bookmarks_removed_.is_null()) |
| 84 on_bookmarks_removed_.Run(removed_urls); |
| 85 } |
| 86 |
| 87 void ChromeHistoryClient::BookmarkAllUserNodesRemoved( |
| 88 bookmarks::BookmarkModel* bookmark_model, |
| 89 const std::set<GURL>& removed_urls) { |
| 90 BaseBookmarkModelObserver::BookmarkAllUserNodesRemoved(bookmark_model, |
| 91 removed_urls); |
| 92 if (!on_bookmarks_removed_.is_null()) |
| 93 on_bookmarks_removed_.Run(removed_urls); |
| 94 } |
| OLD | NEW |