| 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/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 callback.Run(result->error, result->entries.Pass()); | 224 callback.Run(result->error, result->entries.Pass()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 DriveFileError error; | 227 DriveFileError error; |
| 228 scoped_ptr<DriveEntryProtoVector> entries; | 228 scoped_ptr<DriveEntryProtoVector> entries; |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 // DriveResourceMetadata class implementation. | 231 // DriveResourceMetadata class implementation. |
| 232 | 232 |
| 233 DriveResourceMetadata::DriveResourceMetadata( | 233 DriveResourceMetadata::DriveResourceMetadata( |
| 234 const std::string& root_resource_id, | |
| 235 const base::FilePath& data_directory_path, | 234 const base::FilePath& data_directory_path, |
| 236 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | 235 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
| 237 : data_directory_path_(data_directory_path), | 236 : data_directory_path_(data_directory_path), |
| 238 blocking_task_runner_(blocking_task_runner), | 237 blocking_task_runner_(blocking_task_runner), |
| 239 storage_(new DriveResourceMetadataStorageDB(data_directory_path)), | 238 storage_(new DriveResourceMetadataStorageDB(data_directory_path)), |
| 240 root_resource_id_(root_resource_id), | |
| 241 serialized_size_(0), | 239 serialized_size_(0), |
| 242 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 240 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 244 } | 242 } |
| 245 | 243 |
| 246 void DriveResourceMetadata::Initialize(const FileOperationCallback& callback) { | 244 void DriveResourceMetadata::Initialize(const FileOperationCallback& callback) { |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 248 DCHECK(!callback.is_null()); | 246 DCHECK(!callback.is_null()); |
| 249 | 247 |
| 250 base::PostTaskAndReplyWithResult( | 248 base::PostTaskAndReplyWithResult( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 SetUpDefaultEntries(); | 294 SetUpDefaultEntries(); |
| 297 | 295 |
| 298 return DRIVE_FILE_OK; | 296 return DRIVE_FILE_OK; |
| 299 } | 297 } |
| 300 | 298 |
| 301 void DriveResourceMetadata::SetUpDefaultEntries() { | 299 void DriveResourceMetadata::SetUpDefaultEntries() { |
| 302 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 300 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 303 | 301 |
| 304 // Initialize the grand root and "other" entries. "/drive" and "/drive/other". | 302 // Initialize the grand root and "other" entries. "/drive" and "/drive/other". |
| 305 // As an intermediate change, "/drive/root" is also added here. | 303 // As an intermediate change, "/drive/root" is also added here. |
| 306 // TODO(haruki): Move this initialization to change_list_loader where we | |
| 307 // can retrieve the root folder ID from the server. | |
| 308 if (!storage_->GetEntry(util::kDriveGrandRootSpecialResourceId)) { | 304 if (!storage_->GetEntry(util::kDriveGrandRootSpecialResourceId)) { |
| 309 DriveEntryProto root; | 305 DriveEntryProto root; |
| 310 root.mutable_file_info()->set_is_directory(true); | 306 root.mutable_file_info()->set_is_directory(true); |
| 311 root.set_resource_id(util::kDriveGrandRootSpecialResourceId); | 307 root.set_resource_id(util::kDriveGrandRootSpecialResourceId); |
| 312 root.set_title(util::kDriveGrandRootDirName); | 308 root.set_title(util::kDriveGrandRootDirName); |
| 313 storage_->PutEntry(CreateEntryWithProperBaseName(root)); | 309 storage_->PutEntry(CreateEntryWithProperBaseName(root)); |
| 314 } | 310 } |
| 315 if (!storage_->GetEntry(util::kDriveOtherDirSpecialResourceId)) { | 311 if (!storage_->GetEntry(util::kDriveOtherDirSpecialResourceId)) { |
| 316 DriveEntryProto other_dir; | 312 AddEntryToDirectory(util::CreateOtherDirEntry()); |
| 317 other_dir.mutable_file_info()->set_is_directory(true); | |
| 318 other_dir.set_resource_id(util::kDriveOtherDirSpecialResourceId); | |
| 319 other_dir.set_parent_resource_id(util::kDriveGrandRootSpecialResourceId); | |
| 320 other_dir.set_title(util::kDriveOtherDirName); | |
| 321 AddEntryToDirectory(other_dir); | |
| 322 } | |
| 323 if (!storage_->GetEntry(root_resource_id_)) { | |
| 324 DriveEntryProto mydrive_root; | |
| 325 mydrive_root.mutable_file_info()->set_is_directory(true); | |
| 326 mydrive_root.set_resource_id(root_resource_id_); | |
| 327 mydrive_root.set_parent_resource_id(util::kDriveGrandRootSpecialResourceId); | |
| 328 mydrive_root.set_title(util::kDriveMyDriveRootDirName); | |
| 329 AddEntryToDirectory(mydrive_root); | |
| 330 } | 313 } |
| 331 } | 314 } |
| 332 | 315 |
| 333 void DriveResourceMetadata::DestroyOnBlockingPool() { | 316 void DriveResourceMetadata::DestroyOnBlockingPool() { |
| 334 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 317 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 335 delete this; | 318 delete this; |
| 336 } | 319 } |
| 337 | 320 |
| 338 void DriveResourceMetadata::ResetOnBlockingPool() { | 321 void DriveResourceMetadata::ResetOnBlockingPool() { |
| 339 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 322 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 storage_->PutEntry( | 1204 storage_->PutEntry( |
| 1222 CreateEntryWithProperBaseName(proto.drive_directory().drive_entry())); | 1205 CreateEntryWithProperBaseName(proto.drive_directory().drive_entry())); |
| 1223 AddDescendantsFromProto(proto.drive_directory()); | 1206 AddDescendantsFromProto(proto.drive_directory()); |
| 1224 | 1207 |
| 1225 storage_->SetLargestChangestamp(proto.largest_changestamp()); | 1208 storage_->SetLargestChangestamp(proto.largest_changestamp()); |
| 1226 | 1209 |
| 1227 return true; | 1210 return true; |
| 1228 } | 1211 } |
| 1229 | 1212 |
| 1230 } // namespace drive | 1213 } // namespace drive |
| OLD | NEW |