| 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_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 drive_service_(drive_service), | 51 drive_service_(drive_service), |
| 52 profile_(profile), | 52 profile_(profile), |
| 53 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 53 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 54 initialized_(false) { | 54 initialized_(false) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 DriveScheduler::~DriveScheduler() { | 58 DriveScheduler::~DriveScheduler() { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 DCHECK(initialized_); | 60 DCHECK(initialized_); |
| 61 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 61 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void DriveScheduler::Initialize() { | 64 void DriveScheduler::Initialize() { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 66 | 66 |
| 67 // Initialize() may be called more than once for the lifetime when the | 67 // Initialize() may be called more than once for the lifetime when the |
| 68 // file system is remounted. | 68 // file system is remounted. |
| 69 if (initialized_) | 69 if (initialized_) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 72 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 73 initialized_ = true; | 73 initialized_ = true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void DriveScheduler::GetAccountMetadata( | 76 void DriveScheduler::GetAccountMetadata( |
| 77 const google_apis::GetAccountMetadataCallback& callback) { | 77 const google_apis::GetAccountMetadataCallback& callback) { |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 79 DCHECK(!callback.is_null()); | 79 DCHECK(!callback.is_null()); |
| 80 | 80 |
| 81 scoped_ptr<QueueEntry> new_job(new QueueEntry(TYPE_GET_ACCOUNT_METADATA)); | 81 scoped_ptr<QueueEntry> new_job(new QueueEntry(TYPE_GET_ACCOUNT_METADATA)); |
| 82 new_job->get_account_metadata_callback = callback; | 82 new_job->get_account_metadata_callback = callback; |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 scoped_ptr<QueueEntry> job_info = OnJobDone(job_id, drive_error); | 598 scoped_ptr<QueueEntry> job_info = OnJobDone(job_id, drive_error); |
| 599 | 599 |
| 600 if (!job_info) | 600 if (!job_info) |
| 601 return; | 601 return; |
| 602 | 602 |
| 603 // Handle the callback. | 603 // Handle the callback. |
| 604 DCHECK(!job_info->download_action_callback.is_null()); | 604 DCHECK(!job_info->download_action_callback.is_null()); |
| 605 job_info->download_action_callback.Run(error, temp_file); | 605 job_info->download_action_callback.Run(error, temp_file); |
| 606 } | 606 } |
| 607 | 607 |
| 608 void DriveScheduler::OnConnectionTypeChanged( | 608 void DriveScheduler::OnNetworkChanged( |
| 609 net::NetworkChangeNotifier::ConnectionType type) { | 609 net::NetworkChangeNotifier::ConnectionType type) { |
| 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 611 | 611 |
| 612 // Resume the job loop if the network is back online. Note that we don't | 612 // Resume the job loop if the network is back online. Note that we don't |
| 613 // need to check the type of the network as it will be checked in | 613 // need to check the type of the network as it will be checked in |
| 614 // ShouldStopJobLoop() as soon as the loop is resumed. | 614 // ShouldStopJobLoop() as soon as the loop is resumed. |
| 615 if (!net::NetworkChangeNotifier::IsOffline()) | 615 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) |
| 616 StartJobLoop(); | 616 StartJobLoop(); |
| 617 } | 617 } |
| 618 | 618 |
| 619 } // namespace drive | 619 } // namespace drive |
| OLD | NEW |