| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/task_management/providers/arc/arc_process_task_provider
.h" | 5 #include "chrome/browser/task_management/providers/arc/arc_process_task_provider
.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Stale arc process. | 85 // Stale arc process. |
| 86 NotifyObserverTaskRemoved(nspid_to_task_[entry].get()); | 86 NotifyObserverTaskRemoved(nspid_to_task_[entry].get()); |
| 87 nspid_to_task_.erase(entry); | 87 nspid_to_task_.erase(entry); |
| 88 } | 88 } |
| 89 ScheduleNextRequest(); | 89 ScheduleNextRequest(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ArcProcessTaskProvider::RequestProcessList() { | 92 void ArcProcessTaskProvider::RequestProcessList() { |
| 93 arc::ArcProcessService* arc_process_service = | 93 arc::ArcProcessService* arc_process_service = |
| 94 arc::ArcProcessService::Get(); | 94 arc::ArcProcessService::Get(); |
| 95 auto callback = base::Bind(&ArcProcessTaskProvider::OnUpdateProcessList, |
| 96 weak_ptr_factory_.GetWeakPtr()); |
| 95 if (!arc_process_service || | 97 if (!arc_process_service || |
| 96 !arc_process_service->RequestProcessList( | 98 !arc_process_service->RequestProcessList(callback)) { |
| 97 base::Bind(&ArcProcessTaskProvider::OnUpdateProcessList, | |
| 98 weak_ptr_factory_.GetWeakPtr()))) { | |
| 99 VLOG(2) << "ARC process instance is not ready."; | 99 VLOG(2) << "ARC process instance is not ready."; |
| 100 ScheduleNextRequest(); | 100 // Update with the empty ARC process list. |
| 101 // Note that this can happen in the middle of the session if the user has |
| 102 // just opted out from ARC. |
| 103 callback.Run(std::vector<ArcProcess>()); |
| 101 } | 104 } |
| 102 } | 105 } |
| 103 | 106 |
| 104 void ArcProcessTaskProvider::StartUpdating() { | 107 void ArcProcessTaskProvider::StartUpdating() { |
| 105 is_updating_ = true; | 108 is_updating_ = true; |
| 106 RequestProcessList(); | 109 RequestProcessList(); |
| 107 } | 110 } |
| 108 | 111 |
| 109 void ArcProcessTaskProvider::StopUpdating() { | 112 void ArcProcessTaskProvider::StopUpdating() { |
| 110 is_updating_ = false; | 113 is_updating_ = false; |
| 111 nspid_to_task_.clear(); | 114 nspid_to_task_.clear(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 void ArcProcessTaskProvider::ScheduleNextRequest() { | 117 void ArcProcessTaskProvider::ScheduleNextRequest() { |
| 115 if (!is_updating_) | 118 if (!is_updating_) |
| 116 return; | 119 return; |
| 117 // TODO(nya): Remove this timer once ARC starts to send us UpdateProcessList | 120 // TODO(nya): Remove this timer once ARC starts to send us UpdateProcessList |
| 118 // message when the process list changed. As of today, ARC does not send | 121 // message when the process list changed. As of today, ARC does not send |
| 119 // the process list unless we request it by RequestProcessList message. | 122 // the process list unless we request it by RequestProcessList message. |
| 120 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 123 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 121 FROM_HERE, | 124 FROM_HERE, |
| 122 base::Bind(&ArcProcessTaskProvider::RequestProcessList, | 125 base::Bind(&ArcProcessTaskProvider::RequestProcessList, |
| 123 weak_ptr_factory_.GetWeakPtr()), | 126 weak_ptr_factory_.GetWeakPtr()), |
| 124 base::TimeDelta::FromSeconds(kUpdateProcessListDelaySeconds)); | 127 base::TimeDelta::FromSeconds(kUpdateProcessListDelaySeconds)); |
| 125 } | 128 } |
| 126 | 129 |
| 127 } // namespace task_management | 130 } // namespace task_management |
| OLD | NEW |