OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/sync_file_system/drive_metadata_store.h" | 5 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 529 } |
530 | 530 |
531 bool DriveMetadataStore::IsOriginDisabled(const GURL& origin) const { | 531 bool DriveMetadataStore::IsOriginDisabled(const GURL& origin) const { |
532 DCHECK(CalledOnValidThread()); | 532 DCHECK(CalledOnValidThread()); |
533 return ContainsKey(disabled_origins_, origin); | 533 return ContainsKey(disabled_origins_, origin); |
534 } | 534 } |
535 | 535 |
536 void DriveMetadataStore::AddBatchSyncOrigin(const GURL& origin, | 536 void DriveMetadataStore::AddBatchSyncOrigin(const GURL& origin, |
537 const std::string& resource_id) { | 537 const std::string& resource_id) { |
538 DCHECK(CalledOnValidThread()); | 538 DCHECK(CalledOnValidThread()); |
539 DCHECK(!IsBatchSyncOrigin(origin)); | |
540 DCHECK(!IsIncrementalSyncOrigin(origin)); | 539 DCHECK(!IsIncrementalSyncOrigin(origin)); |
541 DCHECK(!IsOriginDisabled(origin)); | 540 DCHECK(!IsOriginDisabled(origin)); |
542 DCHECK_EQ(SYNC_STATUS_OK, db_status_); | 541 DCHECK_EQ(SYNC_STATUS_OK, db_status_); |
543 | 542 |
| 543 if (IsBatchSyncOrigin(origin)) |
| 544 return; |
| 545 |
544 batch_sync_origins_.insert(std::make_pair(origin, resource_id)); | 546 batch_sync_origins_.insert(std::make_pair(origin, resource_id)); |
545 origin_by_resource_id_.insert(std::make_pair(resource_id, origin)); | 547 origin_by_resource_id_.insert(std::make_pair(resource_id, origin)); |
546 | 548 |
547 // Store a pair of |origin| and |resource_id| in the DB. | 549 // Store a pair of |origin| and |resource_id| in the DB. |
548 base::PostTaskAndReplyWithResult( | 550 base::PostTaskAndReplyWithResult( |
549 file_task_runner_, FROM_HERE, | 551 file_task_runner_, FROM_HERE, |
550 base::Bind(&DriveMetadataDB::UpdateOriginAsBatchSync, | 552 base::Bind(&DriveMetadataDB::UpdateOriginAsBatchSync, |
551 base::Unretained(db_.get()), origin, resource_id), | 553 base::Unretained(db_.get()), origin, resource_id), |
552 base::Bind(&DriveMetadataStore::UpdateDBStatus, AsWeakPtr())); | 554 base::Bind(&DriveMetadataStore::UpdateDBStatus, AsWeakPtr())); |
553 } | 555 } |
(...skipping 25 matching lines...) Expand all Loading... |
579 DCHECK(CalledOnValidThread()); | 581 DCHECK(CalledOnValidThread()); |
580 | 582 |
581 std::map<GURL, std::string>::iterator found = disabled_origins_.find(origin); | 583 std::map<GURL, std::string>::iterator found = disabled_origins_.find(origin); |
582 if (found == disabled_origins_.end()) { | 584 if (found == disabled_origins_.end()) { |
583 // |origin| has not been registered yet. | 585 // |origin| has not been registered yet. |
584 return; | 586 return; |
585 } | 587 } |
586 std::string resource_id = found->second; | 588 std::string resource_id = found->second; |
587 disabled_origins_.erase(found); | 589 disabled_origins_.erase(found); |
588 | 590 |
589 // Ensure |origin| is marked as a batch sync origin. | 591 // |Origin| goes back to DriveFileSyncService.pending_batch_sync_origins_ |
590 batch_sync_origins_.insert(std::make_pair(origin, resource_id)); | 592 // only and is not stored in drive_metadata_store. |
591 found = incremental_sync_origins_.find(origin); | 593 found = incremental_sync_origins_.find(origin); |
592 if (found != incremental_sync_origins_.end()) | 594 if (found != incremental_sync_origins_.end()) |
593 incremental_sync_origins_.erase(found); | 595 incremental_sync_origins_.erase(found); |
594 | 596 |
595 // Store a pair of |origin| and |resource_id| in the DB. | 597 // Store a pair of |origin| and |resource_id| in the DB. |
596 base::PostTaskAndReplyWithResult( | 598 base::PostTaskAndReplyWithResult( |
597 file_task_runner_, FROM_HERE, | 599 file_task_runner_, FROM_HERE, |
598 base::Bind(&DriveMetadataDB::EnableOrigin, | 600 base::Bind(&DriveMetadataDB::EnableOrigin, |
599 base::Unretained(db_.get()), origin, resource_id), | 601 base::Unretained(db_.get()), origin, resource_id), |
600 base::Bind(&DriveMetadataStore::DidUpdateOrigin, AsWeakPtr(), callback)); | 602 base::Bind(&DriveMetadataStore::DidUpdateOrigin, AsWeakPtr(), callback)); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 DCHECK(origin.is_valid()); | 1181 DCHECK(origin.is_valid()); |
1180 bool result = disabled_origins->insert( | 1182 bool result = disabled_origins->insert( |
1181 std::make_pair(origin, itr->value().ToString())).second; | 1183 std::make_pair(origin, itr->value().ToString())).second; |
1182 DCHECK(result); | 1184 DCHECK(result); |
1183 } | 1185 } |
1184 | 1186 |
1185 return SYNC_STATUS_OK; | 1187 return SYNC_STATUS_OK; |
1186 } | 1188 } |
1187 | 1189 |
1188 } // namespace sync_file_system | 1190 } // namespace sync_file_system |
OLD | NEW |