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

Side by Side Diff: sync/syncable/directory.cc

Issue 582913002: Make GenericChangeProcessor upload attachments on startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 6 years, 3 months 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
« no previous file with comments | « sync/syncable/directory.h ('k') | sync/syncable/directory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "sync/syncable/directory.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include <algorithm>
7 #include <iterator> 8 #include <iterator>
8 9
9 #include "base/base64.h" 10 #include "base/base64.h"
10 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "sync/internal_api/public/base/attachment_id_proto.h" 14 #include "sync/internal_api/public/base/attachment_id_proto.h"
14 #include "sync/internal_api/public/base/unique_position.h" 15 #include "sync/internal_api/public/base/unique_position.h"
15 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 16 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
16 #include "sync/syncable/entry.h" 17 #include "sync/syncable/entry.h"
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 std::copy(kernel_->unapplied_update_metahandles[type].begin(), 1057 std::copy(kernel_->unapplied_update_metahandles[type].begin(),
1057 kernel_->unapplied_update_metahandles[type].end(), 1058 kernel_->unapplied_update_metahandles[type].end(),
1058 back_inserter(*result)); 1059 back_inserter(*result));
1059 } 1060 }
1060 } 1061 }
1061 } 1062 }
1062 1063
1063 void Directory::GetMetaHandlesOfType(BaseTransaction* trans, 1064 void Directory::GetMetaHandlesOfType(BaseTransaction* trans,
1064 ModelType type, 1065 ModelType type,
1065 std::vector<int64>* result) { 1066 std::vector<int64>* result) {
1067 ScopedKernelLock lock(this);
1068 GetMetaHandlesOfType(lock, trans, type, result);
1069 }
1070
1071 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock,
1072 BaseTransaction* trans,
1073 ModelType type,
1074 std::vector<int64>* result) {
1066 result->clear(); 1075 result->clear();
1067 ScopedKernelLock lock(this);
1068 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); 1076 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin();
1069 it != kernel_->metahandles_map.end(); ++it) { 1077 it != kernel_->metahandles_map.end(); ++it) {
1070 EntryKernel* entry = it->second; 1078 EntryKernel* entry = it->second;
1071 const ModelType entry_type = 1079 const ModelType entry_type =
1072 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); 1080 GetModelTypeFromSpecifics(entry->ref(SPECIFICS));
1073 if (entry_type == type) 1081 if (entry_type == type)
1074 result->push_back(it->first); 1082 result->push_back(it->first);
1075 } 1083 }
1076 } 1084 }
1077 1085
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); 1471 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID));
1464 result->push_back((*i)->ref(META_HANDLE)); 1472 result->push_back((*i)->ref(META_HANDLE));
1465 } 1473 }
1466 } 1474 }
1467 1475
1468 void Directory::UnmarkDirtyEntry(WriteTransaction* trans, Entry* entry) { 1476 void Directory::UnmarkDirtyEntry(WriteTransaction* trans, Entry* entry) {
1469 CHECK(trans); 1477 CHECK(trans);
1470 entry->kernel_->clear_dirty(&kernel_->dirty_metahandles); 1478 entry->kernel_->clear_dirty(&kernel_->dirty_metahandles);
1471 } 1479 }
1472 1480
1481 void Directory::GetAttachmentIdsToUpload(BaseTransaction* trans,
1482 ModelType type,
1483 AttachmentIdSet* id_set) {
1484 // TODO(maniscalco): Maintain an index by ModelType and rewrite this method to
1485 // use it. The approach below is likely very expensive because it iterates
1486 // all entries (bug 415199).
1487 DCHECK(trans);
1488 DCHECK(id_set);
1489 id_set->clear();
1490 AttachmentIdSet on_server_id_set;
1491 AttachmentIdSet not_on_server_id_set;
1492 std::vector<int64> metahandles;
1493 {
1494 ScopedKernelLock lock(this);
1495 GetMetaHandlesOfType(lock, trans, type, &metahandles);
1496 std::vector<int64>::const_iterator iter = metahandles.begin();
1497 const std::vector<int64>::const_iterator end = metahandles.end();
1498 // For all of this type's entries...
1499 for (; iter != end; ++iter) {
1500 EntryKernel* entry = GetEntryByHandle(*iter, &lock);
1501 DCHECK(entry);
1502 const sync_pb::AttachmentMetadata metadata =
1503 entry->ref(ATTACHMENT_METADATA);
1504 // for each of this entry's attachments...
1505 for (int i = 0; i < metadata.record_size(); ++i) {
1506 AttachmentId id =
1507 AttachmentId::CreateFromProto(metadata.record(i).id());
1508 // if this attachment is known to be on the server, remember it for
1509 // later,
1510 if (metadata.record(i).is_on_server()) {
1511 on_server_id_set.insert(id);
1512 } else {
1513 // otherwise, add it to id_set.
1514 not_on_server_id_set.insert(id);
1515 }
1516 }
1517 }
1518 }
1519 // Why did we bother keeping a set of ids known to be on the server? The
1520 // is_on_server flag is stored denormalized so we can end up with two entries
1521 // with the same attachment id where one says it's on the server and the other
1522 // says it's not. When this happens, we trust the one that says it's on the
1523 // server. To avoid re-uploading the same attachment mulitple times, we
1524 // remove any ids known to be on the server from the id_set we are about to
1525 // return.
1526 //
1527 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203).
1528 std::set_difference(not_on_server_id_set.begin(),
1529 not_on_server_id_set.end(),
1530 on_server_id_set.begin(),
1531 on_server_id_set.end(),
1532 std::inserter(*id_set, id_set->end()));
1533 }
1534
1473 } // namespace syncable 1535 } // namespace syncable
1474 } // namespace syncer 1536 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory.h ('k') | sync/syncable/directory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698