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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 ++max_modifier)); | 307 ++max_modifier)); |
308 } | 308 } |
309 } | 309 } |
310 entry->set_base_name(full_file_name.value()); | 310 entry->set_base_name(full_file_name.value()); |
311 | 311 |
312 DVLOG(1) << "AddEntry: dir = " << GetFilePath().value() | 312 DVLOG(1) << "AddEntry: dir = " << GetFilePath().value() |
313 << ", file = " + entry->base_name() | 313 << ", file = " + entry->base_name() |
314 << ", parent resource = " << entry->parent_resource_id() | 314 << ", parent resource = " << entry->parent_resource_id() |
315 << ", resource = " + entry->resource_id(); | 315 << ", resource = " + entry->resource_id(); |
316 | 316 |
317 | |
318 // Add entry to resource map. | 317 // Add entry to resource map. |
319 if (directory_service_) | 318 if (directory_service_) |
320 directory_service_->AddEntryToResourceMap(entry); | 319 directory_service_->AddEntryToResourceMap(entry); |
321 | 320 |
322 // Setup child and parent links. | 321 // Setup child and parent links. |
323 AddChild(entry); | 322 AddChild(entry); |
324 entry->SetParent(this); | 323 entry->SetParent(this); |
325 } | 324 } |
326 | 325 |
327 bool GDataDirectory::TakeEntry(GDataEntry* entry) { | 326 bool GDataDirectory::TakeEntry(GDataEntry* entry) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 | 544 |
546 // GDataDirectoryService class implementation. | 545 // GDataDirectoryService class implementation. |
547 | 546 |
548 GDataDirectoryService::GDataDirectoryService() | 547 GDataDirectoryService::GDataDirectoryService() |
549 : blocking_task_runner_(NULL), | 548 : blocking_task_runner_(NULL), |
550 serialized_size_(0), | 549 serialized_size_(0), |
551 largest_changestamp_(0), | 550 largest_changestamp_(0), |
552 origin_(UNINITIALIZED), | 551 origin_(UNINITIALIZED), |
553 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 552 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
554 root_.reset(new GDataDirectory(NULL, this)); | 553 root_.reset(new GDataDirectory(NULL, this)); |
555 root_->set_title(kGDataRootDirectory); | 554 if (!util::IsDriveV2ApiEnabled()) |
556 root_->SetBaseNameFromTitle(); | 555 SetRootResourceId(kGDataRootDirectoryResourceId); |
satorux1
2012/08/08 13:18:51
The function name looks wrong. Here, we are doing
kochi
2012/08/08 16:53:27
Nope, I introduced the function as Drive v2 uses a
| |
557 root_->set_resource_id(kGDataRootDirectoryResourceId); | |
558 AddEntryToResourceMap(root_.get()); | |
559 } | 556 } |
560 | 557 |
561 GDataDirectoryService::~GDataDirectoryService() { | 558 GDataDirectoryService::~GDataDirectoryService() { |
562 ClearRoot(); | 559 ClearRoot(); |
563 | 560 |
564 // Ensure db is closed on the blocking pool. | 561 // Ensure db is closed on the blocking pool. |
565 if (blocking_task_runner_ && directory_service_db_.get()) | 562 if (blocking_task_runner_ && directory_service_db_.get()) |
566 blocking_task_runner_->DeleteSoon(FROM_HERE, | 563 blocking_task_runner_->DeleteSoon(FROM_HERE, |
567 directory_service_db_.release()); | 564 directory_service_db_.release()); |
568 } | 565 } |
569 | 566 |
567 void GDataDirectoryService::SetRootResourceId(const std::string& root_id) { | |
568 root_.reset(new GDataDirectory(NULL, this)); | |
569 root_->set_title(kGDataRootDirectory); | |
570 root_->SetBaseNameFromTitle(); | |
571 root_->set_resource_id(root_id); | |
572 AddEntryToResourceMap(root_.get()); | |
573 } | |
574 | |
570 void GDataDirectoryService::ClearRoot() { | 575 void GDataDirectoryService::ClearRoot() { |
571 // Note that children have a reference to root_, | 576 // Note that children have a reference to root_, |
572 // so we need to delete them here. | 577 // so we need to delete them here. |
573 root_->RemoveChildren(); | 578 root_->RemoveChildren(); |
574 RemoveEntryFromResourceMap(root_.get()); | 579 RemoveEntryFromResourceMap(root_.get()); |
575 DCHECK(resource_map_.empty()); | 580 DCHECK(resource_map_.empty()); |
576 resource_map_.clear(); | 581 resource_map_.clear(); |
577 root_.reset(); | 582 root_.reset(); |
578 } | 583 } |
579 | 584 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 version != kProtoVersion) { | 737 version != kProtoVersion) { |
733 if (!callback.is_null()) | 738 if (!callback.is_null()) |
734 callback.Run(GDATA_FILE_ERROR_FAILED); | 739 callback.Run(GDATA_FILE_ERROR_FAILED); |
735 return; | 740 return; |
736 } | 741 } |
737 serialized_resources->erase(iter); | 742 serialized_resources->erase(iter); |
738 | 743 |
739 // Get the largest changestamp. | 744 // Get the largest changestamp. |
740 iter = serialized_resources->find(kDBKeyLargestChangestamp); | 745 iter = serialized_resources->find(kDBKeyLargestChangestamp); |
741 if (iter == serialized_resources->end() || | 746 if (iter == serialized_resources->end() || |
742 !base::StringToInt(iter->second, &largest_changestamp_)) { | 747 !base::StringToInt64(iter->second, &largest_changestamp_)) { |
743 NOTREACHED() << "Could not find/parse largest_changestamp"; | 748 NOTREACHED() << "Could not find/parse largest_changestamp"; |
744 if (!callback.is_null()) | 749 if (!callback.is_null()) |
745 callback.Run(GDATA_FILE_ERROR_FAILED); | 750 callback.Run(GDATA_FILE_ERROR_FAILED); |
746 return; | 751 return; |
747 } else { | 752 } else { |
748 DVLOG(1) << "InitResourceMap largest_changestamp_" << largest_changestamp_; | 753 DVLOG(1) << "InitResourceMap largest_changestamp_" << largest_changestamp_; |
749 serialized_resources->erase(iter); | 754 serialized_resources->erase(iter); |
750 } | 755 } |
751 | 756 |
752 ResourceMap resource_map; | 757 ResourceMap resource_map; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1038 return false; | 1043 return false; |
1039 } | 1044 } |
1040 | 1045 |
1041 if (!IsValidRootDirectoryProto(proto.gdata_directory())) | 1046 if (!IsValidRootDirectoryProto(proto.gdata_directory())) |
1042 return false; | 1047 return false; |
1043 | 1048 |
1044 if (!root_->FromProto(proto.gdata_directory())) | 1049 if (!root_->FromProto(proto.gdata_directory())) |
1045 return false; | 1050 return false; |
1046 | 1051 |
1047 origin_ = FROM_CACHE; | 1052 origin_ = FROM_CACHE; |
1048 largest_changestamp_ = proto.largest_changestamp(); | 1053 largest_changestamp_ = proto.largest_changestamp(); |
satorux1
2012/08/08 13:18:51
Because you made an incompatible change in gdata.p
kochi
2012/08/08 16:53:27
Done.
| |
1049 | 1054 |
1050 return true; | 1055 return true; |
1051 } | 1056 } |
1052 | 1057 |
1053 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( | 1058 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( |
1054 const std::string& serialized_proto) { | 1059 const std::string& serialized_proto) { |
1055 GDataEntryProto entry_proto; | 1060 GDataEntryProto entry_proto; |
1056 if (!entry_proto.ParseFromString(serialized_proto)) | 1061 if (!entry_proto.ParseFromString(serialized_proto)) |
1057 return scoped_ptr<GDataEntry>(); | 1062 return scoped_ptr<GDataEntry>(); |
1058 | 1063 |
(...skipping 12 matching lines...) Expand all Loading... | |
1071 if (file->FromProto(entry_proto)) { | 1076 if (file->FromProto(entry_proto)) { |
1072 entry.reset(file.release()); | 1077 entry.reset(file.release()); |
1073 } else { | 1078 } else { |
1074 NOTREACHED() << "FromProto (file) failed"; | 1079 NOTREACHED() << "FromProto (file) failed"; |
1075 } | 1080 } |
1076 } | 1081 } |
1077 return entry.Pass(); | 1082 return entry.Pass(); |
1078 } | 1083 } |
1079 | 1084 |
1080 } // namespace gdata | 1085 } // namespace gdata |
OLD | NEW |