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/chromeos/directory_loader.h" | 5 #include "components/drive/chromeos/directory_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ReadDirectoryEntriesCallback entries_callback; | 93 ReadDirectoryEntriesCallback entries_callback; |
94 FileOperationCallback completion_callback; | 94 FileOperationCallback completion_callback; |
95 std::set<std::string> sent_entry_names; | 95 std::set<std::string> sent_entry_names; |
96 }; | 96 }; |
97 | 97 |
98 // Fetches the resource entries in the directory with |directory_resource_id|. | 98 // Fetches the resource entries in the directory with |directory_resource_id|. |
99 class DirectoryLoader::FeedFetcher { | 99 class DirectoryLoader::FeedFetcher { |
100 public: | 100 public: |
101 FeedFetcher(DirectoryLoader* loader, | 101 FeedFetcher(DirectoryLoader* loader, |
102 const DirectoryFetchInfo& directory_fetch_info, | 102 const DirectoryFetchInfo& directory_fetch_info, |
103 const std::string& root_folder_id) | 103 const std::string& root_folder_id, |
| 104 const std::string& team_drive_id) |
104 : loader_(loader), | 105 : loader_(loader), |
105 directory_fetch_info_(directory_fetch_info), | 106 directory_fetch_info_(directory_fetch_info), |
106 root_folder_id_(root_folder_id), | 107 root_folder_id_(root_folder_id), |
107 weak_ptr_factory_(this) { | 108 team_drive_id_(team_drive_id), |
108 } | 109 weak_ptr_factory_(this) {} |
109 | 110 |
110 ~FeedFetcher() { | 111 ~FeedFetcher() { |
111 } | 112 } |
112 | 113 |
113 void Run(const FileOperationCallback& callback) { | 114 void Run(const FileOperationCallback& callback) { |
114 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
115 DCHECK(!callback.is_null()); | 116 DCHECK(!callback.is_null()); |
116 DCHECK(!directory_fetch_info_.resource_id().empty()); | 117 DCHECK(!directory_fetch_info_.resource_id().empty()); |
117 | 118 |
118 // Remember the time stamp for usage stats. | 119 // Remember the time stamp for usage stats. |
119 start_time_ = base::TimeTicks::Now(); | 120 start_time_ = base::TimeTicks::Now(); |
120 | 121 |
121 loader_->scheduler_->GetFileListInDirectory( | 122 loader_->scheduler_->GetFileListInDirectory( |
122 directory_fetch_info_.resource_id(), | 123 directory_fetch_info_.resource_id(), team_drive_id_, |
123 base::Bind(&FeedFetcher::OnFileListFetched, | 124 base::Bind(&FeedFetcher::OnFileListFetched, |
124 weak_ptr_factory_.GetWeakPtr(), callback)); | 125 weak_ptr_factory_.GetWeakPtr(), callback)); |
125 } | 126 } |
126 | 127 |
127 private: | 128 private: |
128 void OnFileListFetched(const FileOperationCallback& callback, | 129 void OnFileListFetched(const FileOperationCallback& callback, |
129 google_apis::DriveApiErrorCode status, | 130 google_apis::DriveApiErrorCode status, |
130 std::unique_ptr<google_apis::FileList> file_list) { | 131 std::unique_ptr<google_apis::FileList> file_list) { |
131 DCHECK(thread_checker_.CalledOnValidThread()); | 132 DCHECK(thread_checker_.CalledOnValidThread()); |
132 DCHECK(!callback.is_null()); | 133 DCHECK(!callback.is_null()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 // Note: The fetcher is managed by DirectoryLoader, and the instance | 184 // Note: The fetcher is managed by DirectoryLoader, and the instance |
184 // 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 |
185 // invocation. | 186 // invocation. |
186 callback.Run(FILE_ERROR_OK); | 187 callback.Run(FILE_ERROR_OK); |
187 } | 188 } |
188 | 189 |
189 DirectoryLoader* loader_; | 190 DirectoryLoader* loader_; |
190 DirectoryFetchInfo directory_fetch_info_; | 191 DirectoryFetchInfo directory_fetch_info_; |
191 std::string root_folder_id_; | 192 std::string root_folder_id_; |
| 193 std::string team_drive_id_; |
192 base::TimeTicks start_time_; | 194 base::TimeTicks start_time_; |
193 base::ThreadChecker thread_checker_; | 195 base::ThreadChecker thread_checker_; |
194 base::WeakPtrFactory<FeedFetcher> weak_ptr_factory_; | 196 base::WeakPtrFactory<FeedFetcher> weak_ptr_factory_; |
195 DISALLOW_COPY_AND_ASSIGN(FeedFetcher); | 197 DISALLOW_COPY_AND_ASSIGN(FeedFetcher); |
196 }; | 198 }; |
197 | 199 |
198 DirectoryLoader::DirectoryLoader( | 200 DirectoryLoader::DirectoryLoader( |
199 EventLogger* logger, | 201 EventLogger* logger, |
200 base::SequencedTaskRunner* blocking_task_runner, | 202 base::SequencedTaskRunner* blocking_task_runner, |
201 ResourceMetadata* resource_metadata, | 203 ResourceMetadata* resource_metadata, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 const google_apis::AboutResource* about_resource = | 496 const google_apis::AboutResource* about_resource = |
495 about_resource_loader_->cached_about_resource(); | 497 about_resource_loader_->cached_about_resource(); |
496 DCHECK(about_resource); | 498 DCHECK(about_resource); |
497 | 499 |
498 logger_->Log(logging::LOG_INFO, | 500 logger_->Log(logging::LOG_INFO, |
499 "Fast-fetch start: %s; Server changestamp: %s", | 501 "Fast-fetch start: %s; Server changestamp: %s", |
500 directory_fetch_info.ToString().c_str(), | 502 directory_fetch_info.ToString().c_str(), |
501 base::Int64ToString( | 503 base::Int64ToString( |
502 about_resource->largest_change_id()).c_str()); | 504 about_resource->largest_change_id()).c_str()); |
503 | 505 |
504 FeedFetcher* fetcher = new FeedFetcher(this, | 506 // TODO(yamaguchi): Pass the right |team_drive_id| based on |
505 directory_fetch_info, | 507 // directory_fetch_info. Curently it doesn't support fetching a directory |
506 about_resource->root_folder_id()); | 508 // under Team Drives. |
| 509 FeedFetcher* fetcher = |
| 510 new FeedFetcher(this, directory_fetch_info, |
| 511 about_resource->root_folder_id(), "" /* team_drive_id */); |
507 fast_fetch_feed_fetcher_set_.insert(base::WrapUnique(fetcher)); | 512 fast_fetch_feed_fetcher_set_.insert(base::WrapUnique(fetcher)); |
508 fetcher->Run( | 513 fetcher->Run( |
509 base::Bind(&DirectoryLoader::LoadDirectoryFromServerAfterLoad, | 514 base::Bind(&DirectoryLoader::LoadDirectoryFromServerAfterLoad, |
510 weak_ptr_factory_.GetWeakPtr(), | 515 weak_ptr_factory_.GetWeakPtr(), |
511 directory_fetch_info, | 516 directory_fetch_info, |
512 fetcher)); | 517 fetcher)); |
513 } | 518 } |
514 | 519 |
515 void DirectoryLoader::LoadDirectoryFromServerAfterLoad( | 520 void DirectoryLoader::LoadDirectoryFromServerAfterLoad( |
516 const DirectoryFetchInfo& directory_fetch_info, | 521 const DirectoryFetchInfo& directory_fetch_info, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 | 572 |
568 // Also notify the observers. | 573 // Also notify the observers. |
569 if (error == FILE_ERROR_OK && !directory_path->empty()) { | 574 if (error == FILE_ERROR_OK && !directory_path->empty()) { |
570 for (auto& observer : observers_) | 575 for (auto& observer : observers_) |
571 observer.OnDirectoryReloaded(*directory_path); | 576 observer.OnDirectoryReloaded(*directory_path); |
572 } | 577 } |
573 } | 578 } |
574 | 579 |
575 } // namespace internal | 580 } // namespace internal |
576 } // namespace drive | 581 } // namespace drive |
OLD | NEW |