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

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: Remove other resource id check. 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 OnChangeListLoadComplete(callback, DRIVE_FILE_ERROR_FAILED); 179 OnChangeListLoadComplete(callback, DRIVE_FILE_ERROR_FAILED);
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())) {
191 // If the caller is interested in a particular directory, and the 190 // If the caller is interested in a particular directory, and the
192 // directory changestamp is older than server's, start loading the 191 // directory changestamp is older than server's, start loading the
193 // directory first. Skip special entries as they are not meaningful in the 192 // directory first. Skip special entries as they are not meaningful in the
194 // server. 193 // server.
195 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() 194 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString()
196 << "; remote_changestamp: " << remote_changestamp; 195 << "; remote_changestamp: " << remote_changestamp;
197 const DirectoryFetchInfo new_directory_fetch_info( 196 const DirectoryFetchInfo new_directory_fetch_info(
198 directory_fetch_info.resource_id(), remote_changestamp); 197 directory_fetch_info.resource_id(), remote_changestamp);
199 DoLoadDirectoryFromServer( 198 DoLoadDirectoryFromServer(
200 new_directory_fetch_info, 199 new_directory_fetch_info,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 333 }
335 334
336 void ChangeListLoader::DoLoadDirectoryFromServer( 335 void ChangeListLoader::DoLoadDirectoryFromServer(
337 const DirectoryFetchInfo& directory_fetch_info, 336 const DirectoryFetchInfo& directory_fetch_info,
338 const FileOperationCallback& callback) { 337 const FileOperationCallback& callback) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 DCHECK(!callback.is_null()); 339 DCHECK(!callback.is_null());
341 DCHECK(!directory_fetch_info.empty()); 340 DCHECK(!directory_fetch_info.empty());
342 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString(); 341 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString();
343 342
344 if (util::IsSpecialResourceId(directory_fetch_info.resource_id())) { 343 if (directory_fetch_info.resource_id() ==
345 // Load for a special directory is meaningless in the server. 344 util::kDriveOtherDirSpecialResourceId) {
345 // Load for a <other> directory is meaningless in the server.
346 // Let it succeed and use what we have locally. 346 // Let it succeed and use what we have locally.
347 callback.Run(DRIVE_FILE_OK); 347 callback.Run(DRIVE_FILE_OK);
348 return; 348 return;
349 } 349 }
350 350
351 if (directory_fetch_info.resource_id() ==
352 util::kDriveGrandRootSpecialResourceId) {
353 // Load for a grand root directory means slightly different from other
354 // directories. It should have two directories; <other> and mydrive root.
355 // <other> directory should always exist, but mydrive root should be
356 // created by root resource id retrieved from the server.
357 // Here, we check if mydrive root exists, and if not, create it.
358 resource_metadata_->GetEntryInfoByPath(
359 base::FilePath(util::kDriveMyDriveRootPath),
360 base::Bind(
361 &ChangeListLoader
362 ::DoLoadGrandRootDirectoryFromServerAfterGetEntryInfoByPath,
363 weak_ptr_factory_.GetWeakPtr(),
364 directory_fetch_info,
365 callback));
366 return;
367 }
368
351 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); 369 scoped_ptr<LoadFeedParams> params(new LoadFeedParams);
352 params->directory_resource_id = directory_fetch_info.resource_id(); 370 params->directory_resource_id = directory_fetch_info.resource_id();
353 LoadFromServer( 371 LoadFromServer(
354 params.Pass(), 372 params.Pass(),
355 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad, 373 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad,
356 weak_ptr_factory_.GetWeakPtr(), 374 weak_ptr_factory_.GetWeakPtr(),
357 directory_fetch_info, 375 directory_fetch_info,
358 callback)); 376 callback));
359 } 377 }
360 378
379 void
380 ChangeListLoader::DoLoadGrandRootDirectoryFromServerAfterGetEntryInfoByPath(
381 const DirectoryFetchInfo& directory_fetch_info,
382 const FileOperationCallback& callback,
383 DriveFileError error,
384 scoped_ptr<DriveEntryProto> entry_proto) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
386 DCHECK(!callback.is_null());
387 DCHECK_EQ(directory_fetch_info.resource_id(),
388 util::kDriveGrandRootSpecialResourceId);
389
390 if (error == DRIVE_FILE_OK) {
391 // MyDrive root already exists. Just return success.
392 callback.Run(DRIVE_FILE_OK);
393 return;
394 }
395
396 // Fetch root resource id from the server.
397 scheduler_->GetAboutResource(
398 base::Bind(
399 &ChangeListLoader
400 ::DoLoadGrandRootDirectoryFromServerAfterGetAboutResource,
401 weak_ptr_factory_.GetWeakPtr(),
402 directory_fetch_info,
403 callback));
404 }
405
406 void ChangeListLoader::DoLoadGrandRootDirectoryFromServerAfterGetAboutResource(
407 const DirectoryFetchInfo& directory_fetch_info,
408 const FileOperationCallback& callback,
409 google_apis::GDataErrorCode status,
410 scoped_ptr<google_apis::AboutResource> about_resource) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
412 DCHECK(!callback.is_null());
413 DCHECK_EQ(directory_fetch_info.resource_id(),
414 util::kDriveGrandRootSpecialResourceId);
415
416 DriveFileError error = util::GDataToDriveFileError(status);
417 if (error != DRIVE_FILE_OK) {
418 callback.Run(error);
419 return;
420 }
421
422 // Build entry proto map for grand root directory, which has two entries;
423 // "/drive/root" and "/drive/other".
424 DriveEntryProtoMap grand_root_entry_proto_map;
425 const std::string& root_resource_id = about_resource->root_folder_id();
426 grand_root_entry_proto_map[root_resource_id] =
427 util::CreateMyDriveRootEntry(root_resource_id);
428 grand_root_entry_proto_map[util::kDriveOtherDirSpecialResourceId] =
429 util::CreateOtherDirEntry();
430 resource_metadata_->RefreshDirectory(
431 directory_fetch_info,
432 grand_root_entry_proto_map,
433 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh,
434 weak_ptr_factory_.GetWeakPtr(),
435 directory_fetch_info,
436 callback));
437 }
438
361 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad( 439 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad(
362 const DirectoryFetchInfo& directory_fetch_info, 440 const DirectoryFetchInfo& directory_fetch_info,
363 const FileOperationCallback& callback, 441 const FileOperationCallback& callback,
364 ScopedVector<ChangeList> change_lists, 442 ScopedVector<ChangeList> change_lists,
365 DriveFileError error) { 443 DriveFileError error) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
367 DCHECK(!callback.is_null()); 445 DCHECK(!callback.is_null());
368 DCHECK(!directory_fetch_info.empty()); 446 DCHECK(!directory_fetch_info.empty());
369 447
370 if (error != DRIVE_FILE_OK) { 448 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) { 850 for (size_t i = 0; i < callbacks.size(); ++i) {
773 base::MessageLoopProxy::current()->PostTask( 851 base::MessageLoopProxy::current()->PostTask(
774 FROM_HERE, 852 FROM_HERE,
775 base::Bind(callbacks[i], error)); 853 base::Bind(callbacks[i], error));
776 } 854 }
777 pending_load_callback_.erase(it); 855 pending_load_callback_.erase(it);
778 } 856 }
779 } 857 }
780 858
781 } // namespace drive 859 } // 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