Commit 179769cf authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Migrate ArcService to BrowserContextKeyedService part 20.

This CL migrates ArcStorageManager.

BUG=672829
TEST=Ran try.

Change-Id: If91bab2be503825fa3c10ee71053acf52c504057
Reviewed-on: https://chromium-review.googlesource.com/572886
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487189}
parent 1d837f7f
...@@ -98,8 +98,6 @@ void ArcServiceLauncher::Initialize() { ...@@ -98,8 +98,6 @@ void ArcServiceLauncher::Initialize() {
base::MakeUnique<ArcIntentHelperBridge>(arc_bridge_service)); base::MakeUnique<ArcIntentHelperBridge>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcSettingsService>(arc_bridge_service)); base::MakeUnique<ArcSettingsService>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcStorageManager>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcTtsService>(arc_bridge_service)); base::MakeUnique<ArcTtsService>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
......
...@@ -191,7 +191,10 @@ void StorageManagerHandler::HandleOpenDownloads( ...@@ -191,7 +191,10 @@ void StorageManagerHandler::HandleOpenDownloads(
void StorageManagerHandler::HandleOpenArcStorage( void StorageManagerHandler::HandleOpenArcStorage(
const base::ListValue* unused_args) { const base::ListValue* unused_args) {
arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); auto* arc_storage_manager = arc::ArcStorageManager::GetForBrowserContext(
Profile::FromWebUI(web_ui()));
if (arc_storage_manager)
arc_storage_manager->OpenPrivateVolumeSettings();
} }
void StorageManagerHandler::HandleClearDriveCache( void StorageManagerHandler::HandleClearDriveCache(
...@@ -418,9 +421,13 @@ void StorageManagerHandler::UpdateArcSize() { ...@@ -418,9 +421,13 @@ void StorageManagerHandler::UpdateArcSize() {
// Shows the item "Android apps and cache" and start calculating size. // Shows the item "Android apps and cache" and start calculating size.
web_ui()->CallJavascriptFunctionUnsafe( web_ui()->CallJavascriptFunctionUnsafe(
"options.StorageManager.showArcItem"); "options.StorageManager.showArcItem");
bool success = arc::ArcStorageManager::Get()->GetApplicationsSize( bool success = false;
base::Bind(&StorageManagerHandler::OnGetArcSize, auto* arc_storage_manager =
weak_ptr_factory_.GetWeakPtr())); arc::ArcStorageManager::GetForBrowserContext(profile);
if (arc_storage_manager) {
success = arc_storage_manager->GetApplicationsSize(base::Bind(
&StorageManagerHandler::OnGetArcSize, weak_ptr_factory_.GetWeakPtr()));
}
if (!success) if (!success)
updating_arc_size_ = false; updating_arc_size_ = false;
} }
......
...@@ -122,7 +122,10 @@ void StorageHandler::HandleOpenDownloads( ...@@ -122,7 +122,10 @@ void StorageHandler::HandleOpenDownloads(
void StorageHandler::HandleOpenArcStorage( void StorageHandler::HandleOpenArcStorage(
const base::ListValue* unused_args) { const base::ListValue* unused_args) {
arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); auto* arc_storage_manager = arc::ArcStorageManager::GetForBrowserContext(
Profile::FromWebUI(web_ui()));
if (arc_storage_manager)
arc_storage_manager->OpenPrivateVolumeSettings();
} }
void StorageHandler::HandleClearDriveCache( void StorageHandler::HandleClearDriveCache(
...@@ -340,8 +343,13 @@ void StorageHandler::UpdateAndroidSize() { ...@@ -340,8 +343,13 @@ void StorageHandler::UpdateAndroidSize() {
// Shows the item "Android apps and cache" and start calculating size. // Shows the item "Android apps and cache" and start calculating size.
FireWebUIListener("storage-android-enabled-changed", base::Value(true)); FireWebUIListener("storage-android-enabled-changed", base::Value(true));
bool success = arc::ArcStorageManager::Get()->GetApplicationsSize(base::Bind( bool success = false;
auto* arc_storage_manager =
arc::ArcStorageManager::GetForBrowserContext(profile);
if (arc_storage_manager) {
success = arc_storage_manager->GetApplicationsSize(base::Bind(
&StorageHandler::OnGetAndroidSize, weak_ptr_factory_.GetWeakPtr())); &StorageHandler::OnGetAndroidSize, weak_ptr_factory_.GetWeakPtr()));
}
if (!success) if (!success)
updating_android_size_ = false; updating_android_size_ = false;
} }
......
...@@ -8,38 +8,49 @@ ...@@ -8,38 +8,49 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/singleton.h"
#include "components/arc/arc_bridge_service.h" #include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
namespace arc { namespace arc {
namespace { namespace {
// This class is owned by ArcServiceManager so that it is safe to use this raw // Singleton factory for ArcStorageManager.
// pointer as the singleton reference. class ArcStorageManagerFactory
ArcStorageManager* g_arc_storage_manager = nullptr; : public internal::ArcBrowserContextKeyedServiceFactoryBase<
ArcStorageManager,
ArcStorageManagerFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName = "ArcStorageManagerFactory";
} // namespace static ArcStorageManagerFactory* GetInstance() {
return base::Singleton<ArcStorageManagerFactory>::get();
}
ArcStorageManager::ArcStorageManager(ArcBridgeService* bridge_service) private:
: ArcService(bridge_service) { friend base::DefaultSingletonTraits<ArcStorageManagerFactory>;
DCHECK(!g_arc_storage_manager); ArcStorageManagerFactory() = default;
g_arc_storage_manager = this; ~ArcStorageManagerFactory() override = default;
} };
ArcStorageManager::~ArcStorageManager() { } // namespace
DCHECK_EQ(this, g_arc_storage_manager);
g_arc_storage_manager = nullptr;
}
// static // static
ArcStorageManager* ArcStorageManager::Get() { ArcStorageManager* ArcStorageManager::GetForBrowserContext(
DCHECK(g_arc_storage_manager); content::BrowserContext* context) {
return g_arc_storage_manager; return ArcStorageManagerFactory::GetForBrowserContext(context);
} }
ArcStorageManager::ArcStorageManager(content::BrowserContext* context,
ArcBridgeService* bridge_service)
: arc_bridge_service_(bridge_service) {}
ArcStorageManager::~ArcStorageManager() = default;
bool ArcStorageManager::OpenPrivateVolumeSettings() { bool ArcStorageManager::OpenPrivateVolumeSettings() {
auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->storage_manager(), OpenPrivateVolumeSettings); arc_bridge_service_->storage_manager(), OpenPrivateVolumeSettings);
if (!storage_manager_instance) if (!storage_manager_instance)
return false; return false;
storage_manager_instance->OpenPrivateVolumeSettings(); storage_manager_instance->OpenPrivateVolumeSettings();
...@@ -49,7 +60,7 @@ bool ArcStorageManager::OpenPrivateVolumeSettings() { ...@@ -49,7 +60,7 @@ bool ArcStorageManager::OpenPrivateVolumeSettings() {
bool ArcStorageManager::GetApplicationsSize( bool ArcStorageManager::GetApplicationsSize(
const GetApplicationsSizeCallback& callback) { const GetApplicationsSizeCallback& callback) {
auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->storage_manager(), GetApplicationsSize); arc_bridge_service_->storage_manager(), GetApplicationsSize);
if (!storage_manager_instance) if (!storage_manager_instance)
return false; return false;
storage_manager_instance->GetApplicationsSize(callback); storage_manager_instance->GetApplicationsSize(callback);
...@@ -59,7 +70,7 @@ bool ArcStorageManager::GetApplicationsSize( ...@@ -59,7 +70,7 @@ bool ArcStorageManager::GetApplicationsSize(
bool ArcStorageManager::DeleteApplicationsCache( bool ArcStorageManager::DeleteApplicationsCache(
const base::Callback<void()>& callback) { const base::Callback<void()>& callback) {
auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* storage_manager_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service()->storage_manager(), DeleteApplicationsCache); arc_bridge_service_->storage_manager(), DeleteApplicationsCache);
if (!storage_manager_instance) if (!storage_manager_instance)
return false; return false;
storage_manager_instance->DeleteApplicationsCache(callback); storage_manager_instance->DeleteApplicationsCache(callback);
......
...@@ -9,23 +9,28 @@ ...@@ -9,23 +9,28 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/storage_manager.mojom.h" #include "components/arc/common/storage_manager.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc { namespace arc {
class ArcBridgeService; class ArcBridgeService;
// This class represents as a simple proxy of StorageManager to Chrome OS. // This class represents as a simple proxy of StorageManager to Chrome OS.
class ArcStorageManager : public ArcService { class ArcStorageManager : public KeyedService {
public: public:
explicit ArcStorageManager(ArcBridgeService* bridge_service); // Returns singleton instance for the given BrowserContext,
~ArcStorageManager() override; // or nullptr if the browser |context| is not allowed to use ARC.
static ArcStorageManager* GetForBrowserContext(
content::BrowserContext* context);
// Gets the singleton instance of the ARC Storage Manager. ArcStorageManager(content::BrowserContext* context,
// MUST be called while ArcStorageManager is alive, otherwise it returns ArcBridgeService* bridge_service);
// nullptr (or aborts on Debug build). ~ArcStorageManager() override;
static ArcStorageManager* Get();
// Opens detailed preference screen of private volume on ARC. // Opens detailed preference screen of private volume on ARC.
// Returns false when an instance of ARC-side isn't ready yet. // Returns false when an instance of ARC-side isn't ready yet.
...@@ -40,6 +45,8 @@ class ArcStorageManager : public ArcService { ...@@ -40,6 +45,8 @@ class ArcStorageManager : public ArcService {
bool DeleteApplicationsCache(const base::Callback<void()>& callback); bool DeleteApplicationsCache(const base::Callback<void()>& callback);
private: private:
ArcBridgeService* const arc_bridge_service_;
DISALLOW_COPY_AND_ASSIGN(ArcStorageManager); DISALLOW_COPY_AND_ASSIGN(ArcStorageManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment