summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 04:51:41 +0000
committerhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 04:51:41 +0000
commit92dbf7091e1aa673a87a256c296ea27f3372833d (patch)
treec33dd62a782c21a1661b38c6bbd28af55321c4e5 /chrome
parentf1b0f9cf541d1917e5d21fdae44014f0e76066f3 (diff)
downloadchromium_src-92dbf7091e1aa673a87a256c296ea27f3372833d.zip
chromium_src-92dbf7091e1aa673a87a256c296ea27f3372833d.tar.gz
chromium_src-92dbf7091e1aa673a87a256c296ea27f3372833d.tar.bz2
Polish the SystemInfoProvider template code and refactor StorageInfoProvider based on it.
BUG=136519 TEST=browser_tests --gtest_filter=SystemInfoStorageApiTest.* Review URL: https://chromiumcodereview.appspot.com/10876041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h10
-rw-r--r--chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc5
-rw-r--r--chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc5
-rw-r--r--chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc5
-rw-r--r--chrome/browser/extensions/api/system_info_storage/storage_info_provider.h28
-rw-r--r--chrome/browser/extensions/api/system_info_storage/storage_info_provider_linux.cc42
-rw-r--r--chrome/browser/extensions/api/system_info_storage/storage_info_provider_mac.cc42
-rw-r--r--chrome/browser/extensions/api/system_info_storage/storage_info_provider_win.cc106
-rw-r--r--chrome/browser/extensions/api/system_info_storage/system_info_storage_api.cc73
-rw-r--r--chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h12
-rw-r--r--chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc40
-rw-r--r--chrome/browser/extensions/system_info_provider.h8
-rw-r--r--chrome/chrome_browser_extensions.gypi2
-rw-r--r--chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js8
14 files changed, 238 insertions, 148 deletions
diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h
index b0cb12f..5a714db 100644
--- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h
+++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h
@@ -9,8 +9,14 @@
namespace extensions {
-typedef SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo>
- CpuInfoProvider;
+class CpuInfoProvider
+ : public SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo> {
+ public:
+ virtual ~CpuInfoProvider() {}
+
+ // Return the single shared instance of CpuInfoProvider.
+ static CpuInfoProvider* Get();
+};
} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
index c8d6c6c..80c1995 100644
--- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
+++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
@@ -6,6 +6,8 @@
namespace extensions {
+namespace {
+
using api::experimental_system_info_cpu::CpuInfo;
// CpuInfoProvider implementation for Linux platform.
@@ -21,8 +23,9 @@ bool CpuInfoProviderLinux::QueryInfo(CpuInfo* info) {
return false;
}
+} // namespace
+
// static
-template<>
CpuInfoProvider* CpuInfoProvider::Get() {
return CpuInfoProvider::GetInstance<CpuInfoProviderLinux>();
}
diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc
index 3010d6e..7f43b00 100644
--- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc
+++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc
@@ -6,6 +6,8 @@
namespace extensions {
+namespace {
+
using api::experimental_system_info_cpu::CpuInfo;
// CpuInfoProvider implementation on Mac OS.
@@ -21,8 +23,9 @@ bool CpuInfoProviderMac::QueryInfo(CpuInfo* info) {
return false;
}
+} // namespace
+
// static
-template<>
CpuInfoProvider* CpuInfoProvider::Get() {
return CpuInfoProvider::GetInstance<CpuInfoProviderMac>();
}
diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
index eb51d3d..d1929a2 100644
--- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
+++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
@@ -6,6 +6,8 @@
namespace extensions {
+namespace {
+
using api::experimental_system_info_cpu::CpuInfo;
// CpuInfoProvider implementation on Windows platform.
@@ -21,8 +23,9 @@ bool CpuInfoProviderWin::QueryInfo(CpuInfo* info) {
return false;
}
+} // namespace
+
// static
-template<>
CpuInfoProvider* CpuInfoProvider::Get() {
return CpuInfoProvider::GetInstance<CpuInfoProviderWin>();
}
diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h
index 18f0e6f..0265ddd 100644
--- a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h
+++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h
@@ -4,14 +4,15 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_STORAGE_INFO_PROVIDER_H_
#define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_STORAGE_INFO_PROVIDER_H_
+#include "chrome/browser/extensions/system_info_provider.h"
#include "chrome/common/extensions/api/experimental_system_info_storage.h"
namespace extensions {
namespace systeminfo {
-// TODO(hmin): Here the storage type is declared as string type due to the IDL
-// doesn't support enum type yet. Once http://crbug.com/141940 is fixed, we
-// could reuse enum values generated by IDL compiler.
+// TODO(hongbo): Here the storage type is declared as string type due to the
+// IDL doesn't support enum type yet. Once http://crbug.com/141940 is fixed,
+// we could reuse enum values generated by IDL compiler.
// Unknown storage type.
extern const char kStorageTypeUnknown[];
@@ -19,21 +20,22 @@ extern const char kStorageTypeUnknown[];
extern const char kStorageTypeHardDisk[];
// Removable storage, e.g. USB device, flash card reader.
extern const char kStorageTypeRemovable[];
+
} // namespace systeminfo
-// An interface for retrieving storage information on different platforms.
-class StorageInfoProvider {
+class StorageInfoProvider
+ : public SystemInfoProvider<
+ api::experimental_system_info_storage::StorageInfo> {
public:
- // Return a StorageInfoProvider instance. The caller is responsible for
- // destroying it.
- static StorageInfoProvider* Create();
+ virtual ~StorageInfoProvider() {}
- virtual ~StorageInfoProvider() {}
+ // Get the single shared instance of StorageInfoProvider.
+ static StorageInfoProvider* Get();
- // Return true if succeed to get storage information. Should be implemented
- // on different platforms.
- virtual bool GetStorageInfo(
- api::experimental_system_info_storage::StorageInfo* info) = 0;
+ // Get the information for the storage unit specified by the |id| parameter,
+ // and output the result to the |info|.
+ virtual bool QueryUnitInfo(const std::string& id,
+ api::experimental_system_info_storage::StorageUnitInfo* info) = 0;
};
} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_linux.cc b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_linux.cc
new file mode 100644
index 0000000..43790f9
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_linux.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
+
+namespace extensions {
+
+namespace {
+
+using api::experimental_system_info_storage::StorageInfo;
+using api::experimental_system_info_storage::StorageUnitInfo;
+
+// StorageInfoProvider implementation on Linux platform.
+// TODO(hongbo): not implemented yet.
+class StorageInfoProviderLinux : public StorageInfoProvider {
+ public:
+ StorageInfoProviderLinux() {}
+ virtual ~StorageInfoProviderLinux() {}
+
+ virtual bool QueryInfo(StorageInfo* info) OVERRIDE;
+ virtual bool QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) OVERRIDE;
+};
+
+bool StorageInfoProviderLinux::QueryInfo(StorageInfo* info) {
+ return false;
+}
+
+bool StorageInfoProviderLinux::QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) {
+ return false;
+}
+
+} // namespace
+
+// static
+StorageInfoProvider* StorageInfoProvider::Get() {
+ return StorageInfoProvider::GetInstance<StorageInfoProviderLinux>();
+}
+
+} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_mac.cc b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_mac.cc
new file mode 100644
index 0000000..2c7f555
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_mac.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
+
+namespace extensions {
+
+namespace {
+
+using api::experimental_system_info_storage::StorageInfo;
+using api::experimental_system_info_storage::StorageUnitInfo;
+
+// StorageInfoProvider implementation on Macdows platform.
+// TODO(hongbo): not implemented yet.
+class StorageInfoProviderMac : public StorageInfoProvider {
+ public:
+ StorageInfoProviderMac() {}
+ virtual ~StorageInfoProviderMac() {}
+
+ virtual bool QueryInfo(StorageInfo* info) OVERRIDE;
+ virtual bool QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) OVERRIDE;
+};
+
+bool StorageInfoProviderMac::QueryInfo(StorageInfo* info) {
+ return false;
+}
+
+bool StorageInfoProviderMac::QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) {
+ return false;
+}
+
+} // namespace
+
+// static
+StorageInfoProvider* StorageInfoProvider::Get() {
+ return StorageInfoProvider::GetInstance<StorageInfoProviderMac>();
+}
+
+} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_win.cc b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_win.cc
index 524ba82..66a3ebb 100644
--- a/chrome/browser/extensions/api/system_info_storage/storage_info_provider_win.cc
+++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider_win.cc
@@ -5,11 +5,13 @@
#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
#include "base/string_util.h"
-
+#include "base/utf_string_conversions.h"
#include <windows.h>
namespace extensions {
+namespace {
+
using api::experimental_system_info_storage::StorageInfo;
using api::experimental_system_info_storage::StorageUnitInfo;
@@ -20,26 +22,16 @@ const unsigned long kMaxLogicalDriveString = 4 * 26;
// StorageInfoProvider implementation on Windows platform.
class StorageInfoProviderWin : public StorageInfoProvider {
public:
- StorageInfoProviderWin();
- virtual ~StorageInfoProviderWin();
+ StorageInfoProviderWin() {}
+ virtual ~StorageInfoProviderWin() {}
- virtual bool GetStorageInfo(StorageInfo* info) OVERRIDE;
+ virtual bool QueryInfo(StorageInfo* info) OVERRIDE;
+ virtual bool QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) OVERRIDE;
};
-// static
-StorageInfoProvider* StorageInfoProvider::Create() {
- return new StorageInfoProviderWin();
-}
-
-// StorageInfoProviderWin implementation.
-StorageInfoProviderWin::StorageInfoProviderWin() {
-}
-
-StorageInfoProviderWin::~StorageInfoProviderWin() {
-}
-
-bool StorageInfoProviderWin::GetStorageInfo(StorageInfo* info) {
- if (info == NULL) return false;
+bool StorageInfoProviderWin::QueryInfo(StorageInfo* info) {
+ info->units.clear();
WCHAR logical_drive_strings[kMaxLogicalDriveString];
@@ -54,41 +46,57 @@ bool StorageInfoProviderWin::GetStorageInfo(StorageInfo* info) {
// Iterate the drive string by 4 wchars each step
for (unsigned int i = 0; i < string_length; i += 4) {
- std::string type;
- DWORD ret = GetDriveType(&logical_drive_strings[i]);
- switch (ret) {
- case DRIVE_FIXED:
- type = systeminfo::kStorageTypeHardDisk;
- break;
- case DRIVE_REMOVABLE:
- type = systeminfo::kStorageTypeRemovable;
- break;
- case DRIVE_UNKNOWN:
- type = systeminfo::kStorageTypeUnknown;
- break;
- case DRIVE_CDROM: // CD ROM
- case DRIVE_REMOTE: // Remote network drive
- case DRIVE_NO_ROOT_DIR: // Invalid root path
- case DRIVE_RAMDISK: // RAM disk
- // TODO(hmin): Do we need to care about these drive types?
- continue;
- }
-
- ULARGE_INTEGER available_bytes;
- ULARGE_INTEGER free_bytes;
- BOOL status = GetDiskFreeSpaceEx(&logical_drive_strings[i], NULL,
- &available_bytes,
- &free_bytes);
- if (status) {
- linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
- unit->id = WideToASCII(string16(&logical_drive_strings[i]));
- unit->type = type;
- unit->capacity = static_cast<double>(available_bytes.QuadPart);
- unit->available_capacity = static_cast<double>(free_bytes.QuadPart);
+ linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
+ if (QueryUnitInfo(WideToUTF8(&logical_drive_strings[i]), unit.get())) {
info->units.push_back(unit);
}
}
return true;
}
+bool StorageInfoProviderWin::QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) {
+ DCHECK(info);
+ string16 drive = UTF8ToUTF16(id);
+
+ std::string type;
+ DWORD ret = GetDriveType(drive.c_str());
+ switch (ret) {
+ case DRIVE_FIXED:
+ type = systeminfo::kStorageTypeHardDisk;
+ break;
+ case DRIVE_REMOVABLE:
+ type = systeminfo::kStorageTypeRemovable;
+ break;
+ case DRIVE_UNKNOWN:
+ type = systeminfo::kStorageTypeUnknown;
+ break;
+ case DRIVE_CDROM: // CD ROM
+ case DRIVE_REMOTE: // Remote network drive
+ case DRIVE_NO_ROOT_DIR: // Invalid root path
+ case DRIVE_RAMDISK: // RAM disk
+ // TODO(hmin): Do we need to care about these drive types?
+ return false;
+ }
+
+ ULARGE_INTEGER total_bytes;
+ ULARGE_INTEGER free_bytes;
+
+ if (GetDiskFreeSpaceEx(drive.c_str(), NULL, &total_bytes, &free_bytes)) {
+ info->id = id;
+ info->type = type;
+ info->capacity = static_cast<double>(total_bytes.QuadPart);
+ info->available_capacity = static_cast<double>(free_bytes.QuadPart);
+ return true;
+ }
+ return false;
+}
+
+} // namespace
+
+// static
+StorageInfoProvider* StorageInfoProvider::Get() {
+ return StorageInfoProvider::GetInstance<StorageInfoProviderWin>();
+}
+
} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.cc b/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.cc
index 91916ee..187be39 100644
--- a/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.cc
+++ b/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.cc
@@ -3,21 +3,12 @@
// found in the LICENSE file.
#include "chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h"
-#include "base/logging.h"
-#include "base/json/json_writer.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
-#include "base/values.h"
-#include "content/public/browser/browser_thread.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
namespace extensions {
using api::experimental_system_info_storage::StorageInfo;
using api::experimental_system_info_storage::StorageUnitInfo;
-using content::BrowserThread;
SystemInfoStorageGetFunction::SystemInfoStorageGetFunction() {
}
@@ -26,67 +17,19 @@ SystemInfoStorageGetFunction::~SystemInfoStorageGetFunction() {
}
bool SystemInfoStorageGetFunction::RunImpl() {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SystemInfoStorageGetFunction::WorkOnFileThread, this));
+ StorageInfoProvider::Get()->StartQueryInfo(
+ base::Bind(&SystemInfoStorageGetFunction::OnGetStorageInfoCompleted,
+ this));
return true;
}
-void SystemInfoStorageGetFunction::WorkOnFileThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- bool success = false;
- scoped_ptr<StorageInfoProvider> provider(StorageInfoProvider::Create());
- StorageInfo info;
- if (provider.get() && provider->GetStorageInfo(&info)) {
+void SystemInfoStorageGetFunction::OnGetStorageInfoCompleted(
+ const StorageInfo& info, bool success) {
+ if (success)
SetResult(info.ToValue().release());
- success = true;
- } else {
- SetError("Error in querying storage information");
- }
-
- // Return the result on UI thread.
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&SystemInfoStorageGetFunction::RespondOnUIThread,
- this, success));
-}
-
-void SystemInfoStorageGetFunction::RespondOnUIThread(bool success) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ else
+ SetError("Error occurred when querying storage information.");
SendResponse(success);
}
-#if !defined(OS_WIN)
-// A Mock implementation for temporary usage. Will be moved out for testing
-// once the platform specifc implementations are ready.
-const char kStorageTypeUnknownStr[] = "unknown";
-const char kStorageTypeHardDiskStr[] = "harddisk";
-const char kStorageTypeUSBStr[] = "usb";
-const char kStorageTypeMMCStr[] = "mmc";
-
-class MockStorageInfoProvider : public StorageInfoProvider {
- public:
- MockStorageInfoProvider() {}
- virtual ~MockStorageInfoProvider() {}
- virtual bool GetStorageInfo(StorageInfo* info) OVERRIDE;
-};
-
-bool MockStorageInfoProvider::GetStorageInfo(StorageInfo* info) {
- if (info == NULL) return false;
- linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
- unit->id = "0xbeaf";
- unit->type = kStorageTypeUnknownStr;
- unit->capacity = 4098;
- unit->available_capacity = 1000;
-
- info->units.push_back(unit);
- return true;
-}
-
-// static
-StorageInfoProvider* StorageInfoProvider::Create() {
- return new MockStorageInfoProvider();
-}
-#endif // !OS_WIN
-
} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h b/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h
index f925f17..eb9ccaa 100644
--- a/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h
+++ b/chrome/browser/extensions/api/system_info_storage/system_info_storage_api.h
@@ -5,6 +5,7 @@
#define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_SYSTEM_INFO_STORAGE_API_H_
#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/common/extensions/api/experimental_system_info_storage.h"
namespace extensions {
@@ -13,20 +14,15 @@ namespace extensions {
class SystemInfoStorageGetFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION_NAME("experimental.systemInfo.storage.get");
-
SystemInfoStorageGetFunction();
private:
virtual ~SystemInfoStorageGetFunction();
-
- // AsyncExtensionFunction implementation.
virtual bool RunImpl() OVERRIDE;
- // Called on FILE thread to get storage information
- void WorkOnFileThread();
-
- // Responds the result back to UI thread
- void RespondOnUIThread(bool success);
+ void OnGetStorageInfoCompleted(
+ const api::experimental_system_info_storage::StorageInfo& info,
+ bool success);
};
} // namespace extensions
diff --git a/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc b/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
index c55d0ae..9d46706 100644
--- a/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
+++ b/chrome/browser/extensions/api/system_info_storage/system_info_storage_apitest.cc
@@ -2,22 +2,62 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/message_loop.h"
+#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/common/chrome_switches.h"
namespace extensions {
+using api::experimental_system_info_storage::StorageInfo;
+using api::experimental_system_info_storage::StorageUnitInfo;
+
+class MockStorageInfoProvider : public StorageInfoProvider {
+ public:
+ MockStorageInfoProvider() {}
+ virtual ~MockStorageInfoProvider() {}
+
+ virtual bool QueryInfo(StorageInfo* info) OVERRIDE {
+ info->units.clear();
+
+ linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
+ unit->id = "0xbeaf";
+ unit->type = systeminfo::kStorageTypeUnknown;
+ unit->capacity = 4098;
+ unit->available_capacity = 1024;
+
+ info->units.push_back(unit);
+ return true;
+ }
+
+ virtual bool QueryUnitInfo(const std::string& id,
+ StorageUnitInfo* info) OVERRIDE {
+ return false;
+ }
+};
+
class SystemInfoStorageApiTest: public ExtensionApiTest {
public:
SystemInfoStorageApiTest() {}
~SystemInfoStorageApiTest() {}
+
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
}
+
+ virtual void SetUpInProcessBrowserTestFixture() {
+ ExtensionApiTest::SetUpInProcessBrowserTestFixture();
+ message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
+ }
+
+ private:
+ scoped_ptr<MessageLoop> message_loop_;
};
IN_PROC_BROWSER_TEST_F(SystemInfoStorageApiTest, Storage) {
+ StorageInfoProvider* provider = new MockStorageInfoProvider();
+ StorageInfoProvider::InitializeForTesting(provider);
ASSERT_TRUE(RunExtensionTest("systeminfo/storage")) << message_;
}
diff --git a/chrome/browser/extensions/system_info_provider.h b/chrome/browser/extensions/system_info_provider.h
index 38fac9e..d9057d5 100644
--- a/chrome/browser/extensions/system_info_provider.h
+++ b/chrome/browser/extensions/system_info_provider.h
@@ -47,10 +47,6 @@ class SystemInfoProvider {
virtual ~SystemInfoProvider() {}
- // Static method to get the single shared instance. Should be implemented
- // in the impl file for each kind of provider.
- static SystemInfoProvider<T>* Get();
-
// For testing
static void InitializeForTesting(SystemInfoProvider<T>* provider) {
DCHECK(provider != NULL);
@@ -113,12 +109,12 @@ class SystemInfoProvider {
// Template function for creating the single shared provider instance.
// Template paramter I is the type of SystemInfoProvider implementation.
template<class I>
- static SystemInfoProvider<T>* GetInstance() {
+ static I* GetInstance() {
if (!single_shared_provider_.Get().get()) {
I* impl = new I();
single_shared_provider_.Get().reset(impl);
}
- return single_shared_provider_.Get().get();
+ return static_cast<I*>(single_shared_provider_.Get().get());
}
// The latest information filled up by QueryInfo implementation. Here we
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index 2beaed8..efa226c 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -250,6 +250,8 @@
'browser/extensions/api/system_info_storage/system_info_storage_api.h',
'browser/extensions/api/system_info_storage/storage_info_provider.cc',
'browser/extensions/api/system_info_storage/storage_info_provider.h',
+ 'browser/extensions/api/system_info_storage/storage_info_provider_linux.cc',
+ 'browser/extensions/api/system_info_storage/storage_info_provider_mac.cc',
'browser/extensions/api/system_info_storage/storage_info_provider_win.cc',
'browser/extensions/api/tabs/execute_code_in_tab_function.cc',
'browser/extensions/api/tabs/execute_code_in_tab_function.h',
diff --git a/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js b/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js
index 5b4f834..787ca40 100644
--- a/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js
+++ b/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js
@@ -9,8 +9,12 @@ chrome.systemInfo = chrome.experimental.systemInfo;
chrome.test.runTests([
function testGet() {
chrome.systemInfo.storage.get(chrome.test.callbackPass(function(info) {
- // TODO(hmin): Need to check the value from Mock implementation
- chrome.test.assertTrue(info.units.length > 0);
+ chrome.test.assertTrue(info.units.length == 1);
+ var unit = info.units[0];
+ chrome.test.assertTrue(unit.id == "0xbeaf");
+ chrome.test.assertTrue(unit.type == "unknown");
+ chrome.test.assertTrue(unit.capacity == 4098);
+ chrome.test.assertTrue(unit.availableCapacity == 1024);
}));
}
]);