| 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/enhanced_bookmarks/enhanced_bookmark_model.h" | 5 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
| 6 | 6 |
| 7 #include <iomanip> | 7 #include <iomanip> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/location.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/bookmarks/browser/bookmark_node.h" | 18 #include "components/bookmarks/browser/bookmark_node.h" |
| 17 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h" | 19 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h" |
| 18 #include "components/enhanced_bookmarks/proto/metadata.pb.h" | 20 #include "components/enhanced_bookmarks/proto/metadata.pb.h" |
| 19 #include "ui/base/models/tree_node_iterator.h" | 21 #include "ui/base/models/tree_node_iterator.h" |
| 20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 21 | 23 |
| 22 using bookmarks::BookmarkModel; | 24 using bookmarks::BookmarkModel; |
| 23 using bookmarks::BookmarkNode; | 25 using bookmarks::BookmarkNode; |
| 24 | 26 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 for (int i = 0; i < node->child_count(); i++) { | 393 for (int i = 0; i < node->child_count(); i++) { |
| 392 RemoveNodeFromMaps(node->GetChild(i)); | 394 RemoveNodeFromMaps(node->GetChild(i)); |
| 393 } | 395 } |
| 394 std::string remote_id = GetRemoteId(node); | 396 std::string remote_id = GetRemoteId(node); |
| 395 id_map_.erase(remote_id); | 397 id_map_.erase(remote_id); |
| 396 nodes_to_reset_.erase(node); | 398 nodes_to_reset_.erase(node); |
| 397 } | 399 } |
| 398 | 400 |
| 399 void EnhancedBookmarkModel::ScheduleResetDuplicateRemoteIds() { | 401 void EnhancedBookmarkModel::ScheduleResetDuplicateRemoteIds() { |
| 400 if (!nodes_to_reset_.empty()) { | 402 if (!nodes_to_reset_.empty()) { |
| 401 base::MessageLoopProxy::current()->PostTask( | 403 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 402 FROM_HERE, | 404 FROM_HERE, base::Bind(&EnhancedBookmarkModel::ResetDuplicateRemoteIds, |
| 403 base::Bind(&EnhancedBookmarkModel::ResetDuplicateRemoteIds, | 405 weak_ptr_factory_.GetWeakPtr())); |
| 404 weak_ptr_factory_.GetWeakPtr())); | |
| 405 } | 406 } |
| 406 } | 407 } |
| 407 | 408 |
| 408 void EnhancedBookmarkModel::ResetDuplicateRemoteIds() { | 409 void EnhancedBookmarkModel::ResetDuplicateRemoteIds() { |
| 409 for (NodeToIdMap::iterator it = nodes_to_reset_.begin(); | 410 for (NodeToIdMap::iterator it = nodes_to_reset_.begin(); |
| 410 it != nodes_to_reset_.end(); | 411 it != nodes_to_reset_.end(); |
| 411 ++it) { | 412 ++it) { |
| 412 BookmarkNode::MetaInfoMap meta_info; | 413 BookmarkNode::MetaInfoMap meta_info; |
| 413 meta_info[kIdKey] = ""; | 414 meta_info[kIdKey] = ""; |
| 414 meta_info[kOldIdKey] = it->second; | 415 meta_info[kOldIdKey] = it->second; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (!result) | 528 if (!result) |
| 528 return false; | 529 return false; |
| 529 | 530 |
| 530 std::string encoded; | 531 std::string encoded; |
| 531 base::Base64Encode(output, &encoded); | 532 base::Base64Encode(output, &encoded); |
| 532 bookmark_model_->SetNodeMetaInfo(node, kImageDataKey, encoded); | 533 bookmark_model_->SetNodeMetaInfo(node, kImageDataKey, encoded); |
| 533 return true; | 534 return true; |
| 534 } | 535 } |
| 535 | 536 |
| 536 } // namespace enhanced_bookmarks | 537 } // namespace enhanced_bookmarks |
| OLD | NEW |