| 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 #include "components/arc/storage_manager/arc_storage_manager.h" | 5 #include "components/arc/storage_manager/arc_storage_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 12 | 12 |
| 13 namespace arc { | 13 namespace arc { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int kMinInstanceVersion = 1; // See storage_manager.mojom. | |
| 18 | |
| 19 // This class is owned by ArcServiceManager so that it is safe to use this raw | 17 // This class is owned by ArcServiceManager so that it is safe to use this raw |
| 20 // pointer as the singleton reference. | 18 // pointer as the singleton reference. |
| 21 ArcStorageManager* g_arc_storage_manager = nullptr; | 19 ArcStorageManager* g_arc_storage_manager = nullptr; |
| 22 | 20 |
| 23 } // namespace | 21 } // namespace |
| 24 | 22 |
| 25 ArcStorageManager::ArcStorageManager(ArcBridgeService* bridge_service) | 23 ArcStorageManager::ArcStorageManager(ArcBridgeService* bridge_service) |
| 26 : ArcService(bridge_service) { | 24 : ArcService(bridge_service) { |
| 27 DCHECK(!g_arc_storage_manager); | 25 DCHECK(!g_arc_storage_manager); |
| 28 g_arc_storage_manager = this; | 26 g_arc_storage_manager = this; |
| 29 } | 27 } |
| 30 | 28 |
| 31 ArcStorageManager::~ArcStorageManager() { | 29 ArcStorageManager::~ArcStorageManager() { |
| 32 DCHECK_EQ(this, g_arc_storage_manager); | 30 DCHECK_EQ(this, g_arc_storage_manager); |
| 33 g_arc_storage_manager = nullptr; | 31 g_arc_storage_manager = nullptr; |
| 34 } | 32 } |
| 35 | 33 |
| 36 // static | 34 // static |
| 37 ArcStorageManager* ArcStorageManager::Get() { | 35 ArcStorageManager* ArcStorageManager::Get() { |
| 38 DCHECK(g_arc_storage_manager); | 36 DCHECK(g_arc_storage_manager); |
| 39 return g_arc_storage_manager; | 37 return g_arc_storage_manager; |
| 40 } | 38 } |
| 41 | 39 |
| 42 bool ArcStorageManager::OpenPrivateVolumeSettings() { | 40 bool ArcStorageManager::OpenPrivateVolumeSettings() { |
| 43 auto* storage_manager_instance = | 41 auto* storage_manager_instance = GET_INSTANCE_FOR_METHOD( |
| 44 arc_bridge_service()->storage_manager()->GetInstanceForMethod( | 42 arc_bridge_service()->storage_manager(), OpenPrivateVolumeSettings); |
| 45 "OpenPrivateVolumeSettings", kMinInstanceVersion); | |
| 46 if (!storage_manager_instance) | 43 if (!storage_manager_instance) |
| 47 return false; | 44 return false; |
| 48 storage_manager_instance->OpenPrivateVolumeSettings(); | 45 storage_manager_instance->OpenPrivateVolumeSettings(); |
| 49 return true; | 46 return true; |
| 50 } | 47 } |
| 51 | 48 |
| 52 bool ArcStorageManager::GetApplicationsSize( | 49 bool ArcStorageManager::GetApplicationsSize( |
| 53 const GetApplicationsSizeCallback& callback) { | 50 const GetApplicationsSizeCallback& callback) { |
| 54 auto* storage_manager_instance = | 51 auto* storage_manager_instance = GET_INSTANCE_FOR_METHOD( |
| 55 arc_bridge_service()->storage_manager()->GetInstanceForMethod( | 52 arc_bridge_service()->storage_manager(), GetApplicationsSize); |
| 56 "GetApplicationsSize", kMinInstanceVersion); | |
| 57 if (!storage_manager_instance) | 53 if (!storage_manager_instance) |
| 58 return false; | 54 return false; |
| 59 storage_manager_instance->GetApplicationsSize(callback); | 55 storage_manager_instance->GetApplicationsSize(callback); |
| 60 return true; | 56 return true; |
| 61 } | 57 } |
| 62 | 58 |
| 63 bool ArcStorageManager::DeleteApplicationsCache( | 59 bool ArcStorageManager::DeleteApplicationsCache( |
| 64 const base::Callback<void()>& callback) { | 60 const base::Callback<void()>& callback) { |
| 65 auto* storage_manager_instance = | 61 auto* storage_manager_instance = GET_INSTANCE_FOR_METHOD( |
| 66 arc_bridge_service()->storage_manager()->GetInstanceForMethod( | 62 arc_bridge_service()->storage_manager(), DeleteApplicationsCache); |
| 67 "DeleteApplicationsCache", kMinInstanceVersion); | |
| 68 if (!storage_manager_instance) | 63 if (!storage_manager_instance) |
| 69 return false; | 64 return false; |
| 70 storage_manager_instance->DeleteApplicationsCache(callback); | 65 storage_manager_instance->DeleteApplicationsCache(callback); |
| 71 return true; | 66 return true; |
| 72 } | 67 } |
| 73 | 68 |
| 74 } // namespace arc | 69 } // namespace arc |
| OLD | NEW |