summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/media_galleries/media_galleries_api.cc10
-rw-r--r--chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc13
-rw-r--r--chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc3
-rw-r--r--chrome/browser/media_galleries/media_file_system_registry.cc16
-rw-r--r--chrome/browser/media_galleries/media_file_system_registry.h5
-rw-r--r--chrome/browser/media_galleries/media_file_system_registry_unittest.cc8
-rw-r--r--chrome/browser/storage_monitor/storage_monitor.cc4
-rw-r--r--chrome/browser/storage_monitor/storage_monitor.h4
-rw-r--r--chrome/browser/storage_monitor/transient_device_ids.cc36
-rw-r--r--chrome/browser/storage_monitor/transient_device_ids.h10
-rw-r--r--chrome/common/extensions/api/media_galleries.idl4
-rw-r--r--chrome/common/extensions/api/media_galleries_private.idl12
-rw-r--r--chrome/test/data/extensions/api_test/media_galleries_private/eject/test.js5
-rw-r--r--chrome/test/data/extensions/api_test/media_galleries_private/gallerywatch/test.js8
14 files changed, 71 insertions, 67 deletions
diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
index 9fdf42d..ba9371d 100644
--- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
+++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
@@ -13,6 +13,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/stl_util.h"
+#include "base/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/shell_window_registry.h"
@@ -164,10 +165,11 @@ void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
file_system_names.insert(filesystems[i].name);
file_system_dict_value->SetStringWithoutPathExpansion(
MediaFileSystemRegistry::kNameKey, filesystems[i].name);
- file_system_dict_value->SetIntegerWithoutPathExpansion(
- MediaFileSystemRegistry::kGalleryIdKey, filesystems[i].pref_id);
- if (filesystems[i].transient_device_id) {
- file_system_dict_value->SetIntegerWithoutPathExpansion(
+ file_system_dict_value->SetStringWithoutPathExpansion(
+ MediaFileSystemRegistry::kGalleryIdKey,
+ base::Uint64ToString(filesystems[i].pref_id));
+ if (!filesystems[i].transient_device_id.empty()) {
+ file_system_dict_value->SetStringWithoutPathExpansion(
MediaFileSystemRegistry::kDeviceIdKey,
filesystems[i].transient_device_id);
}
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
index ca34bec..7383ea0 100644
--- a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
+++ b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
@@ -47,14 +47,14 @@ void HandleProfileShutdownOnFileThread(void* profile_id) {
// Gets the |gallery_file_path| and |gallery_pref_id| of the gallery specified
// by the |gallery_id|. Returns true and set |gallery_file_path| and
// |gallery_pref_id| if the |gallery_id| is valid and returns false otherwise.
-bool GetGalleryFilePathAndId(int gallery_id,
+bool GetGalleryFilePathAndId(const std::string& gallery_id,
Profile* profile,
const Extension* extension,
base::FilePath* gallery_file_path,
chrome::MediaGalleryPrefId* gallery_pref_id) {
- if (gallery_id < 0)
+ chrome::MediaGalleryPrefId pref_id;
+ if (!base::StringToUint64(gallery_id, &pref_id))
return false;
- chrome::MediaGalleryPrefId pref_id = static_cast<uint64>(gallery_id);
chrome::MediaFileSystemRegistry* registry =
g_browser_process->media_file_system_registry();
base::FilePath file_path(
@@ -189,7 +189,7 @@ void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse(
bool success) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
extensions::api::media_galleries_private::AddGalleryWatchResult result;
- result.gallery_id = gallery_id;
+ result.gallery_id = base::Uint64ToString(gallery_id);
result.success = success;
SetResult(result.ToValue().release());
if (success) {
@@ -256,7 +256,7 @@ bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() {
if (!render_view_host() || !render_view_host()->GetProcess())
return false;
- std::vector<int> result;
+ std::vector<std::string> result;
#if defined(OS_WIN)
GalleryWatchStateTracker* state_tracker =
MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
@@ -265,8 +265,7 @@ bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() {
for (chrome::MediaGalleryPrefIdSet::const_iterator iter =
gallery_ids.begin();
iter != gallery_ids.end(); ++iter) {
- if (*iter < kint32max)
- result.push_back(*iter);
+ result.push_back(base::Uint64ToString(*iter));
}
#endif
results_ = GetAllGalleryWatch::Results::Create(result);
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
index f027bb4..d26ab44 100644
--- a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
+++ b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.cc
@@ -8,7 +8,6 @@
#include <map>
-#include "base/strings/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/event_names.h"
@@ -25,7 +24,7 @@ namespace {
std::string GetTransientIdForDeviceId(const std::string& device_id) {
chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance();
- return base::Uint64ToString(monitor->GetTransientIdForDeviceId(device_id));
+ return monitor->GetTransientIdForDeviceId(device_id);
}
} // namespace
diff --git a/chrome/browser/media_galleries/media_file_system_registry.cc b/chrome/browser/media_galleries/media_file_system_registry.cc
index 6bc7c8b..4ef589d 100644
--- a/chrome/browser/media_galleries/media_file_system_registry.cc
+++ b/chrome/browser/media_galleries/media_file_system_registry.cc
@@ -82,7 +82,7 @@ MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name,
const base::FilePath& fs_path,
const std::string& filesystem_id,
MediaGalleryPrefId pref_id,
- uint64 transient_device_id,
+ const std::string& transient_device_id,
bool removable,
bool media_device)
: name(fs_name),
@@ -95,6 +95,7 @@ MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name,
}
MediaFileSystemInfo::MediaFileSystemInfo() {}
+MediaFileSystemInfo::~MediaFileSystemInfo() {}
// Tracks the liveness of multiple RenderProcessHosts that the caller is
// interested in. Once all of the RPHs have closed or been terminated a call
@@ -398,14 +399,14 @@ class ExtensionGalleriesHost
callback.Run(result);
}
- uint64 GetTransientIdForRemovableDeviceId(const std::string& device_id) {
+ std::string GetTransientIdForRemovableDeviceId(const std::string& device_id) {
if (!MediaStorageUtil::IsRemovableDevice(device_id))
- return 0;
+ return std::string();
// StorageMonitor may be NULL in unit tests.
StorageMonitor* monitor = StorageMonitor::GetInstance();
if (!monitor)
- return 0;
+ return std::string();
return monitor->GetTransientIdForDeviceId(device_id);
}
@@ -435,12 +436,11 @@ class ExtensionGalleriesHost
MediaFileSystemRegistry::kGalleryIdKey, pref_id);
// |device_id| can be empty, in which case, just omit it.
- uint64 transient_device_id =
+ std::string transient_device_id =
GetTransientIdForRemovableDeviceId(device_id);
- if (transient_device_id) {
+ if (!transient_device_id.empty()) {
dict_value.SetStringWithoutPathExpansion(
- MediaFileSystemRegistry::kDeviceIdKey,
- base::Uint64ToString(transient_device_id));
+ MediaFileSystemRegistry::kDeviceIdKey, transient_device_id);
}
dict_value.SetStringWithoutPathExpansion(
"DEPRECATED",
diff --git a/chrome/browser/media_galleries/media_file_system_registry.h b/chrome/browser/media_galleries/media_file_system_registry.h
index bc2caf1..b943f36 100644
--- a/chrome/browser/media_galleries/media_file_system_registry.h
+++ b/chrome/browser/media_galleries/media_file_system_registry.h
@@ -51,16 +51,17 @@ struct MediaFileSystemInfo {
const base::FilePath& fs_path,
const std::string& filesystem_id,
MediaGalleryPrefId pref_id,
- uint64 transient_device_id,
+ const std::string& transient_device_id,
bool removable,
bool media_device);
MediaFileSystemInfo();
+ ~MediaFileSystemInfo();
std::string name; // JSON string, must not contain slashes.
base::FilePath path;
std::string fsid;
MediaGalleryPrefId pref_id;
- uint64 transient_device_id;
+ std::string transient_device_id;
bool removable;
bool media_device;
};
diff --git a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc
index ec08062..a3db59a 100644
--- a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc
+++ b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc
@@ -227,9 +227,9 @@ void CheckGalleryInfo(const MediaFileSystemInfo& info,
EXPECT_NE(0UL, info.pref_id);
if (removable)
- EXPECT_NE(0UL, info.transient_device_id);
+ EXPECT_NE(0UL, info.transient_device_id.size());
else
- EXPECT_EQ(0UL, info.transient_device_id);
+ EXPECT_EQ(0UL, info.transient_device_id.size());
base::FilePath fsid_path = fs_context->GetPathForId(info.fsid);
EXPECT_EQ(path, fsid_path);
@@ -764,7 +764,7 @@ MediaFileSystemRegistryTest::GetAutoAddedGalleries(
if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) {
base::FilePath path = it->second.AbsolutePath();
MediaFileSystemInfo info(path.AsUTF8Unsafe(), path, std::string(),
- 0, 0, false, false);
+ 0, std::string(), false, false);
result.push_back(info);
}
}
@@ -846,7 +846,7 @@ TEST_F(MediaFileSystemRegistryTest, UserAddedGallery) {
device_id,
true /*has access*/);
MediaFileSystemInfo added_info(empty_dir().AsUTF8Unsafe(), empty_dir(),
- std::string(), 0, 0, false, false);
+ std::string(), 0, std::string(), false, false);
added_galleries.push_back(added_info);
profile_state->CheckGalleries("user added regular", added_galleries,
auto_galleries);
diff --git a/chrome/browser/storage_monitor/storage_monitor.cc b/chrome/browser/storage_monitor/storage_monitor.cc
index bddb92d..8fea460 100644
--- a/chrome/browser/storage_monitor/storage_monitor.cc
+++ b/chrome/browser/storage_monitor/storage_monitor.cc
@@ -85,13 +85,13 @@ void StorageMonitor::RemoveObserver(
observer_list_->RemoveObserver(obs);
}
-uint64 StorageMonitor::GetTransientIdForDeviceId(
+std::string StorageMonitor::GetTransientIdForDeviceId(
const std::string& device_id) {
return transient_device_ids_->GetTransientIdForDeviceId(device_id);
}
std::string StorageMonitor::GetDeviceIdForTransientId(
- uint64 transient_id) const {
+ const std::string& transient_id) const {
return transient_device_ids_->DeviceIdFromTransientId(transient_id);
}
diff --git a/chrome/browser/storage_monitor/storage_monitor.h b/chrome/browser/storage_monitor/storage_monitor.h
index 86ef72c..8c129c6 100644
--- a/chrome/browser/storage_monitor/storage_monitor.h
+++ b/chrome/browser/storage_monitor/storage_monitor.h
@@ -116,8 +116,8 @@ class StorageMonitor {
void AddObserver(RemovableStorageObserver* obs);
void RemoveObserver(RemovableStorageObserver* obs);
- uint64 GetTransientIdForDeviceId(const std::string& device_id);
- std::string GetDeviceIdForTransientId(uint64 transient_id) const;
+ std::string GetTransientIdForDeviceId(const std::string& device_id);
+ std::string GetDeviceIdForTransientId(const std::string& transient_id) const;
virtual void EjectDevice(
const std::string& device_id,
diff --git a/chrome/browser/storage_monitor/transient_device_ids.cc b/chrome/browser/storage_monitor/transient_device_ids.cc
index c6231a5..473d7e4 100644
--- a/chrome/browser/storage_monitor/transient_device_ids.cc
+++ b/chrome/browser/storage_monitor/transient_device_ids.cc
@@ -6,37 +6,41 @@
#include "chrome/browser/storage_monitor/transient_device_ids.h"
+#include "base/guid.h"
#include "base/logging.h"
+#include "base/stl_util.h"
#include "chrome/browser/storage_monitor/media_storage_util.h"
namespace chrome {
-TransientDeviceIds::TransientDeviceIds() : next_transient_id_(1) {}
+TransientDeviceIds::TransientDeviceIds() {}
TransientDeviceIds::~TransientDeviceIds() {}
-uint64 TransientDeviceIds::GetTransientIdForDeviceId(
+std::string TransientDeviceIds::GetTransientIdForDeviceId(
const std::string& device_id) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(MediaStorageUtil::IsRemovableDevice(device_id));
- bool inserted =
- id_map_.insert(std::make_pair(device_id, next_transient_id_)).second;
- if (inserted) {
- // Inserted a device that has never been seen before.
- ++next_transient_id_;
+ if (!ContainsKey(device_id_map_, device_id)) {
+ std::string transient_id;
+ do {
+ transient_id = base::GenerateGUID();
+ } while (ContainsKey(transient_id_map_, transient_id));
+
+ device_id_map_[device_id] = transient_id;
+ transient_id_map_[transient_id] = device_id;
}
- return id_map_[device_id];
+
+ return device_id_map_[device_id];
}
-const std::string TransientDeviceIds::DeviceIdFromTransientId(
- uint64 transient_id) const {
- for (DeviceIdToTransientIdMap::const_iterator iter = id_map_.begin();
- iter != id_map_.end(); ++iter) {
- if (iter->second == transient_id)
- return iter->first;
- }
- return std::string();
+std::string TransientDeviceIds::DeviceIdFromTransientId(
+ const std::string& transient_id) const {
+ IdMap::const_iterator it = transient_id_map_.find(transient_id);
+ if (it == transient_id_map_.end())
+ return std::string();
+ return it->second;
}
} // namespace chrome
diff --git a/chrome/browser/storage_monitor/transient_device_ids.h b/chrome/browser/storage_monitor/transient_device_ids.h
index 615492c..8f81650 100644
--- a/chrome/browser/storage_monitor/transient_device_ids.h
+++ b/chrome/browser/storage_monitor/transient_device_ids.h
@@ -27,17 +27,17 @@ class TransientDeviceIds {
// |device_id| must be for a removable device.
// If |device_id| has never been seen before, a new, unique transient id will
// be assigned.
- uint64 GetTransientIdForDeviceId(const std::string& device_id);
+ std::string GetTransientIdForDeviceId(const std::string& device_id);
// Get the reverse mapping for a transient ID. Returns an empty string if the
// |transient_id| cannot be found.
- const std::string DeviceIdFromTransientId(uint64 transient_id) const;
+ std::string DeviceIdFromTransientId(const std::string& transient_id) const;
private:
- typedef std::map<std::string, uint64> DeviceIdToTransientIdMap;
+ typedef std::map<std::string, std::string> IdMap;
- DeviceIdToTransientIdMap id_map_;
- uint64 next_transient_id_;
+ IdMap device_id_map_;
+ IdMap transient_id_map_;
base::ThreadChecker thread_checker_;
diff --git a/chrome/common/extensions/api/media_galleries.idl b/chrome/common/extensions/api/media_galleries.idl
index 009c380..f1a92a4 100644
--- a/chrome/common/extensions/api/media_galleries.idl
+++ b/chrome/common/extensions/api/media_galleries.idl
@@ -31,11 +31,11 @@ namespace mediaGalleries {
DOMString name;
// A unique and persistent id for the media gallery.
- long galleryId;
+ DOMString galleryId;
// If the media gallery is on a removable device, a unique id for the
// device.
- long? deviceId;
+ DOMString? deviceId;
// True if the media gallery is on a removable device.
boolean isRemovable;
diff --git a/chrome/common/extensions/api/media_galleries_private.idl b/chrome/common/extensions/api/media_galleries_private.idl
index c9efe94..9767e86 100644
--- a/chrome/common/extensions/api/media_galleries_private.idl
+++ b/chrome/common/extensions/api/media_galleries_private.idl
@@ -24,7 +24,7 @@ namespace mediaGalleriesPrivate {
// A dictionary that describes the modified gallery.
[inline_doc] dictionary GalleryChangeDetails {
// Gallery identifier.
- long galleryId;
+ DOMString galleryId;
};
interface Events {
@@ -40,12 +40,12 @@ namespace mediaGalleriesPrivate {
// A dictionary that describes the add gallery watch request results.
dictionary AddGalleryWatchResult {
- long galleryId;
+ DOMString galleryId;
boolean success;
};
callback AddGalleryWatchCallback = void (AddGalleryWatchResult result);
- callback GetAllGalleryWatchCallback = void (long[] galleryIds);
+ callback GetAllGalleryWatchCallback = void (DOMString[] galleryIds);
[inline_doc] enum EjectDeviceResultCode {
// The ejection command is successful -- the application can prompt the user
@@ -64,11 +64,11 @@ namespace mediaGalleriesPrivate {
callback EjectDeviceCallback = void (EjectDeviceResultCode result);
interface Functions {
- static void addGalleryWatch(long galleryId,
+ static void addGalleryWatch(DOMString galleryId,
AddGalleryWatchCallback callback);
- static void removeGalleryWatch(long galleryId);
+ static void removeGalleryWatch(DOMString galleryId);
static void getAllGalleryWatch(GetAllGalleryWatchCallback callback);
static void removeAllGalleryWatch();
- static void ejectDevice(long deviceId, EjectDeviceCallback callback);
+ static void ejectDevice(DOMString deviceId, EjectDeviceCallback callback);
};
};
diff --git a/chrome/test/data/extensions/api_test/media_galleries_private/eject/test.js b/chrome/test/data/extensions/api_test/media_galleries_private/eject/test.js
index ecf8e87..5866c37 100644
--- a/chrome/test/data/extensions/api_test/media_galleries_private/eject/test.js
+++ b/chrome/test/data/extensions/api_test/media_galleries_private/eject/test.js
@@ -22,8 +22,7 @@ function ejectCallback(result) {
};
function ejectTest() {
- chrome.mediaGalleriesPrivate.ejectDevice(parseInt(attachedDeviceId),
- ejectCallback);
+ chrome.mediaGalleriesPrivate.ejectDevice(attachedDeviceId, ejectCallback);
};
function addAttachListener() {
@@ -37,5 +36,5 @@ function removeAttachListener() {
};
function ejectFailTest() {
- chrome.mediaGalleriesPrivate.ejectDevice(-1, ejectCallback);
+ chrome.mediaGalleriesPrivate.ejectDevice('-1', ejectCallback);
};
diff --git a/chrome/test/data/extensions/api_test/media_galleries_private/gallerywatch/test.js b/chrome/test/data/extensions/api_test/media_galleries_private/gallerywatch/test.js
index 9ea0d53..47281bd 100644
--- a/chrome/test/data/extensions/api_test/media_galleries_private/gallerywatch/test.js
+++ b/chrome/test/data/extensions/api_test/media_galleries_private/gallerywatch/test.js
@@ -3,7 +3,7 @@
// found in the LICENSE file.
var galleries;
-var invalidGalleryId = 11000;
+var invalidGalleryId = '11000';
// chrome.mediaGalleries.getMediaFileSystems callback.
var mediaFileSystemsListCallback = function (results) {
@@ -53,7 +53,7 @@ function addGalleryChangedListener() {
function setupWatchOnValidGalleries() {
for (var i = 0; i < galleries.length; ++i) {
- var info = JSON.parse(galleries[i].name);
+ var info = chrome.mediaGalleries.getMediaFileSystemMetadata(galleries[i]);
chrome.mediaGalleriesPrivate.addGalleryWatch(info.galleryId,
onAddWatchRequestCallback);
}
@@ -73,7 +73,7 @@ function getMediaFileSystems() {
function removeGalleryWatch() {
for (var i = 0; i < galleries.length; ++i) {
- var info = JSON.parse(galleries[i].name);
+ var info = chrome.mediaGalleries.getMediaFileSystemMetadata(galleries[i]);
chrome.mediaGalleriesPrivate.removeGalleryWatch(info.galleryId);
}
chrome.test.sendMessage('remove_gallery_watch_ok');
@@ -93,4 +93,4 @@ function getAllWatchedGalleryIds() {
function removeAllGalleryWatch() {
chrome.mediaGalleriesPrivate.removeAllGalleryWatch();
chrome.test.sendMessage('remove_all_gallery_watch_ok');
-}; \ No newline at end of file
+};