| 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/gdata/gdata_sync_client.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 19 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 20 #include "chrome/browser/prefs/pref_change_registrar.h" | 20 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 | 27 |
| 28 namespace gdata { | 28 namespace gdata { |
| 29 | 29 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 base::Bind(&GDataSyncClient::OnGetEntryInfoByResourceId, | 316 base::Bind(&GDataSyncClient::OnGetEntryInfoByResourceId, |
| 317 weak_ptr_factory_.GetWeakPtr(), | 317 weak_ptr_factory_.GetWeakPtr(), |
| 318 resource_id)); | 318 resource_id)); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 void GDataSyncClient::OnGetEntryInfoByResourceId( | 322 void GDataSyncClient::OnGetEntryInfoByResourceId( |
| 323 const std::string& resource_id, | 323 const std::string& resource_id, |
| 324 GDataFileError error, | 324 GDataFileError error, |
| 325 const FilePath& /* gdata_file_path */, | 325 const FilePath& /* gdata_file_path */, |
| 326 scoped_ptr<GDataEntryProto> entry_proto) { | 326 scoped_ptr<DriveEntryProto> entry_proto) { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 328 | 328 |
| 329 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 329 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
| 330 error = GDATA_FILE_ERROR_NOT_FOUND; | 330 error = GDATA_FILE_ERROR_NOT_FOUND; |
| 331 | 331 |
| 332 if (error != GDATA_FILE_OK) { | 332 if (error != GDATA_FILE_OK) { |
| 333 LOG(WARNING) << "Entry not found: " << resource_id; | 333 LOG(WARNING) << "Entry not found: " << resource_id; |
| 334 return; | 334 return; |
| 335 } | 335 } |
| 336 | 336 |
| 337 cache_->GetCacheEntryOnUIThread( | 337 cache_->GetCacheEntryOnUIThread( |
| 338 resource_id, | 338 resource_id, |
| 339 "" /* don't check MD5 */, | 339 "" /* don't check MD5 */, |
| 340 base::Bind(&GDataSyncClient::OnGetCacheEntry, | 340 base::Bind(&GDataSyncClient::OnGetCacheEntry, |
| 341 weak_ptr_factory_.GetWeakPtr(), | 341 weak_ptr_factory_.GetWeakPtr(), |
| 342 resource_id, | 342 resource_id, |
| 343 entry_proto->file_specific_info().file_md5())); | 343 entry_proto->file_specific_info().file_md5())); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void GDataSyncClient::OnGetCacheEntry( | 346 void GDataSyncClient::OnGetCacheEntry( |
| 347 const std::string& resource_id, | 347 const std::string& resource_id, |
| 348 const std::string& latest_md5, | 348 const std::string& latest_md5, |
| 349 bool success, | 349 bool success, |
| 350 const GDataCacheEntry& cache_entry) { | 350 const DriveCacheEntry& cache_entry) { |
| 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 352 | 352 |
| 353 if (!success) { | 353 if (!success) { |
| 354 LOG(WARNING) << "Cache entry not found: " << resource_id; | 354 LOG(WARNING) << "Cache entry not found: " << resource_id; |
| 355 return; | 355 return; |
| 356 } | 356 } |
| 357 | 357 |
| 358 // If MD5s don't match, it indicates the local cache file is stale, unless | 358 // If MD5s don't match, it indicates the local cache file is stale, unless |
| 359 // the file is dirty (the MD5 is "local"). We should never re-fetch the | 359 // the file is dirty (the MD5 is "local"). We should never re-fetch the |
| 360 // file when we have a locally modified version. | 360 // file when we have a locally modified version. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 const content::NotificationDetails& details) { | 457 const content::NotificationDetails& details) { |
| 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 459 | 459 |
| 460 // Resume the sync loop if gdata preferences are changed. Note that we | 460 // Resume the sync loop if gdata preferences are changed. Note that we |
| 461 // don't need to check the new values here as these will be checked in | 461 // don't need to check the new values here as these will be checked in |
| 462 // ShouldStopSyncLoop() as soon as the loop is resumed. | 462 // ShouldStopSyncLoop() as soon as the loop is resumed. |
| 463 StartSyncLoop(); | 463 StartSyncLoop(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 } // namespace gdata | 466 } // namespace gdata |
| OLD | NEW |