summaryrefslogtreecommitdiffstats
path: root/components/enhanced_bookmarks/bookmark_server_service.cc
diff options
context:
space:
mode:
authorrfevang <rfevang@chromium.org>2014-09-19 15:06:24 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-19 22:06:52 +0000
commitf7a91481ccc179cb47494c3ada5d89b4941e17dd (patch)
treed28749fd6915e88ed7c3fcb7cdae73a9b03354bf /components/enhanced_bookmarks/bookmark_server_service.cc
parentf75586adc8cbec278d71b9177b5c91c91146d200 (diff)
downloadchromium_src-f7a91481ccc179cb47494c3ada5d89b4941e17dd.zip
chromium_src-f7a91481ccc179cb47494c3ada5d89b4941e17dd.tar.gz
chromium_src-f7a91481ccc179cb47494c3ada5d89b4941e17dd.tar.bz2
Only set remote id during url node creation.
Folders should only have their id set by the server, and the clients should only set the remote id on clips they created themselves. Additionally, EnhancedBookmarkModel now monitors the remote id field for bookmarks, and initiates a de-duping protocol whenever two (or more) nodes with the same id are detected. BUG=413876 Review URL: https://codereview.chromium.org/563363002 Cr-Commit-Position: refs/heads/master@{#295790}
Diffstat (limited to 'components/enhanced_bookmarks/bookmark_server_service.cc')
-rw-r--r--components/enhanced_bookmarks/bookmark_server_service.cc100
1 files changed, 10 insertions, 90 deletions
diff --git a/components/enhanced_bookmarks/bookmark_server_service.cc b/components/enhanced_bookmarks/bookmark_server_service.cc
index a5b0e37..b6bd583 100644
--- a/components/enhanced_bookmarks/bookmark_server_service.cc
+++ b/components/enhanced_bookmarks/bookmark_server_service.cc
@@ -5,9 +5,7 @@
#include "components/enhanced_bookmarks/bookmark_server_service.h"
#include "base/auto_reset.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/bookmarks/browser/bookmark_model_observer.h"
-#include "components/enhanced_bookmarks/metadata_accessor.h"
+#include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "google_apis/gaia/gaia_constants.h"
@@ -21,24 +19,21 @@ BookmarkServerService::BookmarkServerService(
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
ProfileOAuth2TokenService* token_service,
SigninManagerBase* signin_manager,
- BookmarkModel* bookmark_model)
+ EnhancedBookmarkModel* enhanced_bookmark_model)
: OAuth2TokenService::Consumer("bookmark_server_service"),
- bookmark_model_(bookmark_model),
+ model_(enhanced_bookmark_model),
token_service_(token_service),
signin_manager_(signin_manager),
- request_context_getter_(request_context_getter),
- inhibit_change_notifications_(false) {
+ request_context_getter_(request_context_getter) {
DCHECK(request_context_getter.get());
DCHECK(token_service);
DCHECK(signin_manager);
- DCHECK(bookmark_model);
- bookmark_model_->AddObserver(this);
- if (bookmark_model_->loaded())
- BuildIdMap();
+ DCHECK(enhanced_bookmark_model);
+ model_->AddObserver(this);
}
BookmarkServerService::~BookmarkServerService() {
- bookmark_model_->RemoveObserver(this);
+ model_->RemoveObserver(this);
}
void BookmarkServerService::AddObserver(
@@ -51,23 +46,6 @@ void BookmarkServerService::RemoveObserver(
observers_.RemoveObserver(observer);
}
-void BookmarkServerService::BuildIdMap() {
- ui::TreeNodeIterator<const BookmarkNode> iterator(
- bookmark_model_->root_node());
-
- while (iterator.has_next()) {
- const BookmarkNode* bookmark = iterator.Next();
- if (bookmark_model_->is_permanent_node(bookmark))
- continue;
- // RemoteIdFromBookmark() will create the ID if it doesn't exists yet.
- std::string starid =
- enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model_, bookmark);
- if (bookmark->is_url()) {
- starsid_to_bookmark_[starid] = bookmark;
- }
- }
-}
-
const BookmarkNode* BookmarkServerService::BookmarkForRemoteId(
const std::string& remote_id) const {
std::map<std::string, const BookmarkNode*>::const_iterator it =
@@ -79,7 +57,7 @@ const BookmarkNode* BookmarkServerService::BookmarkForRemoteId(
const std::string BookmarkServerService::RemoteIDForBookmark(
const BookmarkNode* bookmark) const {
- return enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model_, bookmark);
+ return model_->GetRemoteId(bookmark);
}
void BookmarkServerService::Notify() {
@@ -165,66 +143,8 @@ void BookmarkServerService::OnURLFetchComplete(const net::URLFetcher* source) {
Notify();
}
-//
-// BookmarkModelObserver methods.
-//
-void BookmarkServerService::BookmarkModelLoaded(BookmarkModel* model,
- bool ids_reassigned) {
- BuildIdMap();
-}
-
-void BookmarkServerService::BookmarkNodeAdded(BookmarkModel* model,
- const BookmarkNode* parent,
- int index) {
- DCHECK(!inhibit_change_notifications_);
- const BookmarkNode* bookmark = parent->GetChild(index);
- if (!bookmark->is_url())
- return;
-
- base::AutoReset<bool> inhibitor(&inhibit_change_notifications_, true);
- std::string starid =
- enhanced_bookmarks::RemoteIdFromBookmark(model, bookmark);
- starsid_to_bookmark_[starid] = bookmark;
-}
-
-void BookmarkServerService::BookmarkNodeRemoved(
- BookmarkModel* model,
- const BookmarkNode* parent,
- int old_index,
- const BookmarkNode* node,
- const std::set<GURL>& removed_urls) {
- DCHECK(!inhibit_change_notifications_);
- if (!node->is_url())
- return;
- base::AutoReset<bool> inhibitor(&inhibit_change_notifications_, true);
- std::string starid = enhanced_bookmarks::RemoteIdFromBookmark(model, node);
- starsid_to_bookmark_.erase(starid);
-}
-
-void BookmarkServerService::OnWillChangeBookmarkMetaInfo(
- BookmarkModel* model,
- const BookmarkNode* node) {
- if (!node->is_url() || inhibit_change_notifications_)
- return;
- base::AutoReset<bool> inhibitor(&inhibit_change_notifications_, true);
- std::string starid = enhanced_bookmarks::RemoteIdFromBookmark(model, node);
- starsid_to_bookmark_.erase(starid);
-}
-
-void BookmarkServerService::BookmarkMetaInfoChanged(BookmarkModel* model,
- const BookmarkNode* node) {
- if (!node->is_url() || inhibit_change_notifications_)
- return;
-
- std::string starid = enhanced_bookmarks::RemoteIdFromBookmark(model, node);
- starsid_to_bookmark_[starid] = node;
-}
-
-void BookmarkServerService::BookmarkAllUserNodesRemoved(
- BookmarkModel* model,
- const std::set<GURL>& removed_urls) {
- DCHECK(!inhibit_change_notifications_);
- starsid_to_bookmark_.clear();
+void BookmarkServerService::EnhancedBookmarkModelShuttingDown() {
+ NOTREACHED();
}
SigninManagerBase* BookmarkServerService::GetSigninManager() {