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

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

Issue 15060002: drive: Rename FileCache methods in a blocking pool centric manner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove virtual Created 7 years, 7 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/sync_client.h" 5 #include "chrome/browser/chromeos/drive/sync_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 file_system_->RemoveObserver(this); 74 file_system_->RemoveObserver(this);
75 cache_->RemoveObserver(this); 75 cache_->RemoveObserver(this);
76 } 76 }
77 77
78 void SyncClient::StartProcessingBacklog() { 78 void SyncClient::StartProcessingBacklog() {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
80 80
81 std::vector<std::string>* to_fetch = new std::vector<std::string>; 81 std::vector<std::string>* to_fetch = new std::vector<std::string>;
82 std::vector<std::string>* to_upload = new std::vector<std::string>; 82 std::vector<std::string>* to_upload = new std::vector<std::string>;
83 cache_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload), 83 cache_->IterateOnUIThread(base::Bind(&CollectBacklog, to_fetch, to_upload),
84 base::Bind(&SyncClient::OnGetResourceIdsOfBacklog, 84 base::Bind(&SyncClient::OnGetResourceIdsOfBacklog,
85 weak_ptr_factory_.GetWeakPtr(), 85 weak_ptr_factory_.GetWeakPtr(),
86 base::Owned(to_fetch), 86 base::Owned(to_fetch),
87 base::Owned(to_upload))); 87 base::Owned(to_upload)));
88 } 88 }
89 89
90 void SyncClient::StartCheckingExistingPinnedFiles() { 90 void SyncClient::StartCheckingExistingPinnedFiles() {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
92 92
93 cache_->Iterate( 93 cache_->IterateOnUIThread(
94 base::Bind(&SyncClient::OnGetResourceIdOfExistingPinnedFile, 94 base::Bind(&SyncClient::OnGetResourceIdOfExistingPinnedFile,
95 weak_ptr_factory_.GetWeakPtr()), 95 weak_ptr_factory_.GetWeakPtr()),
96 base::Bind(&base::DoNothing)); 96 base::Bind(&base::DoNothing));
97 } 97 }
98 98
99 std::vector<std::string> SyncClient::GetResourceIdsForTesting( 99 std::vector<std::string> SyncClient::GetResourceIdsForTesting(
100 SyncType sync_type) const { 100 SyncType sync_type) const {
101 switch (sync_type) { 101 switch (sync_type) {
102 case FETCH: 102 case FETCH:
103 return std::vector<std::string>(fetch_list_.begin(), fetch_list_.end()); 103 return std::vector<std::string>(fetch_list_.begin(), fetch_list_.end());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (error != FILE_ERROR_OK) { 255 if (error != FILE_ERROR_OK) {
256 LOG(WARNING) << "Entry not found: " << resource_id; 256 LOG(WARNING) << "Entry not found: " << resource_id;
257 return; 257 return;
258 } 258 }
259 259
260 // If MD5s don't match, it indicates the local cache file is stale, unless 260 // If MD5s don't match, it indicates the local cache file is stale, unless
261 // the file is dirty (the MD5 is "local"). We should never re-fetch the 261 // the file is dirty (the MD5 is "local"). We should never re-fetch the
262 // file when we have a locally modified version. 262 // file when we have a locally modified version.
263 if (entry->file_specific_info().file_md5() != cache_entry.md5() && 263 if (entry->file_specific_info().file_md5() != cache_entry.md5() &&
264 !cache_entry.is_dirty()) { 264 !cache_entry.is_dirty()) {
265 cache_->Remove(resource_id, 265 cache_->RemoveOnUIThread(resource_id,
266 base::Bind(&SyncClient::OnRemove, 266 base::Bind(&SyncClient::OnRemove,
267 weak_ptr_factory_.GetWeakPtr(), 267 weak_ptr_factory_.GetWeakPtr(),
268 resource_id)); 268 resource_id));
269 } 269 }
270 } 270 }
271 271
272 void SyncClient::OnRemove(const std::string& resource_id, 272 void SyncClient::OnRemove(const std::string& resource_id,
273 FileError error) { 273 FileError error) {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 275
276 if (error != FILE_ERROR_OK) { 276 if (error != FILE_ERROR_OK) {
277 LOG(WARNING) << "Failed to remove cache entry: " << resource_id; 277 LOG(WARNING) << "Failed to remove cache entry: " << resource_id;
278 return; 278 return;
279 } 279 }
280 280
281 // Before fetching, we should pin this file again, so that the fetched file 281 // Before fetching, we should pin this file again, so that the fetched file
282 // is downloaded properly to the persistent directory and marked pinned. 282 // is downloaded properly to the persistent directory and marked pinned.
283 cache_->Pin(resource_id, 283 cache_->PinOnUIThread(resource_id,
284 std::string(), 284 std::string(),
285 base::Bind(&SyncClient::OnPinned, 285 base::Bind(&SyncClient::OnPinned,
286 weak_ptr_factory_.GetWeakPtr(), 286 weak_ptr_factory_.GetWeakPtr(),
287 resource_id)); 287 resource_id));
288 } 288 }
289 289
290 void SyncClient::OnPinned(const std::string& resource_id, 290 void SyncClient::OnPinned(const std::string& resource_id,
291 FileError error) { 291 FileError error) {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 293
294 if (error != FILE_ERROR_OK) { 294 if (error != FILE_ERROR_OK) {
295 LOG(WARNING) << "Failed to pin cache entry: " << resource_id; 295 LOG(WARNING) << "Failed to pin cache entry: " << resource_id;
296 return; 296 return;
297 } 297 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (error == FILE_ERROR_OK) { 333 if (error == FILE_ERROR_OK) {
334 DVLOG(1) << "Uploaded " << resource_id; 334 DVLOG(1) << "Uploaded " << resource_id;
335 } else { 335 } else {
336 // TODO(satorux): We should re-queue if the error is recoverable. 336 // TODO(satorux): We should re-queue if the error is recoverable.
337 LOG(WARNING) << "Failed to upload " << resource_id << ": " 337 LOG(WARNING) << "Failed to upload " << resource_id << ": "
338 << FileErrorToString(error); 338 << FileErrorToString(error);
339 } 339 }
340 } 340 }
341 341
342 } // namespace drive 342 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698