Chromium Code Reviews| 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 "components/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/i18n/string_compare.h" | 13 #include "base/i18n/string_compare.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h" | 19 #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h" |
| 20 #include "components/bookmarks/browser/bookmark_index.h" | 20 #include "components/bookmarks/browser/bookmark_index.h" |
| 21 #include "components/bookmarks/browser/bookmark_match.h" | 21 #include "components/bookmarks/browser/bookmark_match.h" |
| 22 #include "components/bookmarks/browser/bookmark_model_observer.h" | 22 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 23 #include "components/bookmarks/browser/bookmark_node_data.h" | 23 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 24 #include "components/bookmarks/browser/bookmark_storage.h" | 24 #include "components/bookmarks/browser/bookmark_storage.h" |
| 25 #include "components/bookmarks/browser/bookmark_undo_delegate.h" | 25 #include "components/bookmarks/browser/bookmark_undo_delegate.h" |
| 26 #include "components/bookmarks/browser/bookmark_utils.h" | 26 #include "components/bookmarks/browser/bookmark_utils.h" |
| 27 #include "components/bookmarks/browser/offline_page_bookmark_observer.h" | |
| 27 #include "components/favicon_base/favicon_types.h" | 28 #include "components/favicon_base/favicon_types.h" |
| 28 #include "grit/components_strings.h" | 29 #include "grit/components_strings.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/gfx/favicon_size.h" | 31 #include "ui/gfx/favicon_size.h" |
| 31 | 32 |
| 32 using base::Time; | 33 using base::Time; |
| 33 | 34 |
| 34 namespace bookmarks { | 35 namespace bookmarks { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 int index, | 101 int index, |
| 101 std::unique_ptr<BookmarkNode> node) override {} | 102 std::unique_ptr<BookmarkNode> node) override {} |
| 102 | 103 |
| 103 DISALLOW_COPY_AND_ASSIGN(EmptyUndoDelegate); | 104 DISALLOW_COPY_AND_ASSIGN(EmptyUndoDelegate); |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 } // namespace | 107 } // namespace |
| 107 | 108 |
| 108 // BookmarkModel -------------------------------------------------------------- | 109 // BookmarkModel -------------------------------------------------------------- |
| 109 | 110 |
| 110 BookmarkModel::BookmarkModel(std::unique_ptr<BookmarkClient> client) | 111 BookmarkModel::BookmarkModel( |
| 112 std::unique_ptr<BookmarkClient> client, | |
| 113 std::unique_ptr<OfflinePageBookmarkObserver> offline_page_observer) | |
| 111 : client_(std::move(client)), | 114 : client_(std::move(client)), |
| 115 offline_page_observer_(std::move(offline_page_observer)), | |
|
sky
2016/08/29 23:02:43
Why do you need OfflinePageBookmarkObserver bake i
romax
2016/08/29 23:21:24
Because I was thinking that it's better for the Bo
| |
| 112 loaded_(false), | 116 loaded_(false), |
| 113 root_(GURL()), | 117 root_(GURL()), |
| 114 bookmark_bar_node_(NULL), | 118 bookmark_bar_node_(NULL), |
| 115 other_node_(NULL), | 119 other_node_(NULL), |
| 116 mobile_node_(NULL), | 120 mobile_node_(NULL), |
| 117 next_node_id_(1), | 121 next_node_id_(1), |
| 118 observers_( | 122 observers_( |
| 119 base::ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), | 123 base::ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), |
| 120 loaded_signal_(base::WaitableEvent::ResetPolicy::MANUAL, | 124 loaded_signal_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 121 base::WaitableEvent::InitialState::NOT_SIGNALED), | 125 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 122 extensive_changes_(0), | 126 extensive_changes_(0), |
| 123 undo_delegate_(nullptr), | 127 undo_delegate_(nullptr), |
| 124 empty_undo_delegate_(new EmptyUndoDelegate) { | 128 empty_undo_delegate_(new EmptyUndoDelegate) { |
| 125 DCHECK(client_); | 129 DCHECK(client_); |
| 126 client_->Init(this); | 130 client_->Init(this); |
| 131 if (offline_page_observer_) | |
| 132 AddObserver(offline_page_observer_.get()); | |
| 127 } | 133 } |
| 128 | 134 |
| 129 BookmarkModel::~BookmarkModel() { | 135 BookmarkModel::~BookmarkModel() { |
| 130 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 136 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 131 BookmarkModelBeingDeleted(this)); | 137 BookmarkModelBeingDeleted(this)); |
| 132 | 138 |
| 133 if (store_.get()) { | 139 if (store_.get()) { |
| 134 // The store maintains a reference back to us. We need to tell it we're gone | 140 // The store maintains a reference back to us. We need to tell it we're gone |
| 135 // so that it doesn't try and invoke a method back on us again. | 141 // so that it doesn't try and invoke a method back on us again. |
| 136 store_->BookmarkModelDeleted(); | 142 store_->BookmarkModelDeleted(); |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 undo_delegate_ = undo_delegate; | 1111 undo_delegate_ = undo_delegate; |
| 1106 if (undo_delegate_) | 1112 if (undo_delegate_) |
| 1107 undo_delegate_->SetUndoProvider(this); | 1113 undo_delegate_->SetUndoProvider(this); |
| 1108 } | 1114 } |
| 1109 | 1115 |
| 1110 BookmarkUndoDelegate* BookmarkModel::undo_delegate() const { | 1116 BookmarkUndoDelegate* BookmarkModel::undo_delegate() const { |
| 1111 return undo_delegate_ ? undo_delegate_ : empty_undo_delegate_.get(); | 1117 return undo_delegate_ ? undo_delegate_ : empty_undo_delegate_.get(); |
| 1112 } | 1118 } |
| 1113 | 1119 |
| 1114 } // namespace bookmarks | 1120 } // namespace bookmarks |
| OLD | NEW |