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" | 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 "chrome/browser/history/chrome_history_backend_client.h" | 10 #include "chrome/browser/history/chrome_history_backend_client.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 ChromeHistoryClient::~ChromeHistoryClient() { | 24 ChromeHistoryClient::~ChromeHistoryClient() { |
25 } | 25 } |
26 | 26 |
27 void ChromeHistoryClient::OnHistoryServiceCreated( | 27 void ChromeHistoryClient::OnHistoryServiceCreated( |
28 history::HistoryService* history_service) { | 28 history::HistoryService* history_service) { |
29 DCHECK(!is_bookmark_model_observer_); | 29 DCHECK(!is_bookmark_model_observer_); |
30 if (bookmark_model_) { | 30 if (bookmark_model_) { |
31 on_bookmarks_removed_ = | 31 on_bookmarks_removed_ = |
32 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, | 32 base::Bind(&history::HistoryService::URLsNoLongerBookmarked, |
33 base::Unretained(history_service)); | 33 base::Unretained(history_service)); |
34 favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( | 34 favicons_changed_subscription_ = |
35 base::Bind(&bookmarks::BookmarkModel::OnFaviconChanged, | 35 history_service->AddFaviconsChangedCallback( |
36 base::Unretained(bookmark_model_))); | 36 base::Bind(&bookmarks::BookmarkModel::OnFaviconsChanged, |
| 37 base::Unretained(bookmark_model_))); |
37 bookmark_model_->AddObserver(this); | 38 bookmark_model_->AddObserver(this); |
38 is_bookmark_model_observer_ = true; | 39 is_bookmark_model_observer_ = true; |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 void ChromeHistoryClient::Shutdown() { | 43 void ChromeHistoryClient::Shutdown() { |
43 // It's possible that bookmarks haven't loaded and history is waiting for | 44 // It's possible that bookmarks haven't loaded and history is waiting for |
44 // bookmarks to complete loading. In such a situation history can't shutdown | 45 // bookmarks to complete loading. In such a situation history can't shutdown |
45 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 46 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To |
46 // break the deadlock we tell BookmarkModel it's about to be deleted so that | 47 // break the deadlock we tell BookmarkModel it's about to be deleted so that |
47 // it can release the signal history is waiting on, allowing history to | 48 // it can release the signal history is waiting on, allowing history to |
48 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 49 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
49 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 50 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
50 if (bookmark_model_) { | 51 if (bookmark_model_) { |
51 if (is_bookmark_model_observer_) { | 52 if (is_bookmark_model_observer_) { |
52 is_bookmark_model_observer_ = false; | 53 is_bookmark_model_observer_ = false; |
53 bookmark_model_->RemoveObserver(this); | 54 bookmark_model_->RemoveObserver(this); |
54 favicon_changed_subscription_.reset(); | 55 favicons_changed_subscription_.reset(); |
55 on_bookmarks_removed_.Reset(); | 56 on_bookmarks_removed_.Reset(); |
56 } | 57 } |
57 bookmark_model_->Shutdown(); | 58 bookmark_model_->Shutdown(); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 bool ChromeHistoryClient::CanAddURL(const GURL& url) { | 62 bool ChromeHistoryClient::CanAddURL(const GURL& url) { |
62 return CanAddURLToHistory(url); | 63 return CanAddURLToHistory(url); |
63 } | 64 } |
64 | 65 |
(...skipping 25 matching lines...) Expand all Loading... |
90 } | 91 } |
91 | 92 |
92 void ChromeHistoryClient::BookmarkAllUserNodesRemoved( | 93 void ChromeHistoryClient::BookmarkAllUserNodesRemoved( |
93 bookmarks::BookmarkModel* bookmark_model, | 94 bookmarks::BookmarkModel* bookmark_model, |
94 const std::set<GURL>& removed_urls) { | 95 const std::set<GURL>& removed_urls) { |
95 BaseBookmarkModelObserver::BookmarkAllUserNodesRemoved(bookmark_model, | 96 BaseBookmarkModelObserver::BookmarkAllUserNodesRemoved(bookmark_model, |
96 removed_urls); | 97 removed_urls); |
97 DCHECK(!on_bookmarks_removed_.is_null()); | 98 DCHECK(!on_bookmarks_removed_.is_null()); |
98 on_bookmarks_removed_.Run(removed_urls); | 99 on_bookmarks_removed_.Run(removed_urls); |
99 } | 100 } |
OLD | NEW |