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

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

Issue 13866009: Remove root resource id aliasing from DriveResourceMetadata. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix JS comment. Created 7 years, 8 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/change_list_loader.h" 5 #include "chrome/browser/chromeos/drive/change_list_loader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return; 180 return;
181 } 181 }
182 182
183 if (directory_fetch_info.empty()) { 183 if (directory_fetch_info.empty()) {
184 // If the caller is not interested in a particular directory, just start 184 // If the caller is not interested in a particular directory, just start
185 // loading the change list. 185 // loading the change list.
186 LoadChangeListFromServer(about_resource.Pass(), 186 LoadChangeListFromServer(about_resource.Pass(),
187 start_changestamp, 187 start_changestamp,
188 callback); 188 callback);
189 } else if (directory_fetch_info.changestamp() < remote_changestamp && 189 } else if (directory_fetch_info.changestamp() < remote_changestamp &&
190 !util::IsSpecialResourceId(directory_fetch_info.resource_id())) { 190 directory_fetch_info.resource_id() !=
191 util::kDriveOtherDirSpecialResourceId) {
kinaba 2013/04/10 06:50:20 I think we can simply remove this check because Do
hidehiko 2013/04/10 07:43:06 Indeed. Done.
191 // If the caller is interested in a particular directory, and the 192 // If the caller is interested in a particular directory, and the
192 // directory changestamp is older than server's, start loading the 193 // directory changestamp is older than server's, start loading the
193 // directory first. Skip special entries as they are not meaningful in the 194 // directory first. Skip special entries as they are not meaningful in the
194 // server. 195 // server.
195 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() 196 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString()
196 << "; remote_changestamp: " << remote_changestamp; 197 << "; remote_changestamp: " << remote_changestamp;
197 const DirectoryFetchInfo new_directory_fetch_info( 198 const DirectoryFetchInfo new_directory_fetch_info(
198 directory_fetch_info.resource_id(), remote_changestamp); 199 directory_fetch_info.resource_id(), remote_changestamp);
199 DoLoadDirectoryFromServer( 200 DoLoadDirectoryFromServer(
200 new_directory_fetch_info, 201 new_directory_fetch_info,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 335 }
335 336
336 void ChangeListLoader::DoLoadDirectoryFromServer( 337 void ChangeListLoader::DoLoadDirectoryFromServer(
337 const DirectoryFetchInfo& directory_fetch_info, 338 const DirectoryFetchInfo& directory_fetch_info,
338 const FileOperationCallback& callback) { 339 const FileOperationCallback& callback) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 DCHECK(!callback.is_null()); 341 DCHECK(!callback.is_null());
341 DCHECK(!directory_fetch_info.empty()); 342 DCHECK(!directory_fetch_info.empty());
342 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString(); 343 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString();
343 344
344 if (util::IsSpecialResourceId(directory_fetch_info.resource_id())) { 345 if (directory_fetch_info.resource_id() ==
345 // Load for a special directory is meaningless in the server. 346 util::kDriveOtherDirSpecialResourceId) {
347 // Load for a <other> directory is meaningless in the server.
346 // Let it succeed and use what we have locally. 348 // Let it succeed and use what we have locally.
347 callback.Run(DRIVE_FILE_OK); 349 callback.Run(DRIVE_FILE_OK);
348 return; 350 return;
349 } 351 }
350 352
353 if (directory_fetch_info.resource_id() ==
354 util::kDriveGrandRootSpecialResourceId) {
355 // Load for a grand root directory means slightly different from other
356 // directories. It should have two directories; <other> and mydrive root.
357 // <other> directory should always exist, but mydrive root should be
358 // created by root resource id retrieved from the server.
359 // Here, we check if mydrive root exists, and if not, create it.
360 resource_metadata_->GetEntryInfoByPath(
361 base::FilePath(util::kDriveMyDriveRootPath),
362 base::Bind(
363 &ChangeListLoader
364 ::DoLoadGrandRootDirectoryFromServerAfterGetEntryInfoByPath,
365 weak_ptr_factory_.GetWeakPtr(),
366 directory_fetch_info,
367 callback));
368 return;
369 }
370
351 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); 371 scoped_ptr<LoadFeedParams> params(new LoadFeedParams);
352 params->directory_resource_id = directory_fetch_info.resource_id(); 372 params->directory_resource_id = directory_fetch_info.resource_id();
353 LoadFromServer( 373 LoadFromServer(
354 params.Pass(), 374 params.Pass(),
355 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad, 375 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad,
356 weak_ptr_factory_.GetWeakPtr(), 376 weak_ptr_factory_.GetWeakPtr(),
357 directory_fetch_info, 377 directory_fetch_info,
358 callback)); 378 callback));
359 } 379 }
360 380
381 void
382 ChangeListLoader::DoLoadGrandRootDirectoryFromServerAfterGetEntryInfoByPath(
383 const DirectoryFetchInfo& directory_fetch_info,
384 const FileOperationCallback& callback,
385 DriveFileError error,
386 scoped_ptr<DriveEntryProto> entry_proto) {
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
388 DCHECK(!callback.is_null());
389 DCHECK_EQ(directory_fetch_info.resource_id(),
390 util::kDriveGrandRootSpecialResourceId);
391
392 if (error == DRIVE_FILE_OK) {
393 // MyDrive root already exists. Just return success.
394 callback.Run(DRIVE_FILE_OK);
395 return;
396 }
397
398 // Fetch root resource id from the server.
399 scheduler_->GetAboutResource(
400 base::Bind(
401 &ChangeListLoader
402 ::DoLoadGrandRootDirectoryFromServerAfterGetAboutResource,
403 weak_ptr_factory_.GetWeakPtr(),
404 directory_fetch_info,
405 callback));
406 }
407
408 void ChangeListLoader::DoLoadGrandRootDirectoryFromServerAfterGetAboutResource(
409 const DirectoryFetchInfo& directory_fetch_info,
410 const FileOperationCallback& callback,
411 google_apis::GDataErrorCode status,
412 scoped_ptr<google_apis::AboutResource> about_resource) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 DCHECK(!callback.is_null());
415 DCHECK_EQ(directory_fetch_info.resource_id(),
416 util::kDriveGrandRootSpecialResourceId);
417
418 DriveFileError error = util::GDataToDriveFileError(status);
419 if (error != DRIVE_FILE_OK) {
420 callback.Run(error);
421 return;
422 }
423
424 // Build entry proto map for grand root directory, which has two entries;
425 // "/drive/root" and "/drive/other".
426 DriveEntryProtoMap grand_root_entry_proto_map;
427 const std::string& root_resource_id = about_resource->root_folder_id();
428 grand_root_entry_proto_map[root_resource_id] =
429 util::CreateMyDriveRootEntry(root_resource_id);
430 grand_root_entry_proto_map[util::kDriveOtherDirSpecialResourceId] =
431 util::CreateOtherDirEntry();
432 resource_metadata_->RefreshDirectory(
433 directory_fetch_info,
434 grand_root_entry_proto_map,
435 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh,
436 weak_ptr_factory_.GetWeakPtr(),
437 directory_fetch_info,
438 callback));
439 }
440
361 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad( 441 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad(
362 const DirectoryFetchInfo& directory_fetch_info, 442 const DirectoryFetchInfo& directory_fetch_info,
363 const FileOperationCallback& callback, 443 const FileOperationCallback& callback,
364 ScopedVector<ChangeList> change_lists, 444 ScopedVector<ChangeList> change_lists,
365 DriveFileError error) { 445 DriveFileError error) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
367 DCHECK(!callback.is_null()); 447 DCHECK(!callback.is_null());
368 DCHECK(!directory_fetch_info.empty()); 448 DCHECK(!directory_fetch_info.empty());
369 449
370 if (error != DRIVE_FILE_OK) { 450 if (error != DRIVE_FILE_OK) {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 for (size_t i = 0; i < callbacks.size(); ++i) { 852 for (size_t i = 0; i < callbacks.size(); ++i) {
773 base::MessageLoopProxy::current()->PostTask( 853 base::MessageLoopProxy::current()->PostTask(
774 FROM_HERE, 854 FROM_HERE,
775 base::Bind(callbacks[i], error)); 855 base::Bind(callbacks[i], error));
776 } 856 }
777 pending_load_callback_.erase(it); 857 pending_load_callback_.erase(it);
778 } 858 }
779 } 859 }
780 860
781 } // namespace drive 861 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader.h ('k') | chrome/browser/chromeos/drive/change_list_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698