Chromium Code Reviews| Index: chrome/browser/android/offline_pages/offline_page_bookmark_observer.cc |
| diff --git a/chrome/browser/android/offline_pages/offline_page_bookmark_observer.cc b/chrome/browser/android/offline_pages/offline_page_bookmark_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba554ef59df46949aab6715a729a7bb1173e275f |
| --- /dev/null |
| +++ b/chrome/browser/android/offline_pages/offline_page_bookmark_observer.cc |
| @@ -0,0 +1,46 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/offline_pages/offline_page_bookmark_observer.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "components/bookmarks/browser/bookmark_node.h" |
| +#include "components/offline_pages/client_namespace_constants.h" |
| +#include "components/offline_pages/offline_page_model.h" |
| +#include "url/gurl.h" |
| + |
| +namespace offline_pages { |
| + |
| +OfflinePageBookmarkObserver::OfflinePageBookmarkObserver(Profile* profile) |
|
Dmitry Titov
2016/08/26 23:08:58
I'd use BrowserContext* instead of Profile* here,
romax
2016/08/29 22:58:02
Done.
|
| + : profile_(profile), offline_page_model_(nullptr) {} |
| + |
| +void OfflinePageBookmarkObserver::BookmarkNodeRemoved( |
| + bookmarks::BookmarkModel* model, |
| + const bookmarks::BookmarkNode* parent, |
| + int old_index, |
| + const bookmarks::BookmarkNode* node, |
| + const std::set<GURL>& removed_urls) { |
| + if (!offline_page_model_) { |
| + offline_page_model_ = |
| + OfflinePageModelFactory::GetForBrowserContext(profile_); |
| + } |
| + ClientId client_id = ClientId(kBookmarkNamespace, std::to_string(node->id())); |
| + offline_page_model_->GetOfflineIdsForClientId( |
| + client_id, |
| + base::Bind(&OfflinePageBookmarkObserver::DoExpireRemovedBookmarkPages, |
| + base::Unretained(this))); |
|
Dmitry Titov
2016/08/26 23:08:59
Using unretained seems dangerous. What if this ins
romax
2016/08/29 22:58:02
Done.
|
| +} |
| + |
| +void OfflinePageBookmarkObserver::DoExpireRemovedBookmarkPages( |
| + const MultipleOfflineIdResult& offline_ids) { |
| + offline_page_model_->ExpirePages( |
| + offline_ids, base::Time::Now(), |
| + base::Bind(&OfflinePageBookmarkObserver::OnExpireRemovedBookmarkPagesDone, |
| + base::Unretained(this))); |
|
Dmitry Titov
2016/08/26 23:08:59
Same here (unretained)
romax
2016/08/29 22:58:02
Done.
|
| +} |
| + |
| +void OfflinePageBookmarkObserver::OnExpireRemovedBookmarkPagesDone( |
| + bool result) {} |
| + |
| +} // namespace offline_pages |