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

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: Add TODO in SystemInfoProvider 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..be8f965aac4014eef9f45ac46d91ee635567a98b 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"
@@ -29,7 +32,7 @@ namespace extensions {
using api::experimental_system_info_storage::StorageUnitInfo;
using api::experimental_system_info_storage::StorageUnitType;
-using api::experimental_system_info_storage::StorageChangeInfo;
+using api::experimental_system_info_storage::StorageCapacityChangeInfo;
Lei Zhang 2013/06/25 04:49:55 nit: alphabetical order
Haojian Wu 2013/06/26 03:22:40 Done.
using content::BrowserThread;
namespace {
@@ -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());
Lei Zhang 2013/06/25 04:49:55 I wouldn't bother with this DCHECK(). If the next
Haojian Wu 2013/06/26 03:22:40 Done.
+ chrome::StorageMonitor::GetInstance()->AddObserver(this);
}
SystemInfoEventRouter::~SystemInfoEventRouter() {
StorageInfoProvider::Get()->RemoveObserver(this);
+ if (chrome::StorageMonitor::GetInstance())
+ chrome::StorageMonitor::GetInstance()->RemoveObserver(this);
}
void SystemInfoEventRouter::StartWatchingStorages(
@@ -198,9 +209,9 @@ 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;
+ StorageCapacityChangeInfo info;
info.id = id;
info.available_capacity = static_cast<double>(new_value);
@@ -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(
+ 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