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

Side by Side Diff: chrome/browser/chromeos/drive/drive_resource_metadata.cc

Issue 11227020: Set root resource ID upon full feed update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a comment. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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/drive/drive_resource_metadata.h" 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h"
6 6
7 #include <leveldb/db.h> 7 #include <leveldb/db.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 // DriveResourceMetadata class implementation. 180 // DriveResourceMetadata class implementation.
181 181
182 DriveResourceMetadata::DriveResourceMetadata() 182 DriveResourceMetadata::DriveResourceMetadata()
183 : blocking_task_runner_(NULL), 183 : blocking_task_runner_(NULL),
184 serialized_size_(0), 184 serialized_size_(0),
185 largest_changestamp_(0), 185 largest_changestamp_(0),
186 origin_(UNINITIALIZED), 186 origin_(UNINITIALIZED),
187 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 187 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
188 root_ = CreateDriveDirectory().Pass();
189 if (!google_apis::util::IsDriveV2ApiEnabled())
190 InitializeRootEntry(kDriveRootDirectoryResourceId);
191 } 188 }
192 189
193 DriveResourceMetadata::~DriveResourceMetadata() { 190 DriveResourceMetadata::~DriveResourceMetadata() {
194 ClearRoot(); 191 ClearRoot();
195 192
196 // Ensure db is closed on the blocking pool. 193 // Ensure db is closed on the blocking pool.
197 if (blocking_task_runner_ && resource_metadata_db_.get()) 194 if (blocking_task_runner_ && resource_metadata_db_.get())
198 blocking_task_runner_->DeleteSoon(FROM_HERE, 195 blocking_task_runner_->DeleteSoon(FROM_HERE,
199 resource_metadata_db_.release()); 196 resource_metadata_db_.release());
200 } 197 }
(...skipping 13 matching lines...) Expand all
214 211
215 scoped_ptr<DriveFile> DriveResourceMetadata::CreateDriveFile() { 212 scoped_ptr<DriveFile> DriveResourceMetadata::CreateDriveFile() {
216 return scoped_ptr<DriveFile>(new DriveFile(this)); 213 return scoped_ptr<DriveFile>(new DriveFile(this));
217 } 214 }
218 215
219 scoped_ptr<DriveDirectory> DriveResourceMetadata::CreateDriveDirectory() { 216 scoped_ptr<DriveDirectory> DriveResourceMetadata::CreateDriveDirectory() {
220 return scoped_ptr<DriveDirectory>(new DriveDirectory(this)); 217 return scoped_ptr<DriveDirectory>(new DriveDirectory(this));
221 } 218 }
222 219
223 void DriveResourceMetadata::InitializeRootEntry(const std::string& root_id) { 220 void DriveResourceMetadata::InitializeRootEntry(const std::string& root_id) {
221 DCHECK(saved_root_resource_id_.empty());
222 saved_root_resource_id_ = root_id;
satorux1 2012/10/23 06:54:50 do we need this? I think we can get the same value
kochi 2012/10/23 07:44:35 This was introduced to keep the root resource ID f
224 root_ = CreateDriveDirectory().Pass(); 223 root_ = CreateDriveDirectory().Pass();
225 root_->set_title(kDriveRootDirectory); 224 root_->set_title(kDriveRootDirectory);
226 root_->SetBaseNameFromTitle(); 225 root_->SetBaseNameFromTitle();
227 root_->set_resource_id(root_id); 226 root_->set_resource_id(root_id);
228 AddEntryToResourceMap(root_.get()); 227 AddEntryToResourceMap(root_.get());
229 } 228 }
230 229
231 void DriveResourceMetadata::ClearRoot() { 230 void DriveResourceMetadata::ClearRoot() {
232 if (!root_.get()) 231 if (!root_.get())
233 return; 232 return;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 MoveEntryToDirectory(file_path, entry->parent()->GetFilePath(), callback); 345 MoveEntryToDirectory(file_path, entry->parent()->GetFilePath(), callback);
347 } 346 }
348 347
349 void DriveResourceMetadata::RemoveEntryFromParent( 348 void DriveResourceMetadata::RemoveEntryFromParent(
350 const std::string& resource_id, 349 const std::string& resource_id,
351 const FileMoveCallback& callback) { 350 const FileMoveCallback& callback) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
353 DCHECK(!callback.is_null()); 352 DCHECK(!callback.is_null());
354 353
355 // Disallow deletion of root. 354 // Disallow deletion of root.
356 if (resource_id == kDriveRootDirectoryResourceId) { 355 if (resource_id == root_->resource_id()) {
357 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_ACCESS_DENIED); 356 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_ACCESS_DENIED);
358 return; 357 return;
359 } 358 }
360 359
361 DriveEntry* entry = GetEntryByResourceId(resource_id); 360 DriveEntry* entry = GetEntryByResourceId(resource_id);
362 if (!entry) { 361 if (!entry) {
363 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND); 362 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND);
364 return; 363 return;
365 } 364 }
366 365
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 603 }
605 604
606 void DriveResourceMetadata::InitFromDB( 605 void DriveResourceMetadata::InitFromDB(
607 const FilePath& db_path, 606 const FilePath& db_path,
608 base::SequencedTaskRunner* blocking_task_runner, 607 base::SequencedTaskRunner* blocking_task_runner,
609 const FileOperationCallback& callback) { 608 const FileOperationCallback& callback) {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
611 DCHECK(!db_path.empty()); 610 DCHECK(!db_path.empty());
612 DCHECK(blocking_task_runner); 611 DCHECK(blocking_task_runner);
613 DCHECK(!callback.is_null()); 612 DCHECK(!callback.is_null());
613 DCHECK(!saved_root_resource_id_.empty());
614 614
615 if (resource_metadata_db_.get()) { 615 if (resource_metadata_db_.get()) {
616 callback.Run(DRIVE_FILE_ERROR_IN_USE); 616 callback.Run(DRIVE_FILE_ERROR_IN_USE);
617 return; 617 return;
618 } 618 }
619 619
620 blocking_task_runner_ = blocking_task_runner; 620 blocking_task_runner_ = blocking_task_runner;
621 621
622 DVLOG(1) << "InitFromDB " << db_path.value(); 622 DVLOG(1) << "InitFromDB " << db_path.value();
623 623
(...skipping 10 matching lines...) Expand all
634 } 634 }
635 635
636 void DriveResourceMetadata::InitResourceMap( 636 void DriveResourceMetadata::InitResourceMap(
637 CreateDBParams* create_params, 637 CreateDBParams* create_params,
638 const FileOperationCallback& callback) { 638 const FileOperationCallback& callback) {
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
640 DCHECK(create_params); 640 DCHECK(create_params);
641 DCHECK(!resource_metadata_db_.get()); 641 DCHECK(!resource_metadata_db_.get());
642 DCHECK(!callback.is_null()); 642 DCHECK(!callback.is_null());
643 643
644
645 SerializedMap* serialized_resources = &create_params->serialized_resources; 644 SerializedMap* serialized_resources = &create_params->serialized_resources;
646 resource_metadata_db_ = create_params->db.Pass(); 645 resource_metadata_db_ = create_params->db.Pass();
647 if (serialized_resources->empty()) { 646 if (serialized_resources->empty()) {
648 origin_ = INITIALIZING; 647 origin_ = INITIALIZING;
649 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); 648 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND);
650 return; 649 return;
651 } 650 }
652 651
653 ClearRoot(); 652 ClearRoot();
654 653
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 resource_map.find(entry->parent_resource_id()); 702 resource_map.find(entry->parent_resource_id());
704 if (parent_it != resource_map.end()) { 703 if (parent_it != resource_map.end()) {
705 DriveDirectory* parent = parent_it->second->AsDriveDirectory(); 704 DriveDirectory* parent = parent_it->second->AsDriveDirectory();
706 if (parent) { 705 if (parent) {
707 DVLOG(1) << "Adding " << entry->resource_id() 706 DVLOG(1) << "Adding " << entry->resource_id()
708 << " as a child of " << parent->resource_id(); 707 << " as a child of " << parent->resource_id();
709 parent->AddEntry(entry); 708 parent->AddEntry(entry);
710 } else { 709 } else {
711 NOTREACHED() << "Parent is not a directory " << parent->resource_id(); 710 NOTREACHED() << "Parent is not a directory " << parent->resource_id();
712 } 711 }
713 } else if (entry->resource_id() == kDriveRootDirectoryResourceId) { 712 } else if (entry->resource_id() == saved_root_resource_id_) {
satorux1 2012/10/23 06:54:50 why not root_->resource_id() ?
kochi 2012/10/23 07:44:35 As mentioned in the previous comment. We already c
714 root_.reset(entry->AsDriveDirectory()); 713 root_.reset(entry->AsDriveDirectory());
715 DCHECK(root_.get()); 714 DCHECK(root_.get());
716 AddEntryToResourceMap(root_.get()); 715 AddEntryToResourceMap(root_.get());
717 } else { 716 } else {
718 NOTREACHED() << "Missing parent id " << entry->parent_resource_id() 717 NOTREACHED() << "Missing parent id " << entry->parent_resource_id()
719 << " for resource " << entry->resource_id(); 718 << " for resource " << entry->resource_id();
720 } 719 }
721 } 720 }
722 721
723 if (!root_.get()) { 722 if (!root_.get()) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 set_last_serialized(base::Time::Now()); 764 set_last_serialized(base::Time::Now());
766 set_serialized_size(serialized_size); 765 set_serialized_size(serialized_size);
767 766
768 blocking_task_runner_->PostTask( 767 blocking_task_runner_->PostTask(
769 FROM_HERE, 768 FROM_HERE,
770 base::Bind(&ResourceMetadataDB::Save, 769 base::Bind(&ResourceMetadataDB::Save,
771 base::Unretained(resource_metadata_db_.get()), 770 base::Unretained(resource_metadata_db_.get()),
772 serialized_resources)); 771 serialized_resources));
773 } 772 }
774 773
774 const std::string& DriveResourceMetadata::root_resource_id() const {
775 return root_->resource_id();
776 }
777
775 void DriveResourceMetadata::SerializeToString( 778 void DriveResourceMetadata::SerializeToString(
776 std::string* serialized_proto) const { 779 std::string* serialized_proto) const {
777 DriveRootDirectoryProto proto; 780 DriveRootDirectoryProto proto;
778 root_->ToProto(proto.mutable_drive_directory()); 781 root_->ToProto(proto.mutable_drive_directory());
779 proto.set_largest_changestamp(largest_changestamp_); 782 proto.set_largest_changestamp(largest_changestamp_);
780 proto.set_version(kProtoVersion); 783 proto.set_version(kProtoVersion);
781 784
782 const bool ok = proto.SerializeToString(serialized_proto); 785 const bool ok = proto.SerializeToString(serialized_proto);
783 DCHECK(ok); 786 DCHECK(ok);
784 } 787 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 DCHECK(result.get()); 868 DCHECK(result.get());
866 869
867 result->second.path = second_path; 870 result->second.path = second_path;
868 result->second.error = error; 871 result->second.error = error;
869 result->second.proto = entry_proto.Pass(); 872 result->second.proto = entry_proto.Pass();
870 873
871 callback.Run(result.Pass()); 874 callback.Run(result.Pass());
872 } 875 }
873 876
874 } // namespace drive 877 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698