Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1557)

Unified Diff: chrome/browser/extensions/api/system_info/system_info_api.cc

Issue 16707002: [SystemInfo API] Rewrite storage info provider using storage monitor impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove storage_info_provider_linux_unittest.cc in chrome_tests_unit.gypi Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/system_info/system_info_api.cc
diff --git a/chrome/browser/extensions/api/system_info/system_info_api.cc b/chrome/browser/extensions/api/system_info/system_info_api.cc
index fdca73e3ef226e220d5d175e08c22fc45860e643..ae34829d987dc2235d5a576a7ce954afeec298f9 100644
--- a/chrome/browser/extensions/api/system_info/system_info_api.cc
+++ b/chrome/browser/extensions/api/system_info/system_info_api.cc
@@ -17,6 +17,9 @@
#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
+#include "chrome/browser/storage_monitor/removable_storage_observer.h"
+#include "chrome/browser/storage_monitor/storage_info.h"
+#include "chrome/browser/storage_monitor/storage_monitor.h"
#include "chrome/common/extensions/api/experimental_system_info_storage.h"
#include "ui/gfx/display_observer.h"
@@ -49,8 +52,9 @@ bool IsAvailableCapacityChangedEvent(const std::string& event_name) {
// Event router for systemInfo API. It is a singleton instance shared by
// multiple profiles.
-class SystemInfoEventRouter
- : public gfx::DisplayObserver, public StorageInfoObserver {
+class SystemInfoEventRouter : public gfx::DisplayObserver,
+ public StorageFreeSpaceObserver,
+ public chrome::RemovableStorageObserver {
public:
static SystemInfoEventRouter* GetInstance();
@@ -65,22 +69,25 @@ class SystemInfoEventRouter
static bool IsSystemInfoEvent(const std::string& event_name);
private:
- // StorageInfoObserver:
- virtual void OnStorageFreeSpaceChanged(const std::string& id,
- double new_value,
- double old_value) OVERRIDE;
- virtual void OnStorageAttached(
- const std::string& id,
- api::experimental_system_info_storage::StorageUnitType type,
- double capacity,
- double available_capacity) OVERRIDE;
- virtual void OnStorageDetached(const std::string& id) OVERRIDE;
+ // StorageFreeSpaceObserver:
+ virtual void OnFreeSpaceChanged(const std::string& id,
+ double new_value,
+ double old_value) OVERRIDE;
// gfx::DisplayObserver:
virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
+ // chrome::RemovableStorageObserver implementation.
+ virtual void OnRemovableStorageAttached(
+ const chrome::StorageInfo& info) OVERRIDE;
+ virtual void OnRemovableStorageDetached(
+ const chrome::StorageInfo& info) OVERRIDE;
+
+ void DispatchStorageAttachedEvent(const chrome::StorageInfo& info,
+ int64 avail_bytes);
+
// Called from any thread to dispatch the systemInfo event to all extension
// processes cross multiple profiles.
void DispatchEvent(const std::string& event_name,
@@ -110,10 +117,14 @@ SystemInfoEventRouter* SystemInfoEventRouter::GetInstance() {
SystemInfoEventRouter::SystemInfoEventRouter() {
StorageInfoProvider::Get()->AddObserver(this);
+ DCHECK(chrome::StorageMonitor::GetInstance());
+ chrome::StorageMonitor::GetInstance()->AddObserver(this);
}
SystemInfoEventRouter::~SystemInfoEventRouter() {
StorageInfoProvider::Get()->RemoveObserver(this);
+ if (chrome::StorageMonitor::GetInstance())
+ chrome::StorageMonitor::GetInstance()->RemoveObserver(this);
}
void SystemInfoEventRouter::StartWatchingStorages(
@@ -198,7 +209,7 @@ bool SystemInfoEventRouter::IsSystemInfoEvent(const std::string& event_name) {
}
// Called on UI thread since the observer is added from UI thread.
-void SystemInfoEventRouter::OnStorageFreeSpaceChanged(
+void SystemInfoEventRouter::OnFreeSpaceChanged(
const std::string& id, double new_value, double old_value) {
StorageChangeInfo info;
info.id = id;
@@ -210,25 +221,36 @@ void SystemInfoEventRouter::OnStorageFreeSpaceChanged(
DispatchEvent(event_names::kOnStorageAvailableCapacityChanged, args.Pass());
}
-void SystemInfoEventRouter::OnStorageAttached(const std::string& id,
- StorageUnitType type,
- double capacity,
- double available_capacity) {
- StorageUnitInfo info;
- info.id = id;
- info.type = type;
- info.capacity = capacity;
- info.available_capacity = available_capacity;
+void SystemInfoEventRouter::OnRemovableStorageAttached(
+ const chrome::StorageInfo& info) {
+ base::FilePath mount_path(info.location());
+ base::PostTaskAndReplyWithResult(
Greg Billock 2013/06/18 18:24:52 Shall we change storage monitor to attempt to gath
Haojian Wu 2013/06/21 05:49:04 If we gather available capacity in storage monitor
Greg Billock 2013/06/24 16:55:38 I think we've decided to keep that experimental, s
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN),
+ FROM_HERE,
+ base::Bind(&StorageInfoProvider::GetStorageFreeSpace,
+ StorageInfoProvider::Get(), mount_path),
+ base::Bind(&SystemInfoEventRouter::DispatchStorageAttachedEvent,
+ base::Unretained(this), info));
+}
- scoped_ptr<base::ListValue> args(new base::ListValue);
- args->Append(info.ToValue().release());
+void SystemInfoEventRouter::DispatchStorageAttachedEvent(
+ const chrome::StorageInfo& info, int64 avail_bytes) {
+ StorageUnitInfo unit;
+ systeminfo::BuildStorageUnitInfo(info, &unit);
+ unit.available_capacity =
+ avail_bytes > 0 ? static_cast<double>(avail_bytes) : 0;
+
+ scoped_ptr<base::ListValue> args(new base::ListValue);
+ args->Append(unit.ToValue().release());
DispatchEvent(event_names::kOnStorageAttached, args.Pass());
}
-void SystemInfoEventRouter::OnStorageDetached(const std::string& id) {
+void SystemInfoEventRouter::OnRemovableStorageDetached(
+ const chrome::StorageInfo& info) {
scoped_ptr<base::ListValue> args(new base::ListValue);
- args->Append(new base::StringValue(id));
+ args->Append(new base::StringValue(info.device_id()));
DispatchEvent(event_names::kOnStorageDetached, args.Pass());
}

Powered by Google App Engine
This is Rietveld 408576698