Index: chrome/browser/sync_file_system/drive_file_sync_client.cc |
diff --git a/chrome/browser/sync_file_system/drive_file_sync_client.cc b/chrome/browser/sync_file_system/drive_file_sync_client.cc |
index a192849b9078c6614b7c01ee72ed5e04a9d599a3..7f5ac64a97962c9d1379551abe95ae3da2f28341 100644 |
--- a/chrome/browser/sync_file_system/drive_file_sync_client.cc |
+++ b/chrome/browser/sync_file_system/drive_file_sync_client.cc |
@@ -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" |
@@ -21,8 +23,6 @@ namespace { |
const char kRootResourceId[] = ""; |
const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; |
-const char kResourceLinkPrefix[] = |
- "https://docs.google.com/feeds/default/private/full/"; |
const char kMimeTypeOctetStream[] = "application/octet-stream"; |
// This path is not actually used but is required by DriveUploaderInterface. |
@@ -30,16 +30,16 @@ const FilePath::CharType kDummyDrivePath[] = |
FILE_PATH_LITERAL("/dummy/drive/path"); |
bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, |
- const std::string& parent_resource_id) { |
- bool should_not_have_parent = parent_resource_id.empty(); |
- GURL parent_link(kResourceLinkPrefix + net::EscapePath(parent_resource_id)); |
+ const GURL& parent_link) { |
+ bool should_not_have_parent = parent_link.is_empty(); |
for (ScopedVector<google_apis::Link>::const_iterator itr = links.begin(); |
itr != links.end(); ++itr) { |
if ((*itr)->type() == google_apis::Link::LINK_PARENT) { |
if (should_not_have_parent) |
return false; |
- if ((*itr)->href() == parent_link) |
+ if ((*itr)->href().GetOrigin() == parent_link.GetOrigin() && |
+ (*itr)->href().path() == parent_link.path()) |
return true; |
} |
} |
@@ -49,12 +49,12 @@ bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, |
google_apis::DocumentEntry* GetDocumentByTitleAndParent( |
const ScopedVector<google_apis::DocumentEntry>& entries, |
- const std::string& parent_resource_id, |
+ const GURL& parent_link, |
const string16& title) { |
typedef ScopedVector<google_apis::DocumentEntry>::const_iterator iterator; |
for (iterator itr = entries.begin(); itr != entries.end(); ++itr) { |
if ((*itr)->title() == title && |
- HasParentLinkTo((*itr)->links(), parent_resource_id)) { |
+ HasParentLinkTo((*itr)->links(), parent_link)) { |
return *itr; |
} |
} |
@@ -63,7 +63,9 @@ google_apis::DocumentEntry* GetDocumentByTitleAndParent( |
} // namespace |
-DriveFileSyncClient::DriveFileSyncClient(Profile* profile) { |
+DriveFileSyncClient::DriveFileSyncClient(Profile* profile) |
+ : url_generator_(GURL( |
+ google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { |
drive_service_.reset(new google_apis::GDataWapiService( |
GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
"" /* custom_user_agent */)); |
@@ -83,7 +85,9 @@ scoped_ptr<DriveFileSyncClient> DriveFileSyncClient::CreateForTesting( |
DriveFileSyncClient::DriveFileSyncClient( |
Profile* profile, |
scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
- scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) { |
+ scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader) |
+ : url_generator_( |
+ GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction)) { |
kinuko
2012/12/03 13:10:34
nit: Should this be given from outside? It feels a
tzik
2012/12/04 04:59:50
Done.
|
drive_service_ = drive_service.Pass(); |
drive_service_->Initialize(profile); |
@@ -113,7 +117,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), |
@@ -135,8 +139,11 @@ void DriveFileSyncClient::DidGetDirectory( |
return; |
} |
+ GURL parent_link; |
+ if (!parent_resource_id.empty()) |
+ parent_link = ResourceIdToResourceLink(parent_resource_id); |
google_apis::DocumentEntry* entry = GetDocumentByTitleAndParent( |
- feed->entries(), parent_resource_id, ASCIIToUTF16(directory_name)); |
+ feed->entries(), parent_link, ASCIIToUTF16(directory_name)); |
if (!entry) { |
if (parent_resource_id.empty()) { |
// Use empty content URL for root directory. |
@@ -356,6 +363,25 @@ 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); |
+} |
+ |
+GURL DriveFileSyncClient::ResourceIdToResourceLink( |
+ const std::string& resource_id) const { |
+ GURL link = url_generator_.GenerateDocumentEntryUrl(resource_id); |
+ GURL::Replacements replacements; |
+ replacements.SetQueryStr(std::string()); |
kinuko
2012/12/03 13:10:34
oh ok... it's cumbersome :(
tzik
2012/12/04 04:59:50
Ah, it seems not needed since we no longer use exa
|
+ return link.ReplaceComponents(replacements); |
+} |
+ |
void DriveFileSyncClient::DidGetDocumentFeedData( |
const DocumentFeedCallback& callback, |
google_apis::GDataErrorCode error, |
@@ -368,6 +394,7 @@ void DriveFileSyncClient::DidGetDocumentFeedData( |
} |
DCHECK(data); |
+ DVLOG(1) << *data; |
kinuko
2012/12/03 13:10:34
nit: can you make this logging a bit more descript
tzik
2012/12/04 04:59:50
Done. Removed.
|
scoped_ptr<google_apis::DocumentFeed> feed( |
google_apis::DocumentFeed::ExtractAndParse(*data)); |
if (!feed) |