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" |
| 9 #include "base/logging.h" |
7 #include "chrome/browser/history/chrome_history_backend_client.h" | 10 #include "chrome/browser/history/chrome_history_backend_client.h" |
8 #include "chrome/browser/history/history_utils.h" | 11 #include "chrome/browser/history/history_utils.h" |
9 #include "chrome/browser/ui/profile_error_dialog.h" | 12 #include "chrome/browser/ui/profile_error_dialog.h" |
10 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
11 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
12 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
13 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
| 17 #include "components/history/core/browser/history_service.h" |
14 | 18 |
15 ChromeHistoryClient::ChromeHistoryClient( | 19 ChromeHistoryClient::ChromeHistoryClient( |
16 bookmarks::BookmarkModel* bookmark_model) | 20 bookmarks::BookmarkModel* bookmark_model) |
17 : bookmark_model_(bookmark_model) { | 21 : bookmark_model_(bookmark_model), is_bookmark_model_observer_(false) { |
18 } | 22 } |
19 | 23 |
20 ChromeHistoryClient::~ChromeHistoryClient() { | 24 ChromeHistoryClient::~ChromeHistoryClient() { |
21 } | 25 } |
22 | 26 |
| 27 void ChromeHistoryClient::OnHistoryServiceCreated( |
| 28 history::HistoryService* history_service) { |
| 29 DCHECK(!is_bookmark_model_observer_); |
| 30 if (bookmark_model_) { |
| 31 on_bookmarks_removed_ = |
| 32 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, |
| 33 base::Unretained(history_service)); |
| 34 favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( |
| 35 base::Bind(&bookmarks::BookmarkModel::OnFaviconChanged, |
| 36 base::Unretained(bookmark_model_))); |
| 37 bookmark_model_->AddObserver(this); |
| 38 is_bookmark_model_observer_ = true; |
| 39 } |
| 40 } |
| 41 |
23 void ChromeHistoryClient::Shutdown() { | 42 void ChromeHistoryClient::Shutdown() { |
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 if (is_bookmark_model_observer_) { |
| 52 is_bookmark_model_observer_ = false; |
| 53 bookmark_model_->RemoveObserver(this); |
| 54 favicon_changed_subscription_.reset(); |
| 55 on_bookmarks_removed_.Reset(); |
| 56 } |
32 bookmark_model_->Shutdown(); | 57 bookmark_model_->Shutdown(); |
| 58 } |
33 } | 59 } |
34 | 60 |
35 bool ChromeHistoryClient::CanAddURL(const GURL& url) { | 61 bool ChromeHistoryClient::CanAddURL(const GURL& url) { |
36 return CanAddURLToHistory(url); | 62 return CanAddURLToHistory(url); |
37 } | 63 } |
38 | 64 |
39 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { | 65 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { |
40 ShowProfileErrorDialog( | 66 ShowProfileErrorDialog( |
41 PROFILE_ERROR_HISTORY, | 67 PROFILE_ERROR_HISTORY, |
42 (init_status == sql::INIT_FAILURE) ? | 68 (init_status == sql::INIT_FAILURE) ? |
43 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 69 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
44 } | 70 } |
45 | 71 |
46 scoped_ptr<history::HistoryBackendClient> | 72 scoped_ptr<history::HistoryBackendClient> |
47 ChromeHistoryClient::CreateBackendClient() { | 73 ChromeHistoryClient::CreateBackendClient() { |
48 return make_scoped_ptr(new ChromeHistoryBackendClient(bookmark_model_)); | 74 return make_scoped_ptr(new ChromeHistoryBackendClient(bookmark_model_)); |
49 } | 75 } |
| 76 |
| 77 void ChromeHistoryClient::BookmarkModelChanged() { |
| 78 } |
| 79 |
| 80 void ChromeHistoryClient::BookmarkNodeRemoved( |
| 81 bookmarks::BookmarkModel* bookmark_model, |
| 82 const bookmarks::BookmarkNode* parent, |
| 83 int old_index, |
| 84 const bookmarks::BookmarkNode* node, |
| 85 const std::set<GURL>& removed_urls) { |
| 86 BaseBookmarkModelObserver::BookmarkNodeRemoved(bookmark_model, parent, |
| 87 old_index, node, removed_urls); |
| 88 DCHECK(!on_bookmarks_removed_.is_null()); |
| 89 on_bookmarks_removed_.Run(removed_urls); |
| 90 } |
| 91 |
| 92 void ChromeHistoryClient::BookmarkAllUserNodesRemoved( |
| 93 bookmarks::BookmarkModel* bookmark_model, |
| 94 const std::set<GURL>& removed_urls) { |
| 95 BaseBookmarkModelObserver::BookmarkAllUserNodesRemoved(bookmark_model, |
| 96 removed_urls); |
| 97 DCHECK(!on_bookmarks_removed_.is_null()); |
| 98 on_bookmarks_removed_.Run(removed_urls); |
| 99 } |
OLD | NEW |