Commit 45413146 authored by tzik@chromium.org's avatar tzik@chromium.org

Sync FileSystem: Use app id part of the URL for its directory title.

- This CL changes the directory title for origins, from "chrome-extension://exampleextension" to "exampleextension"
- Also, drops file name escape.

BUG=163554

Review URL: https://codereview.chromium.org/11411280

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170887 0039d316-1c4b-4281-b951-d872f2087c98
parent afef1535
......@@ -12,6 +12,8 @@
#include "chrome/browser/google_apis/drive_uploader.h"
#include "chrome/browser/google_apis/gdata_wapi_service.h"
#include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
#include "chrome/common/extensions/extension.h"
#include "extensions/common/constants.h"
#include "net/base/escape.h"
#include "net/base/mime_util.h"
......@@ -113,7 +115,7 @@ void DriveFileSyncClient::GetDriveDirectoryForOrigin(
const ResourceIdCallback& callback) {
DCHECK(CalledOnValidThread());
std::string directory_name(origin.spec());
std::string directory_name(OriginToDirectoryTitle(origin));
SearchFilesInDirectory(
sync_root_resource_id,
FormatTitleQuery(directory_name),
......@@ -356,6 +358,17 @@ void DriveFileSyncClient::DeleteFile(
AsWeakPtr(), remote_file_md5, callback)));
}
// static
std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) {
DCHECK(origin.SchemeIs(extensions::kExtensionScheme));
return origin.host();
}
// static
GURL DriveFileSyncClient::DirectoryTitleToOrigin(const std::string& title) {
return extensions::Extension::GetBaseURLFromExtensionId(title);
}
void DriveFileSyncClient::DidGetDocumentFeedData(
const DocumentFeedCallback& callback,
google_apis::GDataErrorCode error,
......
......@@ -150,6 +150,9 @@ class DriveFileSyncClient : public base::NonThreadSafe,
const std::string& remote_file_md5,
const GDataErrorCallback& callback);
static std::string OriginToDirectoryTitle(const GURL& origin);
static GURL DirectoryTitleToOrigin(const std::string& title);
private:
friend class DriveFileSyncClientTest;
friend class DriveFileSyncServiceTest;
......
......@@ -151,6 +151,11 @@ class DriveFileSyncClientTest : public testing::Test {
protected:
DriveFileSyncClient* sync_client() { return sync_client_.get(); }
std::string FormatOriginQuery(const GURL& origin) {
return FormatTitleQuery(
DriveFileSyncClient::OriginToDirectoryTitle(origin));
}
std::string FormatTitleQuery(const std::string& title) {
return DriveFileSyncClient::FormatTitleQuery(title);
}
......@@ -352,7 +357,7 @@ TEST_F(DriveFileSyncClientTest, GetOriginDirectory) {
const std::string kParentResourceId("folder:sync_root_resource_id");
const std::string kOriginDirectoryResourceId(
"folder:origin_directory_resource_id");
const GURL kOrigin("http://example.com");
const GURL kOrigin("chrome-extension://example");
scoped_ptr<base::Value> found_result(google_apis::test_util::LoadJSONFile(
"sync_file_system/origin_directory_found.json").Pass());
......@@ -361,7 +366,7 @@ TEST_F(DriveFileSyncClientTest, GetOriginDirectory) {
EXPECT_CALL(*mock_drive_service(),
GetDocuments(GURL(), // feed_url
0, // start_changestamp
FormatTitleQuery(kOrigin.spec()),
FormatOriginQuery(kOrigin),
false, // shared_with_me
kParentResourceId,
_))
......@@ -383,7 +388,7 @@ TEST_F(DriveFileSyncClientTest, GetOriginDirectory) {
TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) {
const std::string kParentResourceId("folder:sync_root_resource_id");
const GURL kOrigin("http://example.com");
const GURL kOrigin("chrome-extension://example");
scoped_ptr<base::Value> not_found_result(google_apis::test_util::LoadJSONFile(
"sync_file_system/origin_directory_not_found.json").Pass());
......@@ -399,7 +404,7 @@ TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) {
EXPECT_CALL(*mock_drive_service(),
GetDocuments(GURL(), // feed_url
0, // start_changestamp
FormatTitleQuery(kOrigin.spec()),
FormatOriginQuery(kOrigin),
false, // shared_with_me
kParentResourceId, // directory_resource_id
_))
......@@ -412,10 +417,11 @@ TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) {
.WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS,
base::Passed(&got_parent_result)));
std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
// Expected to call AddNewDirectory from GetDriveDirectoryForOrigin.
EXPECT_CALL(*mock_drive_service(),
AddNewDirectory(GURL("https://sync_root_content_url"),
FilePath().AppendASCII(kOrigin.spec()).value(),
FilePath().AppendASCII(dir_title).value(),
_))
.WillOnce(InvokeGetDataCallback2(google_apis::HTTP_CREATED,
base::Passed(&created_result)));
......
......@@ -21,8 +21,9 @@
#include "chrome/browser/sync_file_system/drive_metadata_store.h"
#include "chrome/browser/sync_file_system/remote_change_processor.h"
#include "chrome/browser/sync_file_system/sync_file_system.pb.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/escape.h"
#include "extensions/common/constants.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/syncable/sync_file_metadata.h"
#include "webkit/fileapi/syncable/sync_file_type.h"
......@@ -248,6 +249,7 @@ void DriveFileSyncService::RemoveObserver(Observer* observer) {
void DriveFileSyncService::RegisterOriginForTrackingChanges(
const GURL& origin,
const fileapi::SyncStatusCallback& callback) {
DCHECK(origin.SchemeIs(extensions::kExtensionScheme));
scoped_ptr<TaskToken> token(GetToken(
FROM_HERE, TASK_TYPE_DRIVE, "Retrieving origin metadata"));
if (!token) {
......@@ -434,7 +436,7 @@ void DriveFileSyncService::ApplyLocalChange(
sync_client_->UploadNewFile(
metadata_store_->GetResourceIdForOrigin(url.origin()),
local_file_path,
net::EscapePath(url.path().AsUTF8Unsafe()),
url.path().AsUTF8Unsafe(),
local_file_metadata.size,
base::Bind(&DriveFileSyncService::DidUploadNewFile,
AsWeakPtr(), base::Passed(&token), url, callback));
......
......@@ -386,8 +386,8 @@ TEST_F(DriveFileSyncServiceTest, GetSyncRoot) {
}
TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) {
const GURL kOrigin1("http://example.com");
const GURL kOrigin2("http://hoge.example.com");
const GURL kOrigin1("chrome-extension://example");
const GURL kOrigin2("chrome-extension://example2");
const std::string kDirectoryResourceId1(
"folder:origin_directory_resource_id");
const std::string kDirectoryResourceId2(
......@@ -439,7 +439,7 @@ TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) {
}
TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
const GURL kOrigin("http://example.com");
const GURL kOrigin("chrome-extension://example");
const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
const std::string kSyncRootResourceId("folder:sync_root_resource_id");
const GURL kSyncRootContentURL("https://sync_root_content_url/");
......@@ -456,7 +456,8 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
scoped_ptr<Value> origin_directory_not_found(LoadJSONFile(
"sync_file_system/origin_directory_not_found.json"));
std::string query = FormatTitleQuery(kOrigin.spec());
std::string query = FormatTitleQuery(
DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
EXPECT_CALL(*mock_drive_service(),
GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _))
......@@ -481,8 +482,8 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
scoped_ptr<Value> origin_directory_created(LoadJSONFile(
"sync_file_system/origin_directory_created.json"));
FilePath::StringType dirname =
FilePath().AppendASCII(kOrigin.spec()).value();
FilePath::StringType dirname = FilePath().AppendASCII(
DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)).value();
EXPECT_CALL(*mock_drive_service(),
AddNewDirectory(kSyncRootContentURL, dirname, _))
.WillOnce(InvokeGetDataCallback2(
......@@ -520,7 +521,7 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
}
TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) {
const GURL kOrigin("http://example.com");
const GURL kOrigin("chrome-extension://example");
const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
const std::string kSyncRootResourceId("folder:sync_root_resource_id");
......@@ -536,7 +537,8 @@ TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) {
scoped_ptr<Value> origin_directory_found(LoadJSONFile(
"sync_file_system/origin_directory_found.json"));
std::string query = FormatTitleQuery("http://example.com/");
std::string query = FormatTitleQuery(
DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
EXPECT_CALL(*mock_drive_service(),
GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _))
.WillOnce(InvokeGetDataCallback5(
......@@ -636,7 +638,7 @@ TEST_F(DriveFileSyncServiceTest, UnregisterOrigin) {
TEST_F(DriveFileSyncServiceTest, ResolveSyncOperationType) {
const fileapi::FileSystemURL url = fileapi::CreateSyncableFileSystemURL(
GURL("http://example.com/"),
GURL("chrome-extension://example/"),
DriveFileSyncService::kServiceName,
FilePath().AppendASCII("path/to/file"));
const std::string kResourceId("123456");
......@@ -734,7 +736,7 @@ TEST_F(DriveFileSyncServiceTest, RemoteChange_NoChange) {
}
TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) {
const GURL kOrigin("chrome-extension://example.com");
const GURL kOrigin("chrome-extension://example");
const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
const std::string kSyncRootResourceId("folder:sync_root_resource_id");
const FilePath::StringType kFileName(FPL("File 1.mp3"));
......@@ -765,7 +767,7 @@ TEST_F(DriveFileSyncServiceTest, RemoteChange_Busy) {
}
TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) {
const GURL kOrigin("chrome-extension://example.com");
const GURL kOrigin("chrome-extension://example");
const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
const std::string kSyncRootResourceId("folder:sync_root_resource_id");
const FilePath::StringType kFileName(FPL("File 1.mp3"));
......@@ -811,7 +813,7 @@ TEST_F(DriveFileSyncServiceTest, RemoteChange_NewFile) {
}
TEST_F(DriveFileSyncServiceTest, RemoteChange_UpdateFile) {
const GURL kOrigin("chrome-extension://example.com");
const GURL kOrigin("chrome-extension://example");
const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
const std::string kSyncRootResourceId("folder:sync_root_resource_id");
const FilePath::StringType kFileName(FPL("File 1.mp3"));
......
......@@ -26,7 +26,7 @@ namespace sync_file_system {
namespace {
const char kOrigin[] = "http://www.example.com";
const char kOrigin[] = "chrome-extension://example";
const char* const kServiceName = DriveFileSyncService::kServiceName;
typedef DriveMetadataStore::ResourceIDMap ResourceIDMap;
......@@ -312,8 +312,8 @@ TEST_F(DriveMetadataStoreTest, StoreSyncRootDirectory) {
}
TEST_F(DriveMetadataStoreTest, StoreSyncOrigin) {
const GURL kOrigin1("http://www1.example.com");
const GURL kOrigin2("http://www2.example.com");
const GURL kOrigin1("chrome-extension://example1");
const GURL kOrigin2("chrome-extension://example2");
const std::string kResourceID1("hoge");
const std::string kResourceID2("fuga");
......@@ -371,10 +371,10 @@ TEST_F(DriveMetadataStoreTest, StoreSyncOrigin) {
}
TEST_F(DriveMetadataStoreTest, RemoveOrigin) {
const GURL kOrigin1("http://hoge.example.com");
const GURL kOrigin2("http://fuga.example.net");
const GURL kOrigin3("http://piyo.example.net");
const GURL kOrigin4("http://mogo.example.net");
const GURL kOrigin1("chrome-extension://example1");
const GURL kOrigin2("chrome-extension://example2");
const GURL kOrigin3("chrome-extension://example3");
const GURL kOrigin4("chrome-extension://example4");
const std::string kResourceId1("hogera");
const std::string kResourceId2("fugaga");
const std::string kResourceId3("piyopiyo");
......@@ -432,8 +432,8 @@ TEST_F(DriveMetadataStoreTest, RemoveOrigin) {
}
TEST_F(DriveMetadataStoreTest, GetResourceIdForOrigin) {
const GURL kOrigin1("http://hoge.example.com");
const GURL kOrigin2("http://fuga.example.net");
const GURL kOrigin1("chrome-extension://example1");
const GURL kOrigin2("chrome-extension://example2");
const std::string kResourceId1("hogera");
const std::string kResourceId2("fugaga");
......
......@@ -67,7 +67,7 @@
"type": "application/atom+xml"
} ],
"published": {"$t": "2012-11-01T06:45:30.346Z" },
"title": {"$t": "http://example.com/" },
"title": {"$t": "example.com" },
"updated": {"$t": "2012-11-01T06:45:30.346Z" },
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$batch": "http://schemas.google.com/gdata/batch",
......
......@@ -81,7 +81,7 @@
"type": "application/atom+xml"
} ],
"published": { "$t": "2012-11-01T05:21:40.382Z" },
"title": { "$t": "http://example.com/" },
"title": { "$t": "example" },
"updated": { "$t": "2012-11-01T05:21:40.382Z" }
} ],
"gd$etag": "W/\"AkEFR3Y7eSt7ImA9WhNSF0k.\"",
......
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