| 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/chromeos/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 6 | 6 |
| 7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 ++max_modifier)); | 319 ++max_modifier)); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 entry->set_base_name(full_file_name.value()); | 322 entry->set_base_name(full_file_name.value()); |
| 323 | 323 |
| 324 DVLOG(1) << "AddEntry: dir = " << GetFilePath().value() | 324 DVLOG(1) << "AddEntry: dir = " << GetFilePath().value() |
| 325 << ", file = " + entry->base_name() | 325 << ", file = " + entry->base_name() |
| 326 << ", parent resource = " << entry->parent_resource_id() | 326 << ", parent resource = " << entry->parent_resource_id() |
| 327 << ", resource = " + entry->resource_id(); | 327 << ", resource = " + entry->resource_id(); |
| 328 | 328 |
| 329 | |
| 330 // Add entry to resource map. | 329 // Add entry to resource map. |
| 331 if (directory_service_) | 330 if (directory_service_) |
| 332 directory_service_->AddEntryToResourceMap(entry); | 331 directory_service_->AddEntryToResourceMap(entry); |
| 333 | 332 |
| 334 // Setup child and parent links. | 333 // Setup child and parent links. |
| 335 AddChild(entry); | 334 AddChild(entry); |
| 336 entry->SetParent(this); | 335 entry->SetParent(this); |
| 337 } | 336 } |
| 338 | 337 |
| 339 bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) { | 338 bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 546 |
| 548 // GDataDirectoryService class implementation. | 547 // GDataDirectoryService class implementation. |
| 549 | 548 |
| 550 GDataDirectoryService::GDataDirectoryService() | 549 GDataDirectoryService::GDataDirectoryService() |
| 551 : blocking_task_runner_(NULL), | 550 : blocking_task_runner_(NULL), |
| 552 serialized_size_(0), | 551 serialized_size_(0), |
| 553 largest_changestamp_(0), | 552 largest_changestamp_(0), |
| 554 origin_(UNINITIALIZED), | 553 origin_(UNINITIALIZED), |
| 555 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 554 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 556 root_.reset(new GDataDirectory(NULL, this)); | 555 root_.reset(new GDataDirectory(NULL, this)); |
| 557 root_->set_title(kGDataRootDirectory); | 556 if (!util::IsDriveV2ApiEnabled()) |
| 558 root_->SetBaseNameFromTitle(); | 557 InitializeRootEntry(kGDataRootDirectoryResourceId); |
| 559 root_->set_resource_id(kGDataRootDirectoryResourceId); | |
| 560 AddEntryToResourceMap(root_.get()); | |
| 561 } | 558 } |
| 562 | 559 |
| 563 GDataDirectoryService::~GDataDirectoryService() { | 560 GDataDirectoryService::~GDataDirectoryService() { |
| 564 ClearRoot(); | 561 ClearRoot(); |
| 565 | 562 |
| 566 // Ensure db is closed on the blocking pool. | 563 // Ensure db is closed on the blocking pool. |
| 567 if (blocking_task_runner_ && directory_service_db_.get()) | 564 if (blocking_task_runner_ && directory_service_db_.get()) |
| 568 blocking_task_runner_->DeleteSoon(FROM_HERE, | 565 blocking_task_runner_->DeleteSoon(FROM_HERE, |
| 569 directory_service_db_.release()); | 566 directory_service_db_.release()); |
| 570 } | 567 } |
| 571 | 568 |
| 569 void GDataDirectoryService::InitializeRootEntry(const std::string& root_id) { |
| 570 root_.reset(new GDataDirectory(NULL, this)); |
| 571 root_->set_title(kGDataRootDirectory); |
| 572 root_->SetBaseNameFromTitle(); |
| 573 root_->set_resource_id(root_id); |
| 574 AddEntryToResourceMap(root_.get()); |
| 575 } |
| 576 |
| 572 void GDataDirectoryService::ClearRoot() { | 577 void GDataDirectoryService::ClearRoot() { |
| 573 // Note that children have a reference to root_, | 578 // Note that children have a reference to root_, |
| 574 // so we need to delete them here. | 579 // so we need to delete them here. |
| 575 root_->RemoveChildren(); | 580 root_->RemoveChildren(); |
| 576 RemoveEntryFromResourceMap(root_.get()); | 581 RemoveEntryFromResourceMap(root_.get()); |
| 577 DCHECK(resource_map_.empty()); | 582 DCHECK(resource_map_.empty()); |
| 578 resource_map_.clear(); | 583 resource_map_.clear(); |
| 579 root_.reset(); | 584 root_.reset(); |
| 580 } | 585 } |
| 581 | 586 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 version != kProtoVersion) { | 811 version != kProtoVersion) { |
| 807 if (!callback.is_null()) | 812 if (!callback.is_null()) |
| 808 callback.Run(GDATA_FILE_ERROR_FAILED); | 813 callback.Run(GDATA_FILE_ERROR_FAILED); |
| 809 return; | 814 return; |
| 810 } | 815 } |
| 811 serialized_resources->erase(iter); | 816 serialized_resources->erase(iter); |
| 812 | 817 |
| 813 // Get the largest changestamp. | 818 // Get the largest changestamp. |
| 814 iter = serialized_resources->find(kDBKeyLargestChangestamp); | 819 iter = serialized_resources->find(kDBKeyLargestChangestamp); |
| 815 if (iter == serialized_resources->end() || | 820 if (iter == serialized_resources->end() || |
| 816 !base::StringToInt(iter->second, &largest_changestamp_)) { | 821 !base::StringToInt64(iter->second, &largest_changestamp_)) { |
| 817 NOTREACHED() << "Could not find/parse largest_changestamp"; | 822 NOTREACHED() << "Could not find/parse largest_changestamp"; |
| 818 if (!callback.is_null()) | 823 if (!callback.is_null()) |
| 819 callback.Run(GDATA_FILE_ERROR_FAILED); | 824 callback.Run(GDATA_FILE_ERROR_FAILED); |
| 820 return; | 825 return; |
| 821 } else { | 826 } else { |
| 822 DVLOG(1) << "InitResourceMap largest_changestamp_" << largest_changestamp_; | 827 DVLOG(1) << "InitResourceMap largest_changestamp_" << largest_changestamp_; |
| 823 serialized_resources->erase(iter); | 828 serialized_resources->erase(iter); |
| 824 } | 829 } |
| 825 | 830 |
| 826 ResourceMap resource_map; | 831 ResourceMap resource_map; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 DCHECK(result.get()); | 1217 DCHECK(result.get()); |
| 1213 | 1218 |
| 1214 result->second.path = second_path; | 1219 result->second.path = second_path; |
| 1215 result->second.error = error; | 1220 result->second.error = error; |
| 1216 result->second.proto = entry_proto.Pass(); | 1221 result->second.proto = entry_proto.Pass(); |
| 1217 | 1222 |
| 1218 callback.Run(result.Pass()); | 1223 callback.Run(result.Pass()); |
| 1219 } | 1224 } |
| 1220 | 1225 |
| 1221 } // namespace gdata | 1226 } // namespace gdata |
| OLD | NEW |