| 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 "chrome/browser/chromeos/drive/directory_loader.h" | 5 #include "chrome/browser/chromeos/drive/directory_loader.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 12 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
| 13 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" | 13 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" |
| 14 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 14 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 16 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 16 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 17 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 17 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 18 #include "chrome/browser/drive/event_logger.h" | 18 #include "chrome/browser/drive/event_logger.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "google_apis/drive/drive_api_parser.h" | 20 #include "google_apis/drive/drive_api_parser.h" |
| 21 #include "google_apis/drive/gdata_wapi_parser.h" | |
| 22 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 23 | 22 |
| 24 using content::BrowserThread; | 23 using content::BrowserThread; |
| 25 | 24 |
| 26 namespace drive { | 25 namespace drive { |
| 27 namespace internal { | 26 namespace internal { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // Minimum changestamp gap required to start loading directory. | 30 // Minimum changestamp gap required to start loading directory. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 106 } |
| 108 | 107 |
| 109 void Run(const FileOperationCallback& callback) { | 108 void Run(const FileOperationCallback& callback) { |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 111 DCHECK(!callback.is_null()); | 110 DCHECK(!callback.is_null()); |
| 112 DCHECK(!directory_fetch_info_.resource_id().empty()); | 111 DCHECK(!directory_fetch_info_.resource_id().empty()); |
| 113 | 112 |
| 114 // Remember the time stamp for usage stats. | 113 // Remember the time stamp for usage stats. |
| 115 start_time_ = base::TimeTicks::Now(); | 114 start_time_ = base::TimeTicks::Now(); |
| 116 | 115 |
| 117 loader_->scheduler_->GetResourceListInDirectory( | 116 loader_->scheduler_->GetFileListInDirectory( |
| 118 directory_fetch_info_.resource_id(), | 117 directory_fetch_info_.resource_id(), |
| 119 base::Bind(&FeedFetcher::OnResourceListFetched, | 118 base::Bind(&FeedFetcher::OnFileListFetched, |
| 120 weak_ptr_factory_.GetWeakPtr(), callback)); | 119 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 121 } | 120 } |
| 122 | 121 |
| 123 private: | 122 private: |
| 124 void OnResourceListFetched( | 123 void OnFileListFetched(const FileOperationCallback& callback, |
| 125 const FileOperationCallback& callback, | 124 google_apis::GDataErrorCode status, |
| 126 google_apis::GDataErrorCode status, | 125 scoped_ptr<google_apis::FileList> file_list) { |
| 127 scoped_ptr<google_apis::ResourceList> resource_list) { | |
| 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 129 DCHECK(!callback.is_null()); | 127 DCHECK(!callback.is_null()); |
| 130 | 128 |
| 131 FileError error = GDataToFileError(status); | 129 FileError error = GDataToFileError(status); |
| 132 if (error != FILE_ERROR_OK) { | 130 if (error != FILE_ERROR_OK) { |
| 133 callback.Run(error); | 131 callback.Run(error); |
| 134 return; | 132 return; |
| 135 } | 133 } |
| 136 | 134 |
| 137 DCHECK(resource_list); | 135 DCHECK(file_list); |
| 138 scoped_ptr<ChangeList> change_list(new ChangeList(*resource_list)); | 136 scoped_ptr<ChangeList> change_list(new ChangeList(*file_list)); |
| 139 | 137 GURL next_url = file_list->next_link(); |
| 140 GURL next_url; | |
| 141 resource_list->GetNextFeedURL(&next_url); | |
| 142 | 138 |
| 143 ResourceEntryVector* entries = new ResourceEntryVector; | 139 ResourceEntryVector* entries = new ResourceEntryVector; |
| 144 loader_->loader_controller_->ScheduleRun(base::Bind( | 140 loader_->loader_controller_->ScheduleRun(base::Bind( |
| 145 base::IgnoreResult( | 141 base::IgnoreResult( |
| 146 &base::PostTaskAndReplyWithResult<FileError, FileError>), | 142 &base::PostTaskAndReplyWithResult<FileError, FileError>), |
| 147 loader_->blocking_task_runner_, | 143 loader_->blocking_task_runner_, |
| 148 FROM_HERE, | 144 FROM_HERE, |
| 149 base::Bind(&ChangeListProcessor::RefreshDirectory, | 145 base::Bind(&ChangeListProcessor::RefreshDirectory, |
| 150 loader_->resource_metadata_, | 146 loader_->resource_metadata_, |
| 151 directory_fetch_info_, | 147 directory_fetch_info_, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 170 callback.Run(error); | 166 callback.Run(error); |
| 171 return; | 167 return; |
| 172 } | 168 } |
| 173 | 169 |
| 174 loader_->SendEntries(directory_fetch_info_.local_id(), *refreshed_entries); | 170 loader_->SendEntries(directory_fetch_info_.local_id(), *refreshed_entries); |
| 175 | 171 |
| 176 if (!next_url.is_empty()) { | 172 if (!next_url.is_empty()) { |
| 177 // There is the remaining result so fetch it. | 173 // There is the remaining result so fetch it. |
| 178 loader_->scheduler_->GetRemainingFileList( | 174 loader_->scheduler_->GetRemainingFileList( |
| 179 next_url, | 175 next_url, |
| 180 base::Bind(&FeedFetcher::OnResourceListFetched, | 176 base::Bind(&FeedFetcher::OnFileListFetched, |
| 181 weak_ptr_factory_.GetWeakPtr(), callback)); | 177 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 182 return; | 178 return; |
| 183 } | 179 } |
| 184 | 180 |
| 185 UMA_HISTOGRAM_TIMES("Drive.DirectoryFeedLoadTime", | 181 UMA_HISTOGRAM_TIMES("Drive.DirectoryFeedLoadTime", |
| 186 base::TimeTicks::Now() - start_time_); | 182 base::TimeTicks::Now() - start_time_); |
| 187 | 183 |
| 188 // Note: The fetcher is managed by DirectoryLoader, and the instance | 184 // Note: The fetcher is managed by DirectoryLoader, and the instance |
| 189 // will be deleted in the callback. Do not touch the fields after this | 185 // will be deleted in the callback. Do not touch the fields after this |
| 190 // invocation. | 186 // invocation. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 567 |
| 572 // Also notify the observers. | 568 // Also notify the observers. |
| 573 if (error == FILE_ERROR_OK && !directory_path->empty()) { | 569 if (error == FILE_ERROR_OK && !directory_path->empty()) { |
| 574 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, | 570 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, |
| 575 OnDirectoryChanged(*directory_path)); | 571 OnDirectoryChanged(*directory_path)); |
| 576 } | 572 } |
| 577 } | 573 } |
| 578 | 574 |
| 579 } // namespace internal | 575 } // namespace internal |
| 580 } // namespace drive | 576 } // namespace drive |
| OLD | NEW |