Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 371029: Remove unique naming. (Closed)
Patch Set: Ready and about to go in! Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/sync/engine/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 int64 BaseNode::GetId() const { 238 int64 BaseNode::GetId() const {
239 return GetEntry()->Get(syncable::META_HANDLE); 239 return GetEntry()->Get(syncable::META_HANDLE);
240 } 240 }
241 241
242 bool BaseNode::GetIsFolder() const { 242 bool BaseNode::GetIsFolder() const {
243 return GetEntry()->Get(syncable::IS_DIR); 243 return GetEntry()->Get(syncable::IS_DIR);
244 } 244 }
245 245
246 const std::wstring& BaseNode::GetTitle() const { 246 const std::wstring& BaseNode::GetTitle() const {
247 ServerNameToSyncAPIName(GetEntry()->GetName().non_unique_value(), 247 ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME),
248 &data_->title); 248 &data_->title);
249 return data_->title; 249 return data_->title;
250 } 250 }
251 251
252 const GURL& BaseNode::GetURL() const { 252 const GURL& BaseNode::GetURL() const {
253 GURL url(GetEntry()->Get(syncable::BOOKMARK_URL)); 253 GURL url(GetEntry()->Get(syncable::BOOKMARK_URL));
254 url.Swap(&data_->url); 254 url.Swap(&data_->url);
255 return data_->url; 255 return data_->url;
256 } 256 }
257 257
258 const int64* BaseNode::GetChildIds(size_t* child_count) const { 258 const int64* BaseNode::GetChildIds(size_t* child_count) const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return; // Skip redundant changes. 309 return; // Skip redundant changes.
310 310
311 entry_->Put(syncable::IS_DIR, folder); 311 entry_->Put(syncable::IS_DIR, folder);
312 MarkForSyncing(); 312 MarkForSyncing();
313 } 313 }
314 314
315 void WriteNode::SetTitle(const std::wstring& title) { 315 void WriteNode::SetTitle(const std::wstring& title) {
316 std::string server_legal_name; 316 std::string server_legal_name;
317 SyncAPINameToServerName(title, &server_legal_name); 317 SyncAPINameToServerName(title, &server_legal_name);
318 318
319 syncable::Name old_name = entry_->GetName(); 319 PathString old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
320 320
321 if (server_legal_name == old_name.non_unique_value()) 321 if (server_legal_name == old_name)
322 return; // Skip redundant changes. 322 return; // Skip redundant changes.
323 323
324 // Otherwise, derive a new unique name so we have a valid value 324 entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
325 // to use as the DBName.
326 syncable::SyncName sync_name(server_legal_name);
327 syncable::DBName db_name(sync_name.value());
328 db_name.MakeOSLegal();
329 db_name.MakeNoncollidingForEntry(transaction_->GetWrappedTrans(),
330 entry_->Get(syncable::PARENT_ID), entry_);
331
332 syncable::Name new_name = syncable::Name::FromDBNameAndSyncName(db_name,
333 sync_name);
334 entry_->PutName(new_name);
335 MarkForSyncing(); 325 MarkForSyncing();
336 } 326 }
337 327
338 void WriteNode::SetURL(const GURL& url) { 328 void WriteNode::SetURL(const GURL& url) {
339 const std::string& url_string = url.spec(); 329 const std::string& url_string = url.spec();
340 if (url_string == entry_->Get(syncable::BOOKMARK_URL)) 330 if (url_string == entry_->Get(syncable::BOOKMARK_URL))
341 return; // Skip redundant changes. 331 return; // Skip redundant changes.
342 332
343 entry_->Put(syncable::BOOKMARK_URL, url_string); 333 entry_->Put(syncable::BOOKMARK_URL, url_string);
344 MarkForSyncing(); 334 MarkForSyncing();
(...skipping 29 matching lines...) Expand all
374 const BaseNode* predecessor) { 364 const BaseNode* predecessor) {
375 DCHECK(!entry_) << "Init called twice"; 365 DCHECK(!entry_) << "Init called twice";
376 // |predecessor| must be a child of |parent| or NULL. 366 // |predecessor| must be a child of |parent| or NULL.
377 if (predecessor && predecessor->GetParentId() != parent.GetId()) { 367 if (predecessor && predecessor->GetParentId() != parent.GetId()) {
378 DCHECK(false); 368 DCHECK(false);
379 return false; 369 return false;
380 } 370 }
381 371
382 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID); 372 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
383 373
384 // Start out with a dummy name, but make it unique. We expect 374 // Start out with a dummy name. We expect
385 // the caller to set a meaningful name after creation. 375 // the caller to set a meaningful name after creation.
386 syncable::DBName dummy(kDefaultNameForNewNodes); 376 PathString dummy(kDefaultNameForNewNodes);
387 dummy.MakeOSLegal();
388 dummy.MakeNoncollidingForEntry(transaction_->GetWrappedTrans(), parent_id,
389 NULL);
390 377
391 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), 378 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
392 syncable::CREATE, parent_id, dummy); 379 syncable::CREATE, parent_id, dummy);
393 380
394 if (!entry_->good()) 381 if (!entry_->good())
395 return false; 382 return false;
396 383
397 // Entries are untitled folders by default. 384 // Entries are untitled folders by default.
398 entry_->Put(syncable::IS_DIR, true); 385 entry_->Put(syncable::IS_DIR, true);
399 // TODO(ncarter): Naming this bit IS_BOOKMARK_OBJECT is a bit unfortunate, 386 // TODO(ncarter): Naming this bit IS_BOOKMARK_OBJECT is a bit unfortunate,
(...skipping 18 matching lines...) Expand all
418 405
419 // Filter out redundant changes if both the parent and the predecessor match. 406 // Filter out redundant changes if both the parent and the predecessor match.
420 if (new_parent_id == entry_->Get(syncable::PARENT_ID)) { 407 if (new_parent_id == entry_->Get(syncable::PARENT_ID)) {
421 const syncable::Id& old = entry_->Get(syncable::PREV_ID); 408 const syncable::Id& old = entry_->Get(syncable::PREV_ID);
422 if ((!predecessor && old.IsRoot()) || 409 if ((!predecessor && old.IsRoot()) ||
423 (predecessor && (old == predecessor->GetEntry()->Get(syncable::ID)))) { 410 (predecessor && (old == predecessor->GetEntry()->Get(syncable::ID)))) {
424 return true; 411 return true;
425 } 412 }
426 } 413 }
427 414
428 // Discard the old database name, derive a new database name from the sync 415 // Atomically change the parent. This will fail if it would
429 // name, and make it legal and unique.
430 syncable::Name name = syncable::Name::FromSyncName(GetEntry()->GetName());
431 name.db_value().MakeOSLegal();
432 name.db_value().MakeNoncollidingForEntry(GetTransaction()->GetWrappedTrans(),
433 new_parent_id, entry_);
434
435 // Atomically change the parent and name. This will fail if it would
436 // introduce a cycle in the hierarchy. 416 // introduce a cycle in the hierarchy.
437 if (!entry_->PutParentIdAndName(new_parent_id, name)) 417 if (!entry_->Put(syncable::PARENT_ID, new_parent_id))
438 return false; 418 return false;
439 419
440 // Now set the predecessor, which sets IS_UNSYNCED as necessary. 420 // Now set the predecessor, which sets IS_UNSYNCED as necessary.
441 PutPredecessor(predecessor); 421 PutPredecessor(predecessor);
442 422
443 return true; 423 return true;
444 } 424 }
445 425
446 const syncable::Entry* WriteNode::GetEntry() const { 426 const syncable::Entry* WriteNode::GetEntry() const {
447 return entry_; 427 return entry_;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 if (a.ref(syncable::PARENT_ID) != b.Get(syncable::PARENT_ID)) 786 if (a.ref(syncable::PARENT_ID) != b.Get(syncable::PARENT_ID))
807 return true; 787 return true;
808 return false; 788 return false;
809 } 789 }
810 790
811 // Determine if any of the fields made visible to clients of the Sync API 791 // Determine if any of the fields made visible to clients of the Sync API
812 // differ between the versions of an entry stored in |a| and |b|. A return 792 // differ between the versions of an entry stored in |a| and |b|. A return
813 // value of false means that it should be OK to ignore this change. 793 // value of false means that it should be OK to ignore this change.
814 static bool BookmarkPropertiesDiffer(const syncable::EntryKernel& a, 794 static bool BookmarkPropertiesDiffer(const syncable::EntryKernel& a,
815 const syncable::Entry& b) { 795 const syncable::Entry& b) {
816 if (a.ref(syncable::NAME) != b.Get(syncable::NAME)) 796 if (a.ref(syncable::NON_UNIQUE_NAME) != b.Get(syncable::NON_UNIQUE_NAME))
817 return true;
818 if (a.ref(syncable::UNSANITIZED_NAME) != b.Get(syncable::UNSANITIZED_NAME))
819 return true; 797 return true;
820 if (a.ref(syncable::IS_DIR) != b.Get(syncable::IS_DIR)) 798 if (a.ref(syncable::IS_DIR) != b.Get(syncable::IS_DIR))
821 return true; 799 return true;
822 if (a.ref(syncable::BOOKMARK_URL) != b.Get(syncable::BOOKMARK_URL)) 800 if (a.ref(syncable::BOOKMARK_URL) != b.Get(syncable::BOOKMARK_URL))
823 return true; 801 return true;
824 if (a.ref(syncable::BOOKMARK_FAVICON) != b.Get(syncable::BOOKMARK_FAVICON)) 802 if (a.ref(syncable::BOOKMARK_FAVICON) != b.Get(syncable::BOOKMARK_FAVICON))
825 return true; 803 return true;
826 if (BookmarkPositionsDiffer(a, b)) 804 if (BookmarkPositionsDiffer(a, b))
827 return true; 805 return true;
828 return false; 806 return false;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 BaseTransaction::~BaseTransaction() { 1508 BaseTransaction::~BaseTransaction() {
1531 delete lookup_; 1509 delete lookup_;
1532 } 1510 }
1533 1511
1534 UserShare* SyncManager::GetUserShare() const { 1512 UserShare* SyncManager::GetUserShare() const {
1535 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; 1513 DCHECK(data_->initialized()) << "GetUserShare requires initialization!";
1536 return data_->GetUserShare(); 1514 return data_->GetUserShare();
1537 } 1515 }
1538 1516
1539 } // namespace sync_api 1517 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/process_updates_command.cc ('k') | chrome/browser/sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698