| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/string_util.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" | 16 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_index.h" | 17 #include "chrome/browser/bookmarks/bookmark_index.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_storage.h" | 19 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_utils.h" | 20 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/history/history_notifications.h" | 22 #include "chrome/browser/history/history_notifications.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 DCHECK(node); | 299 DCHECK(node); |
| 299 if (!node->is_favicon_loaded()) { | 300 if (!node->is_favicon_loaded()) { |
| 300 BookmarkNode* mutable_node = AsMutable(node); | 301 BookmarkNode* mutable_node = AsMutable(node); |
| 301 mutable_node->set_is_favicon_loaded(true); | 302 mutable_node->set_is_favicon_loaded(true); |
| 302 LoadFavicon(mutable_node); | 303 LoadFavicon(mutable_node); |
| 303 } | 304 } |
| 304 return node->favicon(); | 305 return node->favicon(); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { | 308 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { |
| 309 // Remove extra whitespace from folder/bookmark names. |
| 310 string16 mutable_title = CollapseWhitespace(title, false); |
| 311 |
| 308 if (!node) { | 312 if (!node) { |
| 309 NOTREACHED(); | 313 NOTREACHED(); |
| 310 return; | 314 return; |
| 311 } | 315 } |
| 312 if (node->GetTitle() == title) | 316 if (node->GetTitle() == mutable_title) |
| 313 return; | 317 return; |
| 314 | 318 |
| 315 if (is_permanent_node(node)) { | 319 if (is_permanent_node(node)) { |
| 316 NOTREACHED(); | 320 NOTREACHED(); |
| 317 return; | 321 return; |
| 318 } | 322 } |
| 319 | 323 |
| 320 // The title index doesn't support changing the title, instead we remove then | 324 // The title index doesn't support changing the title, instead we remove then |
| 321 // add it back. | 325 // add it back. |
| 322 index_->Remove(node); | 326 index_->Remove(node); |
| 323 AsMutable(node)->set_title(title); | 327 AsMutable(node)->set_title(mutable_title); |
| 324 index_->Add(node); | 328 index_->Add(node); |
| 325 | 329 |
| 326 if (store_.get()) | 330 if (store_.get()) |
| 327 store_->ScheduleSave(); | 331 store_->ScheduleSave(); |
| 328 | 332 |
| 329 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 333 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 330 BookmarkNodeChanged(this, node)); | 334 BookmarkNodeChanged(this, node)); |
| 331 } | 335 } |
| 332 | 336 |
| 333 void BookmarkModel::SetURL(const BookmarkNode* node, const GURL& url) { | 337 void BookmarkModel::SetURL(const BookmarkNode* node, const GURL& url) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 int index, | 433 int index, |
| 430 const string16& title) { | 434 const string16& title) { |
| 431 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { | 435 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { |
| 432 // Can't add to the root. | 436 // Can't add to the root. |
| 433 NOTREACHED(); | 437 NOTREACHED(); |
| 434 return NULL; | 438 return NULL; |
| 435 } | 439 } |
| 436 | 440 |
| 437 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); | 441 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); |
| 438 new_node->set_date_folder_modified(Time::Now()); | 442 new_node->set_date_folder_modified(Time::Now()); |
| 439 new_node->set_title(title); | 443 // Folders shouldn't have line breaks in their titles. |
| 444 new_node->set_title(CollapseWhitespace(title, false)); |
| 440 new_node->set_type(BookmarkNode::FOLDER); | 445 new_node->set_type(BookmarkNode::FOLDER); |
| 441 | 446 |
| 442 return AddNode(AsMutable(parent), index, new_node, false); | 447 return AddNode(AsMutable(parent), index, new_node, false); |
| 443 } | 448 } |
| 444 | 449 |
| 445 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, | 450 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, |
| 446 int index, | 451 int index, |
| 447 const string16& title, | 452 const string16& title, |
| 448 const GURL& url) { | 453 const GURL& url) { |
| 449 return AddURLWithCreationTime(parent, index, title, url, Time::Now()); | 454 return AddURLWithCreationTime(parent, index, |
| 455 CollapseWhitespace(title, false), |
| 456 url, Time::Now()); |
| 450 } | 457 } |
| 451 | 458 |
| 452 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( | 459 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( |
| 453 const BookmarkNode* parent, | 460 const BookmarkNode* parent, |
| 454 int index, | 461 int index, |
| 455 const string16& title, | 462 const string16& title, |
| 456 const GURL& url, | 463 const GURL& url, |
| 457 const Time& creation_time) { | 464 const Time& creation_time) { |
| 458 if (!loaded_ || !url.is_valid() || is_root_node(parent) || | 465 if (!loaded_ || !url.is_valid() || is_root_node(parent) || |
| 459 !IsValidIndex(parent, index, true)) { | 466 !IsValidIndex(parent, index, true)) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 return next_node_id_++; | 836 return next_node_id_++; |
| 830 } | 837 } |
| 831 | 838 |
| 832 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 839 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
| 833 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 840 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 834 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 841 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 835 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 842 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
| 836 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 843 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
| 837 new BookmarkIndex(profile_), next_node_id_); | 844 new BookmarkIndex(profile_), next_node_id_); |
| 838 } | 845 } |
| OLD | NEW |