| OLD | NEW |
| 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/drive_sync_client.h" | 5 #include "chrome/browser/chromeos/drive/drive_sync_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <vector> | 7 #include <vector> |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | |
| 13 #include "base/prefs/pref_service.h" | |
| 14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 12 #include "chrome/browser/chromeos/drive/drive_cache.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 13 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 19 | 15 |
| 20 using content::BrowserThread; | 16 using content::BrowserThread; |
| 21 | 17 |
| 22 namespace drive { | 18 namespace drive { |
| 23 | 19 |
| 24 namespace { | 20 namespace { |
| 25 | 21 |
| 26 // The delay constant is used to delay processing a sync task. We should not | 22 // The delay constant is used to delay processing a sync task. We should not |
| 27 // process SyncTasks immediately for the following reasons: | 23 // process SyncTasks immediately for the following reasons: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 | 47 |
| 52 if (cache_entry.is_pinned() && !cache_entry.is_present()) | 48 if (cache_entry.is_pinned() && !cache_entry.is_present()) |
| 53 to_fetch->push_back(resource_id); | 49 to_fetch->push_back(resource_id); |
| 54 | 50 |
| 55 if (cache_entry.is_dirty()) | 51 if (cache_entry.is_dirty()) |
| 56 to_upload->push_back(resource_id); | 52 to_upload->push_back(resource_id); |
| 57 } | 53 } |
| 58 | 54 |
| 59 } // namespace | 55 } // namespace |
| 60 | 56 |
| 61 DriveSyncClient::DriveSyncClient(Profile* profile, | 57 DriveSyncClient::DriveSyncClient(DriveFileSystemInterface* file_system, |
| 62 DriveFileSystemInterface* file_system, | |
| 63 DriveCache* cache) | 58 DriveCache* cache) |
| 64 : profile_(profile), | 59 : file_system_(file_system), |
| 65 file_system_(file_system), | |
| 66 cache_(cache), | 60 cache_(cache), |
| 67 delay_(base::TimeDelta::FromSeconds(kDelaySeconds)), | 61 delay_(base::TimeDelta::FromSeconds(kDelaySeconds)), |
| 68 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 62 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 } | 64 DCHECK(file_system); |
| 71 | 65 DCHECK(cache); |
| 72 DriveSyncClient::~DriveSyncClient() { | |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 74 if (file_system_) | |
| 75 file_system_->RemoveObserver(this); | |
| 76 if (cache_) | |
| 77 cache_->RemoveObserver(this); | |
| 78 } | |
| 79 | |
| 80 void DriveSyncClient::Initialize() { | |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 82 | 66 |
| 83 file_system_->AddObserver(this); | 67 file_system_->AddObserver(this); |
| 84 cache_->AddObserver(this); | 68 cache_->AddObserver(this); |
| 85 } | 69 } |
| 86 | 70 |
| 71 DriveSyncClient::~DriveSyncClient() { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 73 |
| 74 file_system_->RemoveObserver(this); |
| 75 cache_->RemoveObserver(this); |
| 76 } |
| 77 |
| 87 void DriveSyncClient::StartProcessingBacklog() { | 78 void DriveSyncClient::StartProcessingBacklog() { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 | 80 |
| 90 std::vector<std::string>* to_fetch = new std::vector<std::string>; | 81 std::vector<std::string>* to_fetch = new std::vector<std::string>; |
| 91 std::vector<std::string>* to_upload = new std::vector<std::string>; | 82 std::vector<std::string>* to_upload = new std::vector<std::string>; |
| 92 cache_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload), | 83 cache_->Iterate(base::Bind(&CollectBacklog, to_fetch, to_upload), |
| 93 base::Bind(&DriveSyncClient::OnGetResourceIdsOfBacklog, | 84 base::Bind(&DriveSyncClient::OnGetResourceIdsOfBacklog, |
| 94 weak_ptr_factory_.GetWeakPtr(), | 85 weak_ptr_factory_.GetWeakPtr(), |
| 95 base::Owned(to_fetch), | 86 base::Owned(to_fetch), |
| 96 base::Owned(to_upload))); | 87 base::Owned(to_upload))); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 if (error == DRIVE_FILE_OK) { | 334 if (error == DRIVE_FILE_OK) { |
| 344 DVLOG(1) << "Uploaded " << resource_id; | 335 DVLOG(1) << "Uploaded " << resource_id; |
| 345 } else { | 336 } else { |
| 346 // TODO(satorux): We should re-queue if the error is recoverable. | 337 // TODO(satorux): We should re-queue if the error is recoverable. |
| 347 LOG(WARNING) << "Failed to upload " << resource_id << ": " | 338 LOG(WARNING) << "Failed to upload " << resource_id << ": " |
| 348 << DriveFileErrorToString(error); | 339 << DriveFileErrorToString(error); |
| 349 } | 340 } |
| 350 } | 341 } |
| 351 | 342 |
| 352 } // namespace drive | 343 } // namespace drive |
| OLD | NEW |