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

Side by Side Diff: components/sync/syncable/directory_backing_store.cc

Issue 2502253003: [Sync] Move GenerateSyncableHash to base. (Closed)
Patch Set: Keep full syncable/ DEP. Created 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/sync/syncable/directory_backing_store.h" 5 #include "components/sync/syncable/directory_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <unordered_set> 10 #include <unordered_set>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/base64.h" 13 #include "base/base64.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/rand_util.h" 18 #include "base/rand_util.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "components/sync/base/hash_util.h"
25 #include "components/sync/base/node_ordinal.h" 26 #include "components/sync/base/node_ordinal.h"
26 #include "components/sync/base/time.h" 27 #include "components/sync/base/time.h"
27 #include "components/sync/protocol/bookmark_specifics.pb.h" 28 #include "components/sync/protocol/bookmark_specifics.pb.h"
28 #include "components/sync/protocol/sync.pb.h" 29 #include "components/sync/protocol/sync.pb.h"
29 #include "components/sync/syncable/syncable_columns.h" 30 #include "components/sync/syncable/syncable_columns.h"
30 #include "components/sync/syncable/syncable_id.h" 31 #include "components/sync/syncable/syncable_id.h"
31 #include "components/sync/syncable/syncable_util.h"
32 #include "sql/error_delegate_util.h" 32 #include "sql/error_delegate_util.h"
33 #include "sql/transaction.h" 33 #include "sql/transaction.h"
34 34
35 using std::string; 35 using std::string;
36 36
37 namespace syncer { 37 namespace syncer {
38 namespace syncable { 38 namespace syncable {
39 39
40 // Increment this version whenever updating DB tables. 40 // Increment this version whenever updating DB tables.
41 const int32_t kCurrentDBVersion = 90; 41 const int32_t kCurrentDBVersion = 90;
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 // We only maintain positions for bookmarks that are not server-defined 1377 // We only maintain positions for bookmarks that are not server-defined
1378 // top-level folders. 1378 // top-level folders.
1379 UniquePosition position; 1379 UniquePosition position;
1380 if (GetModelTypeFromSpecifics(specifics) == BOOKMARKS 1380 if (GetModelTypeFromSpecifics(specifics) == BOOKMARKS
1381 && !(is_dir && !server_unique_tag.empty())) { 1381 && !(is_dir && !server_unique_tag.empty())) {
1382 if (id_string.at(0) == 'c') { 1382 if (id_string.at(0) == 'c') {
1383 // We found an uncommitted item. This is rare, but fortunate. This 1383 // We found an uncommitted item. This is rare, but fortunate. This
1384 // means we can set the bookmark tag according to the originator client 1384 // means we can set the bookmark tag according to the originator client
1385 // item ID and originator cache guid, because (unlike the other case) we 1385 // item ID and originator cache guid, because (unlike the other case) we
1386 // know that this client is the originator. 1386 // know that this client is the originator.
1387 unique_bookmark_tag = syncable::GenerateSyncableBookmarkHash( 1387 unique_bookmark_tag =
1388 cache_guid, 1388 GenerateSyncableBookmarkHash(cache_guid, id_string.substr(1));
1389 id_string.substr(1));
1390 } else { 1389 } else {
1391 // If we've already committed the item, then we don't know who the 1390 // If we've already committed the item, then we don't know who the
1392 // originator was. We do not have access to the originator client item 1391 // originator was. We do not have access to the originator client item
1393 // ID and originator cache guid at this point. 1392 // ID and originator cache guid at this point.
1394 // 1393 //
1395 // We will base our hash entirely on the server ID instead. This is 1394 // We will base our hash entirely on the server ID instead. This is
1396 // incorrect, but at least all clients that undergo this migration step 1395 // incorrect, but at least all clients that undergo this migration step
1397 // will be incorrect in the same way. 1396 // will be incorrect in the same way.
1398 // 1397 //
1399 // To get everyone back into a synced state, we will update the bookmark 1398 // To get everyone back into a synced state, we will update the bookmark
1400 // tag according to the originator_cache_guid and originator_item_id 1399 // tag according to the originator_cache_guid and originator_item_id
1401 // when we see updates for this item. That should ensure that commonly 1400 // when we see updates for this item. That should ensure that commonly
1402 // modified items will end up with the proper tag values eventually. 1401 // modified items will end up with the proper tag values eventually.
1403 unique_bookmark_tag = syncable::GenerateSyncableBookmarkHash( 1402 unique_bookmark_tag = GenerateSyncableBookmarkHash(
1404 std::string(), // cache_guid left intentionally blank. 1403 std::string(), // cache_guid left intentionally blank.
1405 id_string.substr(1)); 1404 id_string.substr(1));
1406 } 1405 }
1407 1406
1408 int64_t int_position = NodeOrdinalToInt64(ordinal); 1407 int64_t int_position = NodeOrdinalToInt64(ordinal);
1409 position = UniquePosition::FromInt64(int_position, unique_bookmark_tag); 1408 position = UniquePosition::FromInt64(int_position, unique_bookmark_tag);
1410 } else { 1409 } else {
1411 // Leave bookmark_tag and position at their default (invalid) values. 1410 // Leave bookmark_tag and position at their default (invalid) values.
1412 } 1411 }
1413 1412
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 DCHECK(CalledOnValidThread()); 1760 DCHECK(CalledOnValidThread());
1762 DCHECK(!catastrophic_error_handler.is_null()); 1761 DCHECK(!catastrophic_error_handler.is_null());
1763 catastrophic_error_handler_ = catastrophic_error_handler; 1762 catastrophic_error_handler_ = catastrophic_error_handler;
1764 sql::Connection::ErrorCallback error_callback = 1763 sql::Connection::ErrorCallback error_callback =
1765 base::Bind(&OnSqliteError, catastrophic_error_handler_); 1764 base::Bind(&OnSqliteError, catastrophic_error_handler_);
1766 db_->set_error_callback(error_callback); 1765 db_->set_error_callback(error_callback);
1767 } 1766 }
1768 1767
1769 } // namespace syncable 1768 } // namespace syncable
1770 } // namespace syncer 1769 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model_impl/shared_model_type_processor.cc ('k') | components/sync/syncable/model_neutral_mutable_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698