| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_process.h" | 16 #include "chrome/browser/chromeos/arc/arc_process.h" |
| 17 #include "components/arc/arc_bridge_service.h" | 17 #include "components/arc/arc_bridge_service.h" |
| 18 #include "components/arc/arc_service.h" | 18 #include "components/arc/arc_service.h" |
| 19 #include "components/arc/instance_holder.h" |
| 19 | 20 |
| 20 namespace arc { | 21 namespace arc { |
| 21 | 22 |
| 22 // A single global entry to get a list of ARC processes. | 23 // A single global entry to get a list of ARC processes. |
| 23 // | 24 // |
| 24 // Call RequestProcessList() on the main UI thread to get a list of all ARC | 25 // Call RequestProcessList() on the main UI thread to get a list of all ARC |
| 25 // processes. It returns vector<arc::ArcProcess>, which includes pid <-> nspid | 26 // processes. It returns vector<arc::ArcProcess>, which includes pid <-> nspid |
| 26 // mapping. | 27 // mapping. |
| 27 // Example: | 28 // Example: |
| 28 // void OnUpdateProcessList(const vector<arc::ArcProcess>&) {...} | 29 // void OnUpdateProcessList(const vector<arc::ArcProcess>&) {...} |
| 29 // | 30 // |
| 30 // arc::ArcProcessService* arc_process_service = | 31 // arc::ArcProcessService* arc_process_service = |
| 31 // arc::ArcProcessService::Get(); | 32 // arc::ArcProcessService::Get(); |
| 32 // if (!arc_process_service || | 33 // if (!arc_process_service || |
| 33 // !arc_process_service->RequestProcessList( | 34 // !arc_process_service->RequestProcessList( |
| 34 // base::Bind(&OnUpdateProcessList)) { | 35 // base::Bind(&OnUpdateProcessList)) { |
| 35 // LOG(ERROR) << "ARC process instance not ready."; | 36 // LOG(ERROR) << "ARC process instance not ready."; |
| 36 // } | 37 // } |
| 37 class ArcProcessService : public ArcService, | 38 class ArcProcessService |
| 38 public ArcBridgeService::Observer { | 39 : public ArcService, |
| 40 public InstanceHolder<mojom::ProcessInstance>::Observer { |
| 39 public: | 41 public: |
| 40 using RequestProcessListCallback = | 42 using RequestProcessListCallback = |
| 41 base::Callback<void(const std::vector<ArcProcess>&)>; | 43 base::Callback<void(const std::vector<ArcProcess>&)>; |
| 42 | 44 |
| 43 explicit ArcProcessService(ArcBridgeService* bridge_service); | 45 explicit ArcProcessService(ArcBridgeService* bridge_service); |
| 44 ~ArcProcessService() override; | 46 ~ArcProcessService() override; |
| 45 | 47 |
| 46 // Returns nullptr before the global instance is ready. | 48 // Returns nullptr before the global instance is ready. |
| 47 static ArcProcessService* Get(); | 49 static ArcProcessService* Get(); |
| 48 | 50 |
| 49 // ArcBridgeService::Observer overrides. | 51 // InstanceHolder<mojom::ProcessInstance>::Observer overrides. |
| 50 void OnProcessInstanceReady() override; | 52 void OnInstanceReady() override; |
| 51 | 53 |
| 52 // Returns true if ARC IPC is ready for process list request, | 54 // Returns true if ARC IPC is ready for process list request, |
| 53 // otherwise false. | 55 // otherwise false. |
| 54 bool RequestProcessList(RequestProcessListCallback callback); | 56 bool RequestProcessList(RequestProcessListCallback callback); |
| 55 | 57 |
| 56 private: | 58 private: |
| 57 void Reset(); | 59 void Reset(); |
| 58 | 60 |
| 59 void OnReceiveProcessList( | 61 void OnReceiveProcessList( |
| 60 const RequestProcessListCallback& callback, | 62 const RequestProcessListCallback& callback, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 87 // Always keep this the last member of this class to make sure it's the | 89 // Always keep this the last member of this class to make sure it's the |
| 88 // first thing to be destructed. | 90 // first thing to be destructed. |
| 89 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_; | 91 base::WeakPtrFactory<ArcProcessService> weak_ptr_factory_; |
| 90 | 92 |
| 91 DISALLOW_COPY_AND_ASSIGN(ArcProcessService); | 93 DISALLOW_COPY_AND_ASSIGN(ArcProcessService); |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 } // namespace arc | 96 } // namespace arc |
| 95 | 97 |
| 96 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ | 98 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_PROCESS_SERVICE_H_ |
| OLD | NEW |