OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/drive/directory_loader.h" | 5 #include "components/drive/directory_loader.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/macros.h" |
9 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
12 #include "components/drive/change_list_loader.h" | 15 #include "components/drive/change_list_loader.h" |
13 #include "components/drive/change_list_loader_observer.h" | 16 #include "components/drive/change_list_loader_observer.h" |
14 #include "components/drive/change_list_processor.h" | 17 #include "components/drive/change_list_processor.h" |
15 #include "components/drive/event_logger.h" | 18 #include "components/drive/event_logger.h" |
16 #include "components/drive/file_system_core_util.h" | 19 #include "components/drive/file_system_core_util.h" |
17 #include "components/drive/job_scheduler.h" | 20 #include "components/drive/job_scheduler.h" |
18 #include "components/drive/resource_metadata.h" | 21 #include "components/drive/resource_metadata.h" |
19 #include "google_apis/drive/drive_api_parser.h" | 22 #include "google_apis/drive/drive_api_parser.h" |
20 #include "url/gurl.h" | 23 #include "url/gurl.h" |
21 | 24 |
22 namespace drive { | 25 namespace drive { |
23 namespace internal { | 26 namespace internal { |
24 | 27 |
25 namespace { | 28 namespace { |
26 | 29 |
27 // Minimum changestamp gap required to start loading directory. | 30 // Minimum changestamp gap required to start loading directory. |
28 const int kMinimumChangestampGap = 50; | 31 const int kMinimumChangestampGap = 50; |
29 | 32 |
30 FileError CheckLocalState(ResourceMetadata* resource_metadata, | 33 FileError CheckLocalState(ResourceMetadata* resource_metadata, |
31 const google_apis::AboutResource& about_resource, | 34 const google_apis::AboutResource& about_resource, |
32 const std::string& local_id, | 35 const std::string& local_id, |
33 ResourceEntry* entry, | 36 ResourceEntry* entry, |
34 int64* local_changestamp) { | 37 int64_t* local_changestamp) { |
35 // Fill My Drive resource ID. | 38 // Fill My Drive resource ID. |
36 ResourceEntry mydrive; | 39 ResourceEntry mydrive; |
37 FileError error = resource_metadata->GetResourceEntryByPath( | 40 FileError error = resource_metadata->GetResourceEntryByPath( |
38 util::GetDriveMyDriveRootPath(), &mydrive); | 41 util::GetDriveMyDriveRootPath(), &mydrive); |
39 if (error != FILE_ERROR_OK) | 42 if (error != FILE_ERROR_OK) |
40 return error; | 43 return error; |
41 | 44 |
42 if (mydrive.resource_id().empty()) { | 45 if (mydrive.resource_id().empty()) { |
43 mydrive.set_resource_id(about_resource.root_folder_id()); | 46 mydrive.set_resource_id(about_resource.root_folder_id()); |
44 error = resource_metadata->RefreshEntry(mydrive); | 47 error = resource_metadata->RefreshEntry(mydrive); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 if (error != FILE_ERROR_OK) { | 344 if (error != FILE_ERROR_OK) { |
342 OnDirectoryLoadComplete(local_id, error); | 345 OnDirectoryLoadComplete(local_id, error); |
343 return; | 346 return; |
344 } | 347 } |
345 | 348 |
346 DCHECK(about_resource); | 349 DCHECK(about_resource); |
347 | 350 |
348 // Check the current status of local metadata, and start loading if needed. | 351 // Check the current status of local metadata, and start loading if needed. |
349 google_apis::AboutResource* about_resource_ptr = about_resource.get(); | 352 google_apis::AboutResource* about_resource_ptr = about_resource.get(); |
350 ResourceEntry* entry = new ResourceEntry; | 353 ResourceEntry* entry = new ResourceEntry; |
351 int64* local_changestamp = new int64; | 354 int64_t* local_changestamp = new int64_t; |
352 base::PostTaskAndReplyWithResult( | 355 base::PostTaskAndReplyWithResult( |
353 blocking_task_runner_.get(), | 356 blocking_task_runner_.get(), |
354 FROM_HERE, | 357 FROM_HERE, |
355 base::Bind(&CheckLocalState, | 358 base::Bind(&CheckLocalState, |
356 resource_metadata_, | 359 resource_metadata_, |
357 *about_resource_ptr, | 360 *about_resource_ptr, |
358 local_id, | 361 local_id, |
359 entry, | 362 entry, |
360 local_changestamp), | 363 local_changestamp), |
361 base::Bind(&DirectoryLoader::ReadDirectoryAfterCheckLocalState, | 364 base::Bind(&DirectoryLoader::ReadDirectoryAfterCheckLocalState, |
362 weak_ptr_factory_.GetWeakPtr(), | 365 weak_ptr_factory_.GetWeakPtr(), |
363 base::Passed(&about_resource), | 366 base::Passed(&about_resource), |
364 local_id, | 367 local_id, |
365 base::Owned(entry), | 368 base::Owned(entry), |
366 base::Owned(local_changestamp))); | 369 base::Owned(local_changestamp))); |
367 } | 370 } |
368 | 371 |
369 void DirectoryLoader::ReadDirectoryAfterCheckLocalState( | 372 void DirectoryLoader::ReadDirectoryAfterCheckLocalState( |
370 scoped_ptr<google_apis::AboutResource> about_resource, | 373 scoped_ptr<google_apis::AboutResource> about_resource, |
371 const std::string& local_id, | 374 const std::string& local_id, |
372 const ResourceEntry* entry, | 375 const ResourceEntry* entry, |
373 const int64* local_changestamp, | 376 const int64_t* local_changestamp, |
374 FileError error) { | 377 FileError error) { |
375 DCHECK(thread_checker_.CalledOnValidThread()); | 378 DCHECK(thread_checker_.CalledOnValidThread()); |
376 DCHECK(about_resource); | 379 DCHECK(about_resource); |
377 | 380 |
378 if (error != FILE_ERROR_OK) { | 381 if (error != FILE_ERROR_OK) { |
379 OnDirectoryLoadComplete(local_id, error); | 382 OnDirectoryLoadComplete(local_id, error); |
380 return; | 383 return; |
381 } | 384 } |
382 // This entry does not exist on the server. | 385 // This entry does not exist on the server. |
383 if (entry->resource_id().empty()) { | 386 if (entry->resource_id().empty()) { |
384 OnDirectoryLoadComplete(local_id, FILE_ERROR_OK); | 387 OnDirectoryLoadComplete(local_id, FILE_ERROR_OK); |
385 return; | 388 return; |
386 } | 389 } |
387 | 390 |
388 int64 remote_changestamp = about_resource->largest_change_id(); | 391 int64_t remote_changestamp = about_resource->largest_change_id(); |
389 | 392 |
390 // Start loading the directory. | 393 // Start loading the directory. |
391 int64 directory_changestamp = std::max( | 394 int64_t directory_changestamp = std::max( |
392 entry->directory_specific_info().changestamp(), *local_changestamp); | 395 entry->directory_specific_info().changestamp(), *local_changestamp); |
393 | 396 |
394 DirectoryFetchInfo directory_fetch_info( | 397 DirectoryFetchInfo directory_fetch_info( |
395 local_id, entry->resource_id(), remote_changestamp); | 398 local_id, entry->resource_id(), remote_changestamp); |
396 | 399 |
397 // If the directory's changestamp is up-to-date or the global changestamp of | 400 // If the directory's changestamp is up-to-date or the global changestamp of |
398 // the metadata DB is new enough (which means the normal changelist loading | 401 // the metadata DB is new enough (which means the normal changelist loading |
399 // should finish very soon), just schedule to run the callback, as there is no | 402 // should finish very soon), just schedule to run the callback, as there is no |
400 // need to fetch the directory. | 403 // need to fetch the directory. |
401 if (directory_changestamp >= remote_changestamp || | 404 if (directory_changestamp >= remote_changestamp || |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // Also notify the observers. | 565 // Also notify the observers. |
563 if (error == FILE_ERROR_OK && !directory_path->empty()) { | 566 if (error == FILE_ERROR_OK && !directory_path->empty()) { |
564 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 567 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
565 observers_, | 568 observers_, |
566 OnDirectoryReloaded(*directory_path)); | 569 OnDirectoryReloaded(*directory_path)); |
567 } | 570 } |
568 } | 571 } |
569 | 572 |
570 } // namespace internal | 573 } // namespace internal |
571 } // namespace drive | 574 } // namespace drive |
OLD | NEW |